The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1 | |
| 2 | Android Init Language |
| 3 | --------------------- |
| 4 | |
| 5 | The Android Init Language consists of four broad classes of statements, |
| 6 | which are Actions, Commands, Services, and Options. |
| 7 | |
| 8 | All of these are line-oriented, consisting of tokens separated by |
| 9 | whitespace. The c-style backslash escapes may be used to insert |
| 10 | whitespace into a token. Double quotes may also be used to prevent |
| 11 | whitespace from breaking text into multiple tokens. The backslash, |
| 12 | when it is the last character on a line, may be used for line-folding. |
| 13 | |
| 14 | Lines which start with a # (leading whitespace allowed) are comments. |
| 15 | |
| 16 | Actions and Services implicitly declare a new section. All commands |
| 17 | or options belong to the section most recently declared. Commands |
| 18 | or options before the first section are ignored. |
| 19 | |
| 20 | Actions and Services have unique names. If a second Action or Service |
| 21 | is declared with the same name as an existing one, it is ignored as |
| 22 | an error. (??? should we override instead) |
| 23 | |
| 24 | |
| 25 | Actions |
| 26 | ------- |
| 27 | Actions are named sequences of commands. Actions have a trigger which |
| 28 | is used to determine when the action should occur. When an event |
| 29 | occurs which matches an action's trigger, that action is added to |
| 30 | the tail of a to-be-executed queue (unless it is already on the |
| 31 | queue). |
| 32 | |
| 33 | Each action in the queue is dequeued in sequence and each command in |
| 34 | that action is executed in sequence. Init handles other activities |
| 35 | (device creation/destruction, property setting, process restarting) |
| 36 | "between" the execution of the commands in activities. |
| 37 | |
| 38 | Actions take the form of: |
| 39 | |
| 40 | on <trigger> |
| 41 | <command> |
| 42 | <command> |
| 43 | <command> |
| 44 | |
| 45 | |
| 46 | Services |
| 47 | -------- |
| 48 | Services are programs which init launches and (optionally) restarts |
| 49 | when they exit. Services take the form of: |
| 50 | |
| 51 | service <name> <pathname> [ <argument> ]* |
| 52 | <option> |
| 53 | <option> |
| 54 | ... |
| 55 | |
| 56 | |
| 57 | Options |
| 58 | ------- |
| 59 | Options are modifiers to services. They affect how and when init |
| 60 | runs the service. |
| 61 | |
| 62 | critical |
Elliott Hughes | d62f060 | 2015-06-12 18:02:20 -0700 | [diff] [blame] | 63 | This is a device-critical service. If it exits more than four times in |
| 64 | four minutes, the device will reboot into recovery mode. |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 65 | |
| 66 | disabled |
Elliott Hughes | d62f060 | 2015-06-12 18:02:20 -0700 | [diff] [blame] | 67 | This service will not automatically start with its class. |
| 68 | It must be explicitly started by name. |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 69 | |
| 70 | setenv <name> <value> |
Elliott Hughes | d62f060 | 2015-06-12 18:02:20 -0700 | [diff] [blame] | 71 | Set the environment variable <name> to <value> in the launched process. |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 72 | |
Elliott Hughes | 8d82ea0 | 2015-02-06 20:15:18 -0800 | [diff] [blame] | 73 | socket <name> <type> <perm> [ <user> [ <group> [ <seclabel> ] ] ] |
Elliott Hughes | d62f060 | 2015-06-12 18:02:20 -0700 | [diff] [blame] | 74 | Create a unix domain socket named /dev/socket/<name> and pass |
| 75 | its fd to the launched process. <type> must be "dgram", "stream" or "seqpacket". |
| 76 | User and group default to 0. |
| 77 | 'seclabel' is the SELinux security context for the socket. |
| 78 | It defaults to the service security context, as specified by seclabel or |
| 79 | computed based on the service executable file security context. |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 80 | |
| 81 | user <username> |
Elliott Hughes | d62f060 | 2015-06-12 18:02:20 -0700 | [diff] [blame] | 82 | Change to username before exec'ing this service. |
| 83 | Currently defaults to root. (??? probably should default to nobody) |
| 84 | Currently, if your process requires linux capabilities then you cannot use |
| 85 | this command. You must instead request the capabilities in-process while |
| 86 | still root, and then drop to your desired uid. |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 87 | |
| 88 | group <groupname> [ <groupname> ]* |
Elliott Hughes | d62f060 | 2015-06-12 18:02:20 -0700 | [diff] [blame] | 89 | Change to groupname before exec'ing this service. Additional |
| 90 | groupnames beyond the (required) first one are used to set the |
| 91 | supplemental groups of the process (via setgroups()). |
| 92 | Currently defaults to root. (??? probably should default to nobody) |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 93 | |
Elliott Hughes | 8d82ea0 | 2015-02-06 20:15:18 -0800 | [diff] [blame] | 94 | seclabel <seclabel> |
| 95 | Change to 'seclabel' before exec'ing this service. |
Stephen Smalley | 3fb6110 | 2012-11-02 15:22:34 -0400 | [diff] [blame] | 96 | Primarily for use by services run from the rootfs, e.g. ueventd, adbd. |
| 97 | Services on the system partition can instead use policy-defined transitions |
| 98 | based on their file security context. |
| 99 | If not specified and no transition is defined in policy, defaults to the init context. |
| 100 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 101 | oneshot |
Elliott Hughes | d62f060 | 2015-06-12 18:02:20 -0700 | [diff] [blame] | 102 | Do not restart the service when it exits. |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 103 | |
| 104 | class <name> |
Elliott Hughes | d62f060 | 2015-06-12 18:02:20 -0700 | [diff] [blame] | 105 | Specify a class name for the service. All services in a |
| 106 | named class may be started or stopped together. A service |
| 107 | is in the class "default" if one is not specified via the |
| 108 | class option. |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 109 | |
| 110 | onrestart |
Elliott Hughes | d62f060 | 2015-06-12 18:02:20 -0700 | [diff] [blame] | 111 | Execute a Command (see below) when service restarts. |
| 112 | |
| 113 | writepid <file...> |
| 114 | Write the child's pid to the given files when it forks. Meant for |
| 115 | cgroup/cpuset usage. |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 116 | |
Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 117 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 118 | Triggers |
| 119 | -------- |
Elliott Hughes | d62f060 | 2015-06-12 18:02:20 -0700 | [diff] [blame] | 120 | Triggers are strings which can be used to match certain kinds |
| 121 | of events and used to cause an action to occur. |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 122 | |
| 123 | boot |
| 124 | This is the first trigger that will occur when init starts |
| 125 | (after /init.conf is loaded) |
| 126 | |
| 127 | <name>=<value> |
| 128 | Triggers of this form occur when the property <name> is set |
| 129 | to the specific value <value>. |
| 130 | |
Elliott Hughes | d3e37d1 | 2015-02-02 16:43:32 -0800 | [diff] [blame] | 131 | One can also test multiple properties to execute a group |
Badhri Jagan Sridharan | 0b41512 | 2014-10-10 23:19:06 -0700 | [diff] [blame] | 132 | of commands. For example: |
| 133 | |
| 134 | on property:test.a=1 && property:test.b=1 |
| 135 | setprop test.c 1 |
| 136 | |
| 137 | The above stub sets test.c to 1 only when |
| 138 | both test.a=1 and test.b=1 |
| 139 | |
Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 140 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 141 | Commands |
| 142 | -------- |
| 143 | |
Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 144 | bootchart_init |
| 145 | Start bootcharting if configured (see below). |
| 146 | This is included in the default init.rc. |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 147 | |
| 148 | chmod <octal-mode> <path> |
| 149 | Change file access permissions. |
| 150 | |
| 151 | chown <owner> <group> <path> |
| 152 | Change file owner and group. |
| 153 | |
| 154 | class_start <serviceclass> |
| 155 | Start all services of the specified class if they are |
| 156 | not already running. |
| 157 | |
| 158 | class_stop <serviceclass> |
Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 159 | Stop and disable all services of the specified class if they are |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 160 | currently running. |
| 161 | |
Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 162 | class_reset <serviceclass> |
| 163 | Stop all services of the specified class if they are |
| 164 | currently running, without disabling them. They can be restarted |
| 165 | later using class_start. |
| 166 | |
| 167 | copy <src> <dst> |
| 168 | Copies a file. Similar to write, but useful for binary/large |
| 169 | amounts of data. |
| 170 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 171 | domainname <name> |
| 172 | Set the domain name. |
| 173 | |
JP Abgrall | 3beec7e | 2014-05-02 21:14:29 -0700 | [diff] [blame] | 174 | enable <servicename> |
| 175 | Turns a disabled service into an enabled one as if the service did not |
| 176 | specify disabled. |
| 177 | If the service is supposed to be running, it will be started now. |
| 178 | Typically used when the bootloader sets a variable that indicates a specific |
| 179 | service should be started when needed. E.g. |
| 180 | on property:ro.boot.myfancyhardware=1 |
| 181 | enable my_fancy_service_for_my_fancy_hardware |
| 182 | |
Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 183 | exec [ <seclabel> [ <user> [ <group> ]* ] ] -- <command> [ <argument> ]* |
| 184 | Fork and execute command with the given arguments. The command starts |
| 185 | after "--" so that an optional security context, user, and supplementary |
| 186 | groups can be provided. No other commands will be run until this one |
Mark Salyzyn | 17fff89 | 2015-06-02 11:11:02 -0700 | [diff] [blame] | 187 | finishes. <seclabel> can be a - to denote default. |
Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 188 | |
Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 189 | export <name> <value> |
| 190 | Set the environment variable <name> equal to <value> in the |
| 191 | global environment (which will be inherited by all processes |
| 192 | started after this command is executed) |
| 193 | |
| 194 | hostname <name> |
| 195 | Set the host name. |
| 196 | |
| 197 | ifup <interface> |
| 198 | Bring the network interface <interface> online. |
| 199 | |
Lee Campbell | f13b1b3 | 2015-07-24 16:57:14 -0700 | [diff] [blame] | 200 | import <path> |
Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 201 | Parse an init config file, extending the current configuration. |
Lee Campbell | f13b1b3 | 2015-07-24 16:57:14 -0700 | [diff] [blame] | 202 | If <path> is a directory, each file in the directory is parsed as |
| 203 | a config file. It is not recursive, nested directories will |
| 204 | not be parsed. |
Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 205 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 206 | insmod <path> |
| 207 | Install the module at <path> |
| 208 | |
Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 209 | load_all_props |
| 210 | Loads properties from /system, /vendor, et cetera. |
| 211 | This is included in the default init.rc. |
| 212 | |
| 213 | load_persist_props |
| 214 | Loads persistent properties when /data has been decrypted. |
| 215 | This is included in the default init.rc. |
| 216 | |
Elliott Hughes | f682b47 | 2015-02-06 12:19:48 -0800 | [diff] [blame] | 217 | loglevel <level> |
| 218 | Sets the kernel log level to level. Properties are expanded within <level>. |
| 219 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 220 | mkdir <path> [mode] [owner] [group] |
| 221 | Create a directory at <path>, optionally with the given mode, owner, and |
| 222 | group. If not provided, the directory is created with permissions 755 and |
Johan Redestig | 0b42ba2 | 2015-03-15 17:39:41 +0100 | [diff] [blame] | 223 | owned by the root user and root group. If provided, the mode, owner and group |
| 224 | will be updated if the directory exists already. |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 225 | |
Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 226 | mount_all <fstab> |
| 227 | Calls fs_mgr_mount_all on the given fs_mgr-format fstab. |
| 228 | |
Niklas Tibbling | bc3f69f | 2012-08-01 13:15:38 +0200 | [diff] [blame] | 229 | mount <type> <device> <dir> [ <flag> ]* [<options>] |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 230 | Attempt to mount the named device at the directory <dir> |
| 231 | <device> may be of the form mtd@name to specify a mtd block |
| 232 | device by name. |
Niklas Tibbling | bc3f69f | 2012-08-01 13:15:38 +0200 | [diff] [blame] | 233 | <flag>s include "ro", "rw", "remount", "noatime", ... |
| 234 | <options> include "barrier=1", "noauto_da_alloc", "discard", ... as |
| 235 | a comma separated string, eg: barrier=1,noauto_da_alloc |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 236 | |
Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 237 | powerctl |
| 238 | Internal implementation detail used to respond to changes to the |
| 239 | "sys.powerctl" system property, used to implement rebooting. |
| 240 | |
| 241 | restart <service> |
| 242 | Like stop, but doesn't disable the service. |
| 243 | |
Stephen Smalley | 726e8f7 | 2013-10-09 16:02:09 -0400 | [diff] [blame] | 244 | restorecon <path> [ <path> ]* |
Stephen Smalley | 3fb6110 | 2012-11-02 15:22:34 -0400 | [diff] [blame] | 245 | Restore the file named by <path> to the security context specified |
| 246 | in the file_contexts configuration. |
| 247 | Not required for directories created by the init.rc as these are |
| 248 | automatically labeled correctly by init. |
| 249 | |
Stephen Smalley | 726e8f7 | 2013-10-09 16:02:09 -0400 | [diff] [blame] | 250 | restorecon_recursive <path> [ <path> ]* |
| 251 | Recursively restore the directory tree named by <path> to the |
| 252 | security contexts specified in the file_contexts configuration. |
Stephen Smalley | 726e8f7 | 2013-10-09 16:02:09 -0400 | [diff] [blame] | 253 | |
Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 254 | rm <path> |
| 255 | Calls unlink(2) on the given path. You might want to |
| 256 | use "exec -- rm ..." instead (provided the system partition is |
| 257 | already mounted). |
| 258 | |
| 259 | rmdir <path> |
| 260 | Calls rmdir(2) on the given path. |
| 261 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 262 | setprop <name> <value> |
Elliott Hughes | f682b47 | 2015-02-06 12:19:48 -0800 | [diff] [blame] | 263 | Set system property <name> to <value>. Properties are expanded |
| 264 | within <value>. |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 265 | |
| 266 | setrlimit <resource> <cur> <max> |
| 267 | Set the rlimit for a resource. |
| 268 | |
| 269 | start <service> |
| 270 | Start a service running if it is not already running. |
| 271 | |
| 272 | stop <service> |
| 273 | Stop a service from running if it is currently running. |
| 274 | |
Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 275 | swapon_all <fstab> |
| 276 | Calls fs_mgr_swapon_all on the given fstab file. |
| 277 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 278 | symlink <target> <path> |
| 279 | Create a symbolic link at <path> with the value <target> |
| 280 | |
The Android Open Source Project | 35237d1 | 2008-12-17 18:08:08 -0800 | [diff] [blame] | 281 | sysclktz <mins_west_of_gmt> |
| 282 | Set the system clock base (0 if system clock ticks in GMT) |
| 283 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 284 | trigger <event> |
| 285 | Trigger an event. Used to queue an action from another |
| 286 | action. |
| 287 | |
Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 288 | verity_load_state |
| 289 | Internal implementation detail used to load dm-verity state. |
| 290 | |
| 291 | verity_update_state <mount_point> |
| 292 | Internal implementation detail used to update dm-verity state and |
| 293 | set the partition.<mount_point>.verified properties used by adb remount |
| 294 | because fs_mgr can't set them directly itself. |
| 295 | |
Patrick McCormick | 96d0a4d | 2011-02-04 10:51:39 -0800 | [diff] [blame] | 296 | wait <path> [ <timeout> ] |
Elliott Hughes | 91a3be5 | 2015-03-20 11:00:15 -0700 | [diff] [blame] | 297 | Poll for the existence of the given file and return when found, |
| 298 | or the timeout has been reached. If timeout is not specified it |
| 299 | currently defaults to five seconds. |
Patrick McCormick | 96d0a4d | 2011-02-04 10:51:39 -0800 | [diff] [blame] | 300 | |
Elliott Hughes | f682b47 | 2015-02-06 12:19:48 -0800 | [diff] [blame] | 301 | write <path> <content> |
| 302 | Open the file at <path> and write a string to it with write(2). |
| 303 | If the file does not exist, it will be created. If it does exist, |
| 304 | it will be truncated. Properties are expanded within <content>. |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 305 | |
| 306 | |
| 307 | Properties |
| 308 | ---------- |
| 309 | Init updates some system properties to provide some insight into |
| 310 | what it's doing: |
| 311 | |
Elliott Hughes | 8d82ea0 | 2015-02-06 20:15:18 -0800 | [diff] [blame] | 312 | init.action |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 313 | Equal to the name of the action currently being executed or "" if none |
| 314 | |
| 315 | init.command |
| 316 | Equal to the command being executed or "" if none. |
| 317 | |
| 318 | init.svc.<name> |
| 319 | State of a named service ("stopped", "running", "restarting") |
| 320 | |
| 321 | |
Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 322 | Bootcharting |
| 323 | ------------ |
Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 324 | This version of init contains code to perform "bootcharting": generating log |
| 325 | files that can be later processed by the tools provided by www.bootchart.org. |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 326 | |
Elliott Hughes | 59abac2 | 2015-03-28 12:12:51 -0700 | [diff] [blame] | 327 | On the emulator, use the -bootchart <timeout> option to boot with bootcharting |
| 328 | activated for <timeout> seconds. |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 329 | |
Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 330 | On a device, create /data/bootchart/start with a command like the following: |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 331 | |
Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 332 | adb shell 'echo $TIMEOUT > /data/bootchart/start' |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 333 | |
Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 334 | Where the value of $TIMEOUT corresponds to the desired bootcharted period in |
| 335 | seconds. Bootcharting will stop after that many seconds have elapsed. |
| 336 | You can also stop the bootcharting at any moment by doing the following: |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 337 | |
Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 338 | adb shell 'echo 1 > /data/bootchart/stop' |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 339 | |
Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 340 | Note that /data/bootchart/stop is deleted automatically by init at the end of |
| 341 | the bootcharting. This is not the case with /data/bootchart/start, so don't |
| 342 | forget to delete it when you're done collecting data. |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 343 | |
Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 344 | The log files are written to /data/bootchart/. A script is provided to |
| 345 | retrieve them and create a bootchart.tgz file that can be used with the |
| 346 | bootchart command-line utility: |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 347 | |
Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 348 | sudo apt-get install pybootchartgui |
Elliott Hughes | 59abac2 | 2015-03-28 12:12:51 -0700 | [diff] [blame] | 349 | # grab-bootchart.sh uses $ANDROID_SERIAL. |
Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 350 | $ANDROID_BUILD_TOP/system/core/init/grab-bootchart.sh |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 351 | |
Elliott Hughes | 59abac2 | 2015-03-28 12:12:51 -0700 | [diff] [blame] | 352 | One thing to watch for is that the bootchart will show init as if it started |
| 353 | running at 0s. You'll have to look at dmesg to work out when the kernel |
| 354 | actually started init. |
| 355 | |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 356 | |
Ben Cheng | 50bbde0 | 2015-06-09 17:04:36 +0800 | [diff] [blame] | 357 | Comparing two bootcharts |
| 358 | ------------------------ |
| 359 | A handy script named compare-bootcharts.py can be used to compare the |
| 360 | start/end time of selected processes. The aforementioned grab-bootchart.sh |
| 361 | will leave a bootchart tarball named bootchart.tgz at /tmp/android-bootchart. |
| 362 | If two such barballs are preserved on the host machine under different |
| 363 | directories, the script can list the timestamps differences. For example: |
| 364 | |
| 365 | Usage: system/core/init/compare-bootcharts.py base_bootchart_dir |
| 366 | exp_bootchart_dir |
| 367 | |
| 368 | process: baseline experiment (delta) |
| 369 | - Unit is ms (a jiffy is 10 ms on the system) |
| 370 | ------------------------------------ |
| 371 | /init: 50 40 (-10) |
| 372 | /system/bin/surfaceflinger: 4320 4470 (+150) |
| 373 | /system/bin/bootanimation: 6980 6990 (+10) |
| 374 | zygote64: 10410 10640 (+230) |
| 375 | zygote: 10410 10640 (+230) |
| 376 | system_server: 15350 15150 (-200) |
| 377 | bootanimation ends at: 33790 31230 (-2560) |
| 378 | |
| 379 | |
Yasuhiro Matsuda | f93db4b | 2015-06-15 18:49:35 +0900 | [diff] [blame] | 380 | Systrace |
| 381 | -------- |
| 382 | Systrace [1] can be used for obtaining performance analysis reports during boot |
| 383 | time on userdebug or eng builds. |
| 384 | Here is an example of trace events of "wm" and "am" categories: |
| 385 | |
| 386 | $ANDROID_BUILD_TOP/external/chromium-trace/systrace.py wm am --boot |
| 387 | |
| 388 | This command will cause the device to reboot. After the device is rebooted and |
| 389 | the boot sequence has finished, the trace report is obtained from the device |
| 390 | and written as trace.html on the host by hitting Ctrl+C. |
| 391 | |
| 392 | LIMITATION |
| 393 | Recording trace events is started after persistent properties are loaded, so |
| 394 | the trace events that are emitted before that are not recorded. Several |
| 395 | services such as vold, surfaceflinger, and servicemanager are affected by this |
| 396 | limitation since they are started before persistent properties are loaded. |
| 397 | Zygote initialization and the processes that are forked from the zygote are not |
| 398 | affected. |
| 399 | |
| 400 | [1] http://developer.android.com/tools/help/systrace.html |
| 401 | |
| 402 | |
Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 403 | Debugging init |
| 404 | -------------- |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 405 | By default, programs executed by init will drop stdout and stderr into |
| 406 | /dev/null. To help with debugging, you can execute your program via the |
Elliott Hughes | f682b47 | 2015-02-06 12:19:48 -0800 | [diff] [blame] | 407 | Android program logwrapper. This will redirect stdout/stderr into the |
The Android Open Source Project | 4f6e8d7 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 408 | Android logging system (accessed via logcat). |
| 409 | |
| 410 | For example |
| 411 | service akmd /system/bin/logwrapper /sbin/akmd |
Elliott Hughes | f682b47 | 2015-02-06 12:19:48 -0800 | [diff] [blame] | 412 | |
| 413 | For quicker turnaround when working on init itself, use: |
| 414 | |
Elliott Hughes | 841b263 | 2015-02-12 14:28:54 -0800 | [diff] [blame] | 415 | mm -j |
Elliott Hughes | f682b47 | 2015-02-06 12:19:48 -0800 | [diff] [blame] | 416 | m ramdisk-nodeps |
| 417 | m bootimage-nodeps |
| 418 | adb reboot bootloader |
| 419 | fastboot boot $ANDROID_PRODUCT_OUT/boot.img |
| 420 | |
| 421 | Alternatively, use the emulator: |
| 422 | |
| 423 | emulator -partition-size 1024 -verbose -show-kernel -no-window |
| 424 | |
| 425 | You might want to call klog_set_level(6) after the klog_init() call |
| 426 | so you see the kernel logging in dmesg (or the emulator output). |