blob: 4fb016b38893aa4fefae530da9f96e7dfed83872 [file] [log] [blame]
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -07001Android Init Language
2---------------------
3
Tom Cherry3be66ed2015-09-01 14:49:38 -07004The Android Init Language consists of five broad classes of statements,
5which are Actions, Commands, Services, Options, and Imports.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -07006
7All of these are line-oriented, consisting of tokens separated by
8whitespace. The c-style backslash escapes may be used to insert
9whitespace into a token. Double quotes may also be used to prevent
10whitespace from breaking text into multiple tokens. The backslash,
11when it is the last character on a line, may be used for line-folding.
12
13Lines which start with a # (leading whitespace allowed) are comments.
14
15Actions and Services implicitly declare a new section. All commands
16or options belong to the section most recently declared. Commands
17or options before the first section are ignored.
18
Tom Cherry3be66ed2015-09-01 14:49:38 -070019Actions and Services have unique names. If a second Action is defined
20with the same name as an existing one, its commands are appended to
21the commands of the existing action. If a second Service is defined
22with the same name as an existing one, it is ignored and an error
23message is logged.
24
25
26Init .rc Files
27--------------
28The init language is used in plaintext files that take the .rc file
29extension. These are typically multiple of these in multiple
30locations on the system, described below.
31
32/init.rc is the primary .rc file and is loaded by the init executable
33at the beginning of its execution. It is responsible for the initial
34set up of the system. It imports /init.${ro.hardware}.rc which is the
35primary vendor supplied .rc file.
36
37During the mount_all command, the init executable loads all of the
38files contained within the /{system,vendor,odm}/etc/init/ directories.
39These directories are intended for all Actions and Services used after
40file system mounting.
41
Tom Cherry1fb20b82016-01-20 16:53:08 -080042One may specify paths in the mount_all command line to have it import
43.rc files at the specified paths instead of the default ones listed above.
44This is primarily for supporting factory mode and other non-standard boot
45modes. The three default paths should be used for the normal boot process.
46
Tom Cherry3be66ed2015-09-01 14:49:38 -070047The intention of these directories is as follows
48 1) /system/etc/init/ is for core system items such as
Tom Cherry1fb20b82016-01-20 16:53:08 -080049 SurfaceFlinger, MediaService, and logcatd.
Tom Cherry3be66ed2015-09-01 14:49:38 -070050 2) /vendor/etc/init/ is for SoC vendor items such as actions or
51 daemons needed for core SoC functionality.
52 3) /odm/etc/init/ is for device manufacturer items such as
53 actions or daemons needed for motion sensor or other peripheral
54 functionality.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -070055
Tom Cherry1fb20b82016-01-20 16:53:08 -080056All services whose binaries reside on the system, vendor, or odm
57partitions should have their service entries placed into a
58corresponding init .rc file, located in the /etc/init/
59directory of the partition where they reside. There is a build
60system macro, LOCAL_INIT_RC, that handles this for developers. Each
61init .rc file should additionally contain any actions associated with
62its service.
63
64An example is the logcatd.rc and Android.mk files located in the
65system/core/logcat directory. The LOCAL_INIT_RC macro in the
66Android.mk file places logcatd.rc in /system/etc/init/ during the
67build process. Init loads logcatd.rc during the mount_all command and
68allows the service to be run and the action to be queued when
69appropriate.
70
71This break up of init .rc files according to their daemon is preferred
72to the previously used monolithic init .rc files. This approach
73ensures that the only service entries that init reads and the only
74actions that init performs correspond to services whose binaries are in
75fact present on the file system, which was not the case with the
76monolithic init .rc files. This additionally will aid in merge
77conflict resolution when multiple services are added to the system, as
78each one will go into a separate file.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -070079
Wei Wangabfbec32016-08-23 11:58:09 -070080There are two options "early" and "late" in mount_all command
81which can be set after optional paths. With "--early" set, the
82init executable will skip mounting entries with "latemount" flag
83and triggering fs encryption state event. With "--late" set,
84init executable will only mount entries with "latemount" flag but skip
85importing rc files. By default, no option is set, and mount_all will
86mount_all will process all entries in the given fstab.
87
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -070088Actions
89-------
90Actions are named sequences of commands. Actions have a trigger which
91is used to determine when the action should occur. When an event
92occurs which matches an action's trigger, that action is added to
93the tail of a to-be-executed queue (unless it is already on the
94queue).
95
96Each action in the queue is dequeued in sequence and each command in
97that action is executed in sequence. Init handles other activities
98(device creation/destruction, property setting, process restarting)
99"between" the execution of the commands in activities.
100
101Actions take the form of:
102
Tom Cherry3be66ed2015-09-01 14:49:38 -0700103on <trigger> [&& <trigger>]*
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700104 <command>
105 <command>
106 <command>
107
108
109Services
110--------
111Services are programs which init launches and (optionally) restarts
112when they exit. Services take the form of:
113
114service <name> <pathname> [ <argument> ]*
115 <option>
116 <option>
117 ...
118
119
120Options
121-------
122Options are modifiers to services. They affect how and when init
123runs the service.
124
Viorel Suman70daa672016-03-21 10:08:07 +0200125console [<console>]
126 This service needs a console. The optional second parameter chooses a
127 specific console instead of the default. The default "/dev/console" can
128 be changed by setting the "androidboot.console" kernel parameter. In
129 all cases the leading "/dev/" should be omitted, so "/dev/tty0" would be
130 specified as just "console tty0".
131
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700132critical
Elliott Hughesd62f0602015-06-12 18:02:20 -0700133 This is a device-critical service. If it exits more than four times in
134 four minutes, the device will reboot into recovery mode.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700135
136disabled
Elliott Hughesd62f0602015-06-12 18:02:20 -0700137 This service will not automatically start with its class.
138 It must be explicitly started by name.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700139
140setenv <name> <value>
Elliott Hughesd62f0602015-06-12 18:02:20 -0700141 Set the environment variable <name> to <value> in the launched process.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700142
Elliott Hughes8d82ea02015-02-06 20:15:18 -0800143socket <name> <type> <perm> [ <user> [ <group> [ <seclabel> ] ] ]
Elliott Hughesd62f0602015-06-12 18:02:20 -0700144 Create a unix domain socket named /dev/socket/<name> and pass
145 its fd to the launched process. <type> must be "dgram", "stream" or "seqpacket".
146 User and group default to 0.
147 'seclabel' is the SELinux security context for the socket.
148 It defaults to the service security context, as specified by seclabel or
149 computed based on the service executable file security context.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700150
151user <username>
Elliott Hughesd62f0602015-06-12 18:02:20 -0700152 Change to username before exec'ing this service.
153 Currently defaults to root. (??? probably should default to nobody)
Tom Cherrydbddb402015-12-11 12:54:50 -0800154 As of Android M, processes should use this option even if they
155 require linux capabilities. Previously, to acquire linux
156 capabilities, a process would need to run as root, request the
157 capabilities, then drop to its desired uid. There is a new
158 mechanism through fs_config that allows device manufacturers to add
159 linux capabilities to specific binaries on a file system that should
160 be used instead. This mechanism is described on
161 http://source.android.com/devices/tech/config/filesystem.html. When
162 using this new mechanism, processes can use the user option to
163 select their desired uid without ever running as root.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700164
165group <groupname> [ <groupname> ]*
Elliott Hughesd62f0602015-06-12 18:02:20 -0700166 Change to groupname before exec'ing this service. Additional
167 groupnames beyond the (required) first one are used to set the
168 supplemental groups of the process (via setgroups()).
169 Currently defaults to root. (??? probably should default to nobody)
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700170
Elliott Hughes8d82ea02015-02-06 20:15:18 -0800171seclabel <seclabel>
172 Change to 'seclabel' before exec'ing this service.
Stephen Smalley3fb61102012-11-02 15:22:34 -0400173 Primarily for use by services run from the rootfs, e.g. ueventd, adbd.
174 Services on the system partition can instead use policy-defined transitions
175 based on their file security context.
176 If not specified and no transition is defined in policy, defaults to the init context.
177
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700178oneshot
Elliott Hughesd62f0602015-06-12 18:02:20 -0700179 Do not restart the service when it exits.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700180
181class <name>
Elliott Hughesd62f0602015-06-12 18:02:20 -0700182 Specify a class name for the service. All services in a
183 named class may be started or stopped together. A service
184 is in the class "default" if one is not specified via the
185 class option.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700186
187onrestart
Elliott Hughesd62f0602015-06-12 18:02:20 -0700188 Execute a Command (see below) when service restarts.
189
190writepid <file...>
191 Write the child's pid to the given files when it forks. Meant for
192 cgroup/cpuset usage.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700193
Vitalii Tomkiv081705c2016-05-18 17:36:30 -0700194priority <priority>
195 Scheduling priority of the service process. This value has to be in range
196 -20 to 19. Default priority is 0. Priority is set via setpriority().
Elliott Hughes841b2632015-02-12 14:28:54 -0800197
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700198Triggers
199--------
Tom Cherry3be66ed2015-09-01 14:49:38 -0700200Triggers are strings which can be used to match certain kinds of
201events and used to cause an action to occur.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700202
Tom Cherry3be66ed2015-09-01 14:49:38 -0700203Triggers are subdivided into event triggers and property triggers.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700204
Tom Cherry3be66ed2015-09-01 14:49:38 -0700205Event triggers are strings triggered by the 'trigger' command or by
206the QueueEventTrigger() function within the init executable. These
207take the form of a simple string such as 'boot' or 'late-init'.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700208
Tom Cherry3be66ed2015-09-01 14:49:38 -0700209Property triggers are strings triggered when a named property changes
210value to a given new value or when a named property changes value to
211any new value. These take the form of 'property:<name>=<value>' and
212'property:<name>=*' respectively. Property triggers are additionally
213evaluated and triggered accordingly during the initial boot phase of
214init.
Badhri Jagan Sridharan0b415122014-10-10 23:19:06 -0700215
Tom Cherry3be66ed2015-09-01 14:49:38 -0700216An Action can have multiple property triggers but may only have one
217event trigger.
Badhri Jagan Sridharan0b415122014-10-10 23:19:06 -0700218
Tom Cherry3be66ed2015-09-01 14:49:38 -0700219For example:
220'on boot && property:a=b' defines an action that is only executed when
221the 'boot' event trigger happens and the property a equals b.
222
223'on property:a=b && property:c=d' defines an action that is executed
224at three times,
225 1) During initial boot if property a=b and property c=d
226 2) Any time that property a transitions to value b, while property
227 c already equals d.
228 3) Any time that property c transitions to value d, while property
229 a already equals b.
Badhri Jagan Sridharan0b415122014-10-10 23:19:06 -0700230
Elliott Hughes841b2632015-02-12 14:28:54 -0800231
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700232Commands
233--------
234
Elliott Hughes91a3be52015-03-20 11:00:15 -0700235bootchart_init
236 Start bootcharting if configured (see below).
237 This is included in the default init.rc.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700238
239chmod <octal-mode> <path>
240 Change file access permissions.
241
242chown <owner> <group> <path>
243 Change file owner and group.
244
245class_start <serviceclass>
246 Start all services of the specified class if they are
247 not already running.
248
249class_stop <serviceclass>
Elliott Hughes91a3be52015-03-20 11:00:15 -0700250 Stop and disable all services of the specified class if they are
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700251 currently running.
252
Elliott Hughes91a3be52015-03-20 11:00:15 -0700253class_reset <serviceclass>
254 Stop all services of the specified class if they are
255 currently running, without disabling them. They can be restarted
256 later using class_start.
257
258copy <src> <dst>
259 Copies a file. Similar to write, but useful for binary/large
260 amounts of data.
261
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700262domainname <name>
263 Set the domain name.
264
JP Abgrall3beec7e2014-05-02 21:14:29 -0700265enable <servicename>
266 Turns a disabled service into an enabled one as if the service did not
267 specify disabled.
268 If the service is supposed to be running, it will be started now.
269 Typically used when the bootloader sets a variable that indicates a specific
270 service should be started when needed. E.g.
271 on property:ro.boot.myfancyhardware=1
272 enable my_fancy_service_for_my_fancy_hardware
273
Elliott Hughes91a3be52015-03-20 11:00:15 -0700274exec [ <seclabel> [ <user> [ <group> ]* ] ] -- <command> [ <argument> ]*
275 Fork and execute command with the given arguments. The command starts
276 after "--" so that an optional security context, user, and supplementary
277 groups can be provided. No other commands will be run until this one
Mark Salyzyn17fff892015-06-02 11:11:02 -0700278 finishes. <seclabel> can be a - to denote default.
Elliott Hughes91a3be52015-03-20 11:00:15 -0700279
Elliott Hughes91a3be52015-03-20 11:00:15 -0700280export <name> <value>
281 Set the environment variable <name> equal to <value> in the
282 global environment (which will be inherited by all processes
283 started after this command is executed)
284
285hostname <name>
286 Set the host name.
287
288ifup <interface>
289 Bring the network interface <interface> online.
290
Hung-ying Tyanbfa6d752016-05-17 18:49:10 +0800291insmod [-f] <path> [<options>]
292 Install the module at <path> with the specified options.
293 -f
294 Force installation of the module even if the version of the running kernel
295 and the version of the kernel for which the module was compiled do not match.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700296
Elliott Hughes91a3be52015-03-20 11:00:15 -0700297load_all_props
298 Loads properties from /system, /vendor, et cetera.
299 This is included in the default init.rc.
300
301load_persist_props
302 Loads persistent properties when /data has been decrypted.
303 This is included in the default init.rc.
304
Elliott Hughesf682b472015-02-06 12:19:48 -0800305loglevel <level>
306 Sets the kernel log level to level. Properties are expanded within <level>.
307
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700308mkdir <path> [mode] [owner] [group]
309 Create a directory at <path>, optionally with the given mode, owner, and
310 group. If not provided, the directory is created with permissions 755 and
Johan Redestig0b42ba22015-03-15 17:39:41 +0100311 owned by the root user and root group. If provided, the mode, owner and group
312 will be updated if the directory exists already.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700313
Wei Wangabfbec32016-08-23 11:58:09 -0700314mount_all <fstab> [ <path> ]* [--<option>]
Hung-ying Tyandc738ea2016-01-14 11:18:21 +0800315 Calls fs_mgr_mount_all on the given fs_mgr-format fstab and imports .rc files
Wei Wangabfbec32016-08-23 11:58:09 -0700316 at the specified paths (e.g., on the partitions just mounted) with optional
317 options "early" and "late".
318 Refer to the section of "Init .rc Files" for detail.
Elliott Hughes91a3be52015-03-20 11:00:15 -0700319
Niklas Tibblingbc3f69f2012-08-01 13:15:38 +0200320mount <type> <device> <dir> [ <flag> ]* [<options>]
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700321 Attempt to mount the named device at the directory <dir>
Niklas Tibblingbc3f69f2012-08-01 13:15:38 +0200322 <flag>s include "ro", "rw", "remount", "noatime", ...
323 <options> include "barrier=1", "noauto_da_alloc", "discard", ... as
324 a comma separated string, eg: barrier=1,noauto_da_alloc
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700325
Elliott Hughes91a3be52015-03-20 11:00:15 -0700326powerctl
327 Internal implementation detail used to respond to changes to the
328 "sys.powerctl" system property, used to implement rebooting.
329
330restart <service>
331 Like stop, but doesn't disable the service.
332
Stephen Smalley726e8f72013-10-09 16:02:09 -0400333restorecon <path> [ <path> ]*
Stephen Smalley3fb61102012-11-02 15:22:34 -0400334 Restore the file named by <path> to the security context specified
335 in the file_contexts configuration.
336 Not required for directories created by the init.rc as these are
337 automatically labeled correctly by init.
338
Stephen Smalley726e8f72013-10-09 16:02:09 -0400339restorecon_recursive <path> [ <path> ]*
340 Recursively restore the directory tree named by <path> to the
341 security contexts specified in the file_contexts configuration.
Stephen Smalley726e8f72013-10-09 16:02:09 -0400342
Elliott Hughes91a3be52015-03-20 11:00:15 -0700343rm <path>
344 Calls unlink(2) on the given path. You might want to
345 use "exec -- rm ..." instead (provided the system partition is
346 already mounted).
347
348rmdir <path>
349 Calls rmdir(2) on the given path.
350
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700351setprop <name> <value>
Elliott Hughesf682b472015-02-06 12:19:48 -0800352 Set system property <name> to <value>. Properties are expanded
353 within <value>.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700354
355setrlimit <resource> <cur> <max>
356 Set the rlimit for a resource.
357
358start <service>
359 Start a service running if it is not already running.
360
361stop <service>
362 Stop a service from running if it is currently running.
363
Elliott Hughes91a3be52015-03-20 11:00:15 -0700364swapon_all <fstab>
365 Calls fs_mgr_swapon_all on the given fstab file.
366
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700367symlink <target> <path>
368 Create a symbolic link at <path> with the value <target>
369
The Android Open Source Project35237d12008-12-17 18:08:08 -0800370sysclktz <mins_west_of_gmt>
371 Set the system clock base (0 if system clock ticks in GMT)
372
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700373trigger <event>
374 Trigger an event. Used to queue an action from another
375 action.
376
Alex Light68ab20f2016-06-23 11:11:39 -0700377umount <path>
378 Unmount the filesystem mounted at that path.
379
Elliott Hughes91a3be52015-03-20 11:00:15 -0700380verity_load_state
381 Internal implementation detail used to load dm-verity state.
382
383verity_update_state <mount_point>
384 Internal implementation detail used to update dm-verity state and
385 set the partition.<mount_point>.verified properties used by adb remount
386 because fs_mgr can't set them directly itself.
387
Patrick McCormick96d0a4d2011-02-04 10:51:39 -0800388wait <path> [ <timeout> ]
Elliott Hughes91a3be52015-03-20 11:00:15 -0700389 Poll for the existence of the given file and return when found,
390 or the timeout has been reached. If timeout is not specified it
391 currently defaults to five seconds.
Patrick McCormick96d0a4d2011-02-04 10:51:39 -0800392
Elliott Hughesf682b472015-02-06 12:19:48 -0800393write <path> <content>
394 Open the file at <path> and write a string to it with write(2).
395 If the file does not exist, it will be created. If it does exist,
396 it will be truncated. Properties are expanded within <content>.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700397
398
Tom Cherry3be66ed2015-09-01 14:49:38 -0700399Imports
400-------
401The import keyword is not a command, but rather its own section and is
402handled immediately after the .rc file that contains it has finished
403being parsed. It takes the below form:
404
405import <path>
406 Parse an init config file, extending the current configuration.
407 If <path> is a directory, each file in the directory is parsed as
408 a config file. It is not recursive, nested directories will
409 not be parsed.
410
411There are only two times where the init executable imports .rc files,
412 1) When it imports /init.rc during initial boot
Hung-ying Tyandc738ea2016-01-14 11:18:21 +0800413 2) When it imports /{system,vendor,odm}/etc/init/ or .rc files at specified
414 paths during mount_all
Tom Cherry3be66ed2015-09-01 14:49:38 -0700415
416
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700417Properties
418----------
Tom Cherry3be66ed2015-09-01 14:49:38 -0700419Init provides information about the services that it is responsible
420for via the below properties.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700421
422init.svc.<name>
Tom Cherry3be66ed2015-09-01 14:49:38 -0700423 State of a named service ("stopped", "stopping", "running", "restarting")
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700424
425
Elliott Hughes841b2632015-02-12 14:28:54 -0800426Bootcharting
427------------
Elliott Hughes841b2632015-02-12 14:28:54 -0800428This version of init contains code to perform "bootcharting": generating log
429files that can be later processed by the tools provided by www.bootchart.org.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700430
Elliott Hughes59abac22015-03-28 12:12:51 -0700431On the emulator, use the -bootchart <timeout> option to boot with bootcharting
432activated for <timeout> seconds.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700433
Elliott Hughes841b2632015-02-12 14:28:54 -0800434On a device, create /data/bootchart/start with a command like the following:
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700435
Elliott Hughes841b2632015-02-12 14:28:54 -0800436 adb shell 'echo $TIMEOUT > /data/bootchart/start'
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700437
Elliott Hughes841b2632015-02-12 14:28:54 -0800438Where the value of $TIMEOUT corresponds to the desired bootcharted period in
439seconds. Bootcharting will stop after that many seconds have elapsed.
440You can also stop the bootcharting at any moment by doing the following:
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700441
Elliott Hughes841b2632015-02-12 14:28:54 -0800442 adb shell 'echo 1 > /data/bootchart/stop'
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700443
Elliott Hughes841b2632015-02-12 14:28:54 -0800444Note that /data/bootchart/stop is deleted automatically by init at the end of
445the bootcharting. This is not the case with /data/bootchart/start, so don't
446forget to delete it when you're done collecting data.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700447
Elliott Hughes841b2632015-02-12 14:28:54 -0800448The log files are written to /data/bootchart/. A script is provided to
449retrieve them and create a bootchart.tgz file that can be used with the
450bootchart command-line utility:
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700451
Elliott Hughes841b2632015-02-12 14:28:54 -0800452 sudo apt-get install pybootchartgui
Elliott Hughes59abac22015-03-28 12:12:51 -0700453 # grab-bootchart.sh uses $ANDROID_SERIAL.
Elliott Hughes841b2632015-02-12 14:28:54 -0800454 $ANDROID_BUILD_TOP/system/core/init/grab-bootchart.sh
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700455
Elliott Hughes59abac22015-03-28 12:12:51 -0700456One thing to watch for is that the bootchart will show init as if it started
457running at 0s. You'll have to look at dmesg to work out when the kernel
458actually started init.
459
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700460
Ben Cheng50bbde02015-06-09 17:04:36 +0800461Comparing two bootcharts
462------------------------
463A handy script named compare-bootcharts.py can be used to compare the
464start/end time of selected processes. The aforementioned grab-bootchart.sh
465will leave a bootchart tarball named bootchart.tgz at /tmp/android-bootchart.
466If two such barballs are preserved on the host machine under different
467directories, the script can list the timestamps differences. For example:
468
469Usage: system/core/init/compare-bootcharts.py base_bootchart_dir
470 exp_bootchart_dir
471
472process: baseline experiment (delta)
473 - Unit is ms (a jiffy is 10 ms on the system)
474------------------------------------
475/init: 50 40 (-10)
476/system/bin/surfaceflinger: 4320 4470 (+150)
477/system/bin/bootanimation: 6980 6990 (+10)
478zygote64: 10410 10640 (+230)
479zygote: 10410 10640 (+230)
480system_server: 15350 15150 (-200)
481bootanimation ends at: 33790 31230 (-2560)
482
483
Yasuhiro Matsudaf93db4b2015-06-15 18:49:35 +0900484Systrace
485--------
486Systrace [1] can be used for obtaining performance analysis reports during boot
487time on userdebug or eng builds.
488Here is an example of trace events of "wm" and "am" categories:
489
490 $ANDROID_BUILD_TOP/external/chromium-trace/systrace.py wm am --boot
491
492This command will cause the device to reboot. After the device is rebooted and
493the boot sequence has finished, the trace report is obtained from the device
494and written as trace.html on the host by hitting Ctrl+C.
495
496LIMITATION
497Recording trace events is started after persistent properties are loaded, so
498the trace events that are emitted before that are not recorded. Several
499services such as vold, surfaceflinger, and servicemanager are affected by this
500limitation since they are started before persistent properties are loaded.
501Zygote initialization and the processes that are forked from the zygote are not
502affected.
503
504[1] http://developer.android.com/tools/help/systrace.html
505
506
Elliott Hughes841b2632015-02-12 14:28:54 -0800507Debugging init
508--------------
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700509By default, programs executed by init will drop stdout and stderr into
510/dev/null. To help with debugging, you can execute your program via the
Elliott Hughesf682b472015-02-06 12:19:48 -0800511Android program logwrapper. This will redirect stdout/stderr into the
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700512Android logging system (accessed via logcat).
513
514For example
515service akmd /system/bin/logwrapper /sbin/akmd
Elliott Hughesf682b472015-02-06 12:19:48 -0800516
517For quicker turnaround when working on init itself, use:
518
Elliott Hughes841b2632015-02-12 14:28:54 -0800519 mm -j
Elliott Hughesf682b472015-02-06 12:19:48 -0800520 m ramdisk-nodeps
521 m bootimage-nodeps
522 adb reboot bootloader
523 fastboot boot $ANDROID_PRODUCT_OUT/boot.img
524
525Alternatively, use the emulator:
526
527 emulator -partition-size 1024 -verbose -show-kernel -no-window