blob: 56918f60d4a353a0e4c04d608f692846dfd4b71c [file] [log] [blame]
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -07001
2Android Init Language
3---------------------
4
Tom Cherry3be66ed2015-09-01 14:49:38 -07005The Android Init Language consists of five broad classes of statements,
6which are Actions, Commands, Services, Options, and Imports.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -07007
8All of these are line-oriented, consisting of tokens separated by
9whitespace. The c-style backslash escapes may be used to insert
10whitespace into a token. Double quotes may also be used to prevent
11whitespace from breaking text into multiple tokens. The backslash,
12when it is the last character on a line, may be used for line-folding.
13
14Lines which start with a # (leading whitespace allowed) are comments.
15
16Actions and Services implicitly declare a new section. All commands
17or options belong to the section most recently declared. Commands
18or options before the first section are ignored.
19
Tom Cherry3be66ed2015-09-01 14:49:38 -070020Actions and Services have unique names. If a second Action is defined
21with the same name as an existing one, its commands are appended to
22the commands of the existing action. If a second Service is defined
23with the same name as an existing one, it is ignored and an error
24message is logged.
25
26
27Init .rc Files
28--------------
29The init language is used in plaintext files that take the .rc file
30extension. These are typically multiple of these in multiple
31locations on the system, described below.
32
33/init.rc is the primary .rc file and is loaded by the init executable
34at the beginning of its execution. It is responsible for the initial
35set up of the system. It imports /init.${ro.hardware}.rc which is the
36primary vendor supplied .rc file.
37
38During the mount_all command, the init executable loads all of the
39files contained within the /{system,vendor,odm}/etc/init/ directories.
40These directories are intended for all Actions and Services used after
41file system mounting.
42
Tom Cherry1fb20b82016-01-20 16:53:08 -080043One may specify paths in the mount_all command line to have it import
44.rc files at the specified paths instead of the default ones listed above.
45This is primarily for supporting factory mode and other non-standard boot
46modes. The three default paths should be used for the normal boot process.
47
Tom Cherry3be66ed2015-09-01 14:49:38 -070048The intention of these directories is as follows
49 1) /system/etc/init/ is for core system items such as
Tom Cherry1fb20b82016-01-20 16:53:08 -080050 SurfaceFlinger, MediaService, and logcatd.
Tom Cherry3be66ed2015-09-01 14:49:38 -070051 2) /vendor/etc/init/ is for SoC vendor items such as actions or
52 daemons needed for core SoC functionality.
53 3) /odm/etc/init/ is for device manufacturer items such as
54 actions or daemons needed for motion sensor or other peripheral
55 functionality.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -070056
Tom Cherry1fb20b82016-01-20 16:53:08 -080057All services whose binaries reside on the system, vendor, or odm
58partitions should have their service entries placed into a
59corresponding init .rc file, located in the /etc/init/
60directory of the partition where they reside. There is a build
61system macro, LOCAL_INIT_RC, that handles this for developers. Each
62init .rc file should additionally contain any actions associated with
63its service.
64
65An example is the logcatd.rc and Android.mk files located in the
66system/core/logcat directory. The LOCAL_INIT_RC macro in the
67Android.mk file places logcatd.rc in /system/etc/init/ during the
68build process. Init loads logcatd.rc during the mount_all command and
69allows the service to be run and the action to be queued when
70appropriate.
71
72This break up of init .rc files according to their daemon is preferred
73to the previously used monolithic init .rc files. This approach
74ensures that the only service entries that init reads and the only
75actions that init performs correspond to services whose binaries are in
76fact present on the file system, which was not the case with the
77monolithic init .rc files. This additionally will aid in merge
78conflict resolution when multiple services are added to the system, as
79each one will go into a separate file.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -070080
81Actions
82-------
83Actions are named sequences of commands. Actions have a trigger which
84is used to determine when the action should occur. When an event
85occurs which matches an action's trigger, that action is added to
86the tail of a to-be-executed queue (unless it is already on the
87queue).
88
89Each action in the queue is dequeued in sequence and each command in
90that action is executed in sequence. Init handles other activities
91(device creation/destruction, property setting, process restarting)
92"between" the execution of the commands in activities.
93
94Actions take the form of:
95
Tom Cherry3be66ed2015-09-01 14:49:38 -070096on <trigger> [&& <trigger>]*
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -070097 <command>
98 <command>
99 <command>
100
101
102Services
103--------
104Services are programs which init launches and (optionally) restarts
105when they exit. Services take the form of:
106
107service <name> <pathname> [ <argument> ]*
108 <option>
109 <option>
110 ...
111
112
113Options
114-------
115Options are modifiers to services. They affect how and when init
116runs the service.
117
Viorel Suman70daa672016-03-21 10:08:07 +0200118console [<console>]
119 This service needs a console. The optional second parameter chooses a
120 specific console instead of the default. The default "/dev/console" can
121 be changed by setting the "androidboot.console" kernel parameter. In
122 all cases the leading "/dev/" should be omitted, so "/dev/tty0" would be
123 specified as just "console tty0".
124
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700125critical
Elliott Hughesd62f0602015-06-12 18:02:20 -0700126 This is a device-critical service. If it exits more than four times in
127 four minutes, the device will reboot into recovery mode.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700128
129disabled
Elliott Hughesd62f0602015-06-12 18:02:20 -0700130 This service will not automatically start with its class.
131 It must be explicitly started by name.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700132
133setenv <name> <value>
Elliott Hughesd62f0602015-06-12 18:02:20 -0700134 Set the environment variable <name> to <value> in the launched process.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700135
Elliott Hughes8d82ea02015-02-06 20:15:18 -0800136socket <name> <type> <perm> [ <user> [ <group> [ <seclabel> ] ] ]
Elliott Hughesd62f0602015-06-12 18:02:20 -0700137 Create a unix domain socket named /dev/socket/<name> and pass
138 its fd to the launched process. <type> must be "dgram", "stream" or "seqpacket".
139 User and group default to 0.
140 'seclabel' is the SELinux security context for the socket.
141 It defaults to the service security context, as specified by seclabel or
142 computed based on the service executable file security context.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700143
144user <username>
Elliott Hughesd62f0602015-06-12 18:02:20 -0700145 Change to username before exec'ing this service.
146 Currently defaults to root. (??? probably should default to nobody)
Tom Cherrydbddb402015-12-11 12:54:50 -0800147 As of Android M, processes should use this option even if they
148 require linux capabilities. Previously, to acquire linux
149 capabilities, a process would need to run as root, request the
150 capabilities, then drop to its desired uid. There is a new
151 mechanism through fs_config that allows device manufacturers to add
152 linux capabilities to specific binaries on a file system that should
153 be used instead. This mechanism is described on
154 http://source.android.com/devices/tech/config/filesystem.html. When
155 using this new mechanism, processes can use the user option to
156 select their desired uid without ever running as root.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700157
158group <groupname> [ <groupname> ]*
Elliott Hughesd62f0602015-06-12 18:02:20 -0700159 Change to groupname before exec'ing this service. Additional
160 groupnames beyond the (required) first one are used to set the
161 supplemental groups of the process (via setgroups()).
162 Currently defaults to root. (??? probably should default to nobody)
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700163
Elliott Hughes8d82ea02015-02-06 20:15:18 -0800164seclabel <seclabel>
165 Change to 'seclabel' before exec'ing this service.
Stephen Smalley3fb61102012-11-02 15:22:34 -0400166 Primarily for use by services run from the rootfs, e.g. ueventd, adbd.
167 Services on the system partition can instead use policy-defined transitions
168 based on their file security context.
169 If not specified and no transition is defined in policy, defaults to the init context.
170
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700171oneshot
Elliott Hughesd62f0602015-06-12 18:02:20 -0700172 Do not restart the service when it exits.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700173
174class <name>
Elliott Hughesd62f0602015-06-12 18:02:20 -0700175 Specify a class name for the service. All services in a
176 named class may be started or stopped together. A service
177 is in the class "default" if one is not specified via the
178 class option.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700179
180onrestart
Elliott Hughesd62f0602015-06-12 18:02:20 -0700181 Execute a Command (see below) when service restarts.
182
183writepid <file...>
184 Write the child's pid to the given files when it forks. Meant for
185 cgroup/cpuset usage.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700186
Vitalii Tomkiv081705c2016-05-18 17:36:30 -0700187priority <priority>
188 Scheduling priority of the service process. This value has to be in range
189 -20 to 19. Default priority is 0. Priority is set via setpriority().
Elliott Hughes841b2632015-02-12 14:28:54 -0800190
Jorge Lucangeli Obescd2518c2016-08-31 15:23:44 -0400191namespace <pid|mnt>
192 Enter a new PID or mount namespace when forking the service.
193
194
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700195Triggers
196--------
Tom Cherry3be66ed2015-09-01 14:49:38 -0700197Triggers are strings which can be used to match certain kinds of
198events and used to cause an action to occur.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700199
Tom Cherry3be66ed2015-09-01 14:49:38 -0700200Triggers are subdivided into event triggers and property triggers.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700201
Tom Cherry3be66ed2015-09-01 14:49:38 -0700202Event triggers are strings triggered by the 'trigger' command or by
203the QueueEventTrigger() function within the init executable. These
204take the form of a simple string such as 'boot' or 'late-init'.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700205
Tom Cherry3be66ed2015-09-01 14:49:38 -0700206Property triggers are strings triggered when a named property changes
207value to a given new value or when a named property changes value to
208any new value. These take the form of 'property:<name>=<value>' and
209'property:<name>=*' respectively. Property triggers are additionally
210evaluated and triggered accordingly during the initial boot phase of
211init.
Badhri Jagan Sridharan0b415122014-10-10 23:19:06 -0700212
Tom Cherry3be66ed2015-09-01 14:49:38 -0700213An Action can have multiple property triggers but may only have one
214event trigger.
Badhri Jagan Sridharan0b415122014-10-10 23:19:06 -0700215
Tom Cherry3be66ed2015-09-01 14:49:38 -0700216For example:
217'on boot && property:a=b' defines an action that is only executed when
218the 'boot' event trigger happens and the property a equals b.
219
220'on property:a=b && property:c=d' defines an action that is executed
221at three times,
222 1) During initial boot if property a=b and property c=d
223 2) Any time that property a transitions to value b, while property
224 c already equals d.
225 3) Any time that property c transitions to value d, while property
226 a already equals b.
Badhri Jagan Sridharan0b415122014-10-10 23:19:06 -0700227
Elliott Hughes841b2632015-02-12 14:28:54 -0800228
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700229Commands
230--------
231
Elliott Hughes91a3be52015-03-20 11:00:15 -0700232bootchart_init
233 Start bootcharting if configured (see below).
234 This is included in the default init.rc.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700235
236chmod <octal-mode> <path>
237 Change file access permissions.
238
239chown <owner> <group> <path>
240 Change file owner and group.
241
242class_start <serviceclass>
243 Start all services of the specified class if they are
244 not already running.
245
246class_stop <serviceclass>
Elliott Hughes91a3be52015-03-20 11:00:15 -0700247 Stop and disable all services of the specified class if they are
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700248 currently running.
249
Elliott Hughes91a3be52015-03-20 11:00:15 -0700250class_reset <serviceclass>
251 Stop all services of the specified class if they are
252 currently running, without disabling them. They can be restarted
253 later using class_start.
254
255copy <src> <dst>
256 Copies a file. Similar to write, but useful for binary/large
257 amounts of data.
258
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700259domainname <name>
260 Set the domain name.
261
JP Abgrall3beec7e2014-05-02 21:14:29 -0700262enable <servicename>
263 Turns a disabled service into an enabled one as if the service did not
264 specify disabled.
265 If the service is supposed to be running, it will be started now.
266 Typically used when the bootloader sets a variable that indicates a specific
267 service should be started when needed. E.g.
268 on property:ro.boot.myfancyhardware=1
269 enable my_fancy_service_for_my_fancy_hardware
270
Elliott Hughes91a3be52015-03-20 11:00:15 -0700271exec [ <seclabel> [ <user> [ <group> ]* ] ] -- <command> [ <argument> ]*
272 Fork and execute command with the given arguments. The command starts
273 after "--" so that an optional security context, user, and supplementary
274 groups can be provided. No other commands will be run until this one
Mark Salyzyn17fff892015-06-02 11:11:02 -0700275 finishes. <seclabel> can be a - to denote default.
Elliott Hughes91a3be52015-03-20 11:00:15 -0700276
Elliott Hughes91a3be52015-03-20 11:00:15 -0700277export <name> <value>
278 Set the environment variable <name> equal to <value> in the
279 global environment (which will be inherited by all processes
280 started after this command is executed)
281
282hostname <name>
283 Set the host name.
284
285ifup <interface>
286 Bring the network interface <interface> online.
287
Hung-ying Tyanbfa6d752016-05-17 18:49:10 +0800288insmod [-f] <path> [<options>]
289 Install the module at <path> with the specified options.
290 -f
291 Force installation of the module even if the version of the running kernel
292 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 -0700293
Elliott Hughes91a3be52015-03-20 11:00:15 -0700294load_all_props
295 Loads properties from /system, /vendor, et cetera.
296 This is included in the default init.rc.
297
298load_persist_props
299 Loads persistent properties when /data has been decrypted.
300 This is included in the default init.rc.
301
Elliott Hughesf682b472015-02-06 12:19:48 -0800302loglevel <level>
303 Sets the kernel log level to level. Properties are expanded within <level>.
304
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700305mkdir <path> [mode] [owner] [group]
306 Create a directory at <path>, optionally with the given mode, owner, and
307 group. If not provided, the directory is created with permissions 755 and
Johan Redestig0b42ba22015-03-15 17:39:41 +0100308 owned by the root user and root group. If provided, the mode, owner and group
309 will be updated if the directory exists already.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700310
Hung-ying Tyandc738ea2016-01-14 11:18:21 +0800311mount_all <fstab> [ <path> ]*
312 Calls fs_mgr_mount_all on the given fs_mgr-format fstab and imports .rc files
313 at the specified paths (e.g., on the partitions just mounted). Refer to the
314 section of "Init .rc Files" for detail.
Elliott Hughes91a3be52015-03-20 11:00:15 -0700315
Niklas Tibblingbc3f69f2012-08-01 13:15:38 +0200316mount <type> <device> <dir> [ <flag> ]* [<options>]
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700317 Attempt to mount the named device at the directory <dir>
Niklas Tibblingbc3f69f2012-08-01 13:15:38 +0200318 <flag>s include "ro", "rw", "remount", "noatime", ...
319 <options> include "barrier=1", "noauto_da_alloc", "discard", ... as
320 a comma separated string, eg: barrier=1,noauto_da_alloc
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700321
Elliott Hughes91a3be52015-03-20 11:00:15 -0700322powerctl
323 Internal implementation detail used to respond to changes to the
324 "sys.powerctl" system property, used to implement rebooting.
325
326restart <service>
327 Like stop, but doesn't disable the service.
328
Stephen Smalley726e8f72013-10-09 16:02:09 -0400329restorecon <path> [ <path> ]*
Stephen Smalley3fb61102012-11-02 15:22:34 -0400330 Restore the file named by <path> to the security context specified
331 in the file_contexts configuration.
332 Not required for directories created by the init.rc as these are
333 automatically labeled correctly by init.
334
Stephen Smalley726e8f72013-10-09 16:02:09 -0400335restorecon_recursive <path> [ <path> ]*
336 Recursively restore the directory tree named by <path> to the
337 security contexts specified in the file_contexts configuration.
Stephen Smalley726e8f72013-10-09 16:02:09 -0400338
Elliott Hughes91a3be52015-03-20 11:00:15 -0700339rm <path>
340 Calls unlink(2) on the given path. You might want to
341 use "exec -- rm ..." instead (provided the system partition is
342 already mounted).
343
344rmdir <path>
345 Calls rmdir(2) on the given path.
346
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700347setprop <name> <value>
Elliott Hughesf682b472015-02-06 12:19:48 -0800348 Set system property <name> to <value>. Properties are expanded
349 within <value>.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700350
351setrlimit <resource> <cur> <max>
352 Set the rlimit for a resource.
353
354start <service>
355 Start a service running if it is not already running.
356
357stop <service>
358 Stop a service from running if it is currently running.
359
Elliott Hughes91a3be52015-03-20 11:00:15 -0700360swapon_all <fstab>
361 Calls fs_mgr_swapon_all on the given fstab file.
362
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700363symlink <target> <path>
364 Create a symbolic link at <path> with the value <target>
365
The Android Open Source Project35237d12008-12-17 18:08:08 -0800366sysclktz <mins_west_of_gmt>
367 Set the system clock base (0 if system clock ticks in GMT)
368
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700369trigger <event>
370 Trigger an event. Used to queue an action from another
371 action.
372
Elliott Hughes91a3be52015-03-20 11:00:15 -0700373verity_load_state
374 Internal implementation detail used to load dm-verity state.
375
376verity_update_state <mount_point>
377 Internal implementation detail used to update dm-verity state and
378 set the partition.<mount_point>.verified properties used by adb remount
379 because fs_mgr can't set them directly itself.
380
Patrick McCormick96d0a4d2011-02-04 10:51:39 -0800381wait <path> [ <timeout> ]
Elliott Hughes91a3be52015-03-20 11:00:15 -0700382 Poll for the existence of the given file and return when found,
383 or the timeout has been reached. If timeout is not specified it
384 currently defaults to five seconds.
Patrick McCormick96d0a4d2011-02-04 10:51:39 -0800385
Elliott Hughesf682b472015-02-06 12:19:48 -0800386write <path> <content>
387 Open the file at <path> and write a string to it with write(2).
388 If the file does not exist, it will be created. If it does exist,
389 it will be truncated. Properties are expanded within <content>.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700390
391
Tom Cherry3be66ed2015-09-01 14:49:38 -0700392Imports
393-------
394The import keyword is not a command, but rather its own section and is
395handled immediately after the .rc file that contains it has finished
396being parsed. It takes the below form:
397
398import <path>
399 Parse an init config file, extending the current configuration.
400 If <path> is a directory, each file in the directory is parsed as
401 a config file. It is not recursive, nested directories will
402 not be parsed.
403
404There are only two times where the init executable imports .rc files,
405 1) When it imports /init.rc during initial boot
Hung-ying Tyandc738ea2016-01-14 11:18:21 +0800406 2) When it imports /{system,vendor,odm}/etc/init/ or .rc files at specified
407 paths during mount_all
Tom Cherry3be66ed2015-09-01 14:49:38 -0700408
409
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700410Properties
411----------
Tom Cherry3be66ed2015-09-01 14:49:38 -0700412Init provides information about the services that it is responsible
413for via the below properties.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700414
415init.svc.<name>
Tom Cherry3be66ed2015-09-01 14:49:38 -0700416 State of a named service ("stopped", "stopping", "running", "restarting")
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700417
418
Elliott Hughes841b2632015-02-12 14:28:54 -0800419Bootcharting
420------------
Elliott Hughes841b2632015-02-12 14:28:54 -0800421This version of init contains code to perform "bootcharting": generating log
422files that can be later processed by the tools provided by www.bootchart.org.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700423
Elliott Hughes59abac22015-03-28 12:12:51 -0700424On the emulator, use the -bootchart <timeout> option to boot with bootcharting
425activated for <timeout> seconds.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700426
Elliott Hughes841b2632015-02-12 14:28:54 -0800427On a device, create /data/bootchart/start with a command like the following:
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700428
Elliott Hughes841b2632015-02-12 14:28:54 -0800429 adb shell 'echo $TIMEOUT > /data/bootchart/start'
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700430
Elliott Hughes841b2632015-02-12 14:28:54 -0800431Where the value of $TIMEOUT corresponds to the desired bootcharted period in
432seconds. Bootcharting will stop after that many seconds have elapsed.
433You can also stop the bootcharting at any moment by doing the following:
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700434
Elliott Hughes841b2632015-02-12 14:28:54 -0800435 adb shell 'echo 1 > /data/bootchart/stop'
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700436
Elliott Hughes841b2632015-02-12 14:28:54 -0800437Note that /data/bootchart/stop is deleted automatically by init at the end of
438the bootcharting. This is not the case with /data/bootchart/start, so don't
439forget to delete it when you're done collecting data.
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700440
Elliott Hughes841b2632015-02-12 14:28:54 -0800441The log files are written to /data/bootchart/. A script is provided to
442retrieve them and create a bootchart.tgz file that can be used with the
443bootchart command-line utility:
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700444
Elliott Hughes841b2632015-02-12 14:28:54 -0800445 sudo apt-get install pybootchartgui
Elliott Hughes59abac22015-03-28 12:12:51 -0700446 # grab-bootchart.sh uses $ANDROID_SERIAL.
Elliott Hughes841b2632015-02-12 14:28:54 -0800447 $ANDROID_BUILD_TOP/system/core/init/grab-bootchart.sh
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700448
Elliott Hughes59abac22015-03-28 12:12:51 -0700449One thing to watch for is that the bootchart will show init as if it started
450running at 0s. You'll have to look at dmesg to work out when the kernel
451actually started init.
452
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700453
Ben Cheng50bbde02015-06-09 17:04:36 +0800454Comparing two bootcharts
455------------------------
456A handy script named compare-bootcharts.py can be used to compare the
457start/end time of selected processes. The aforementioned grab-bootchart.sh
458will leave a bootchart tarball named bootchart.tgz at /tmp/android-bootchart.
459If two such barballs are preserved on the host machine under different
460directories, the script can list the timestamps differences. For example:
461
462Usage: system/core/init/compare-bootcharts.py base_bootchart_dir
463 exp_bootchart_dir
464
465process: baseline experiment (delta)
466 - Unit is ms (a jiffy is 10 ms on the system)
467------------------------------------
468/init: 50 40 (-10)
469/system/bin/surfaceflinger: 4320 4470 (+150)
470/system/bin/bootanimation: 6980 6990 (+10)
471zygote64: 10410 10640 (+230)
472zygote: 10410 10640 (+230)
473system_server: 15350 15150 (-200)
474bootanimation ends at: 33790 31230 (-2560)
475
476
Yasuhiro Matsudaf93db4b2015-06-15 18:49:35 +0900477Systrace
478--------
479Systrace [1] can be used for obtaining performance analysis reports during boot
480time on userdebug or eng builds.
481Here is an example of trace events of "wm" and "am" categories:
482
483 $ANDROID_BUILD_TOP/external/chromium-trace/systrace.py wm am --boot
484
485This command will cause the device to reboot. After the device is rebooted and
486the boot sequence has finished, the trace report is obtained from the device
487and written as trace.html on the host by hitting Ctrl+C.
488
489LIMITATION
490Recording trace events is started after persistent properties are loaded, so
491the trace events that are emitted before that are not recorded. Several
492services such as vold, surfaceflinger, and servicemanager are affected by this
493limitation since they are started before persistent properties are loaded.
494Zygote initialization and the processes that are forked from the zygote are not
495affected.
496
497[1] http://developer.android.com/tools/help/systrace.html
498
499
Elliott Hughes841b2632015-02-12 14:28:54 -0800500Debugging init
501--------------
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700502By default, programs executed by init will drop stdout and stderr into
503/dev/null. To help with debugging, you can execute your program via the
Elliott Hughesf682b472015-02-06 12:19:48 -0800504Android program logwrapper. This will redirect stdout/stderr into the
The Android Open Source Project4f6e8d72008-10-21 07:00:00 -0700505Android logging system (accessed via logcat).
506
507For example
508service akmd /system/bin/logwrapper /sbin/akmd
Elliott Hughesf682b472015-02-06 12:19:48 -0800509
510For quicker turnaround when working on init itself, use:
511
Elliott Hughes841b2632015-02-12 14:28:54 -0800512 mm -j
Elliott Hughesf682b472015-02-06 12:19:48 -0800513 m ramdisk-nodeps
514 m bootimage-nodeps
515 adb reboot bootloader
516 fastboot boot $ANDROID_PRODUCT_OUT/boot.img
517
518Alternatively, use the emulator:
519
520 emulator -partition-size 1024 -verbose -show-kernel -no-window