1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
|
system/core/bootstat/bootstat.rc
# Record boot complete metrics.
on property:sys.boot_completed=1 && property:sys.logbootcomplete=1
# Record boot_complete and related stats (decryption, etc).
exec - root root -- /system/bin/bootstat --record_boot_complete
# Record the boot reason.
exec - root root -- /system/bin/bootstat --record_boot_reason
# Record time since factory reset.
exec - root root -- /system/bin/bootstat --record_time_since_factory_reset
# Log all boot events.
exec - root root -- /system/bin/bootstat -l
system/core/bootstat/README.md
# bootstat #
The bootstat command records boot events (e.g., `firmware_loaded`,
`boot_complete`) and the relative time at which these events occurred. The
command also aggregates boot event metrics locally and logs the metrics for
analysis.
Usage: bootstat [options]
options include:
-h, --help Show this help
-l, --log Log all metrics to logstorage
-p, --print Dump the boot event records to the console
-r, --record Record the timestamp of a named boot event
--record_boot_reason Record the reason why the device booted
--record_time_since_factory_reset Record the time since the device was reset
## Relative time ##
The timestamp recorded by bootstat is the uptime of the system, i.e., the
number of seconds since the system booted.
## Recording boot events ##
To record the relative time of an event during the boot phase, call `bootstat`
with the `-r` option and the name of the boot event.
$ bootstat -r boot_complete
The relative time at which the command runs is recorded along with the name of
the boot event to be persisted.
## Logging boot events ##
To log the persisted boot events, call `bootstat` with the `-l` option.
$ bootstat -l
bootstat logs all boot events recorded using the `-r` option to the EventLog
using the Tron histogram. These logs may be uploaded by interested parties
for aggregation and analysis of boot time across different devices and
versions.
## Printing boot events ##
To print the set of persisted boot events, call `bootstat` with the `-p` option.
$ bootstat -p
Boot events:
------------
boot_complete 71
10:34:07 liuyq: master-backup$ tree system/core/bootstat/
system/core/bootstat/
├── Android.bp
├── AndroidTest.xml
├── boot_event_record_store.cpp
├── boot_event_record_store.h
├── boot_event_record_store_test.cpp
├── bootstat.cpp
├── bootstat.rc
├── README.md
└── testrunner.cpp
0 directories, 9 files
10:34:13 liuyq: master-backup$
const char BOOTSTAT_DATA_DIR[] = "/data/misc/bootstat/";
========================================
Boot timing
-----------
Init records some boot timing information in system properties.
`ro.boottime.init`
> Time after boot in ns (via the CLOCK\_BOOTTIME clock) at which the first
stage of init started.
`ro.boottime.init.selinux`
> How long it took the first stage to initialize SELinux.
`ro.boottime.init.cold_boot_wait`
> How long init waited for ueventd's coldboot phase to end.
`ro.boottime.<service-name>`
> Time after boot in ns (via the CLOCK\_BOOTTIME clock) that the service was
first started.
ro.boot.boottime: for BootloaderTimingMap, not reported on all devices
// |ro.boot.boottime| is of the form 'stage1:time1,...,stageN:timeN', where timeN is in milliseconds.
RecordBootComplete
time_since_last_boot: only set when last_boot_time_utc has already set when the bootstat command with record_boot_complete option executed, unit is second
last_boot_time_utc: the time when the bootstat command with record_boot_complete option executed. normally the timing that property sys.boot_completed set to 1, unit is second
build_date: value from property ro.build.date.utc, seconds since 1970-01-01 00:00:00 UTC at the build time, unit is second
factory_reset_boot_complete_no_encryption: uptime gotten with CLOCK_BOOTTIME, set when the bootstat command with record_boot_complete option executed. normally the timing that property sys.boot_completed set to 1, which means the uptime when the boot complete. unit is second
factory_reset_boot_complete: same as factory_reset_boot_complete_no_encryption
ro.boottime.init: value get from property of ro.boottime.init, Time after boot in ns (via the CLOCK\_BOOTTIME clock) at which the first stage of init started.
ro.boottime.init.selinux: value get from property of ro.boottime.init.selinux, How long it took the first stage to initialize SELinux.
ro.boottime.init.cold_boot_wait: value get from property of ro.boottime.init.cold_boot_wait, How long init waited for ueventd's coldboot phase to end, unit is ms
boottime.bootloader.*: get from property of ro.boot.boottime where the unit is ms. this is not reported by all devices.
boottime.bootloader.total: the total time taken for bootloader. this is not reported by all devices. unit is ms
absolute_boot_time: total time that includes bootloader duration and the android boot time till property sys.boot_completed set to 1
RecordBootReason:
boot_reason: get from property ro.boot.bootreason, and contvert it to integer representation. 1 for unknown reason
RecordFactoryReset: Records two metrics related to the user resetting a device: the time at which the device is reset, and the time since the user last reset the device. The former is only set once per-factory reset.
factory_reset_current_time: the time when the bootstat command with record_time_since_factory_reset option executed. normally the timing that property sys.boot_completed set to 1, unit is second
factory_reset: The factory_reset boot event does not exist after the device is reset, so use this signal to mark the time of the factory reset.
factory_reset_record_value: only set when factory_reset has been set already. The value should be the same as factory_reset.
time_since_factory_reset: only set when factory_reset has been set already. it's the diff between current_time_utc and factory_reset_utc.
================================
hikey:/ # date
Mon Jul 10 07:16:36 GMT 2017
hikey:/ # bootstat -p
Boot events:
------------
last_boot_time_utc 1499670715
build_date 1499338003
factory_reset_boot_complete_no_encryption 59
factory_reset_boot_complete 59
ro.boottime.init 5766
ro.boottime.init.selinux 148
ro.boottime.init.cold_boot_wait 399
boottime.bootloader.total 0
absolute_boot_time 59
boot_reason 1
factory_reset_current_time 1499670715
factory_reset 1499670715
hikey:/ #
--------------------------------------
hikey:/ # date
Mon Jul 10 07:19:39 GMT 2017
hikey:/ # bootstat -p
Boot events:
------------
last_boot_time_utc 1499671056
build_date 1499338003
factory_reset_boot_complete_no_encryption 59
factory_reset_boot_complete 59
ro.boottime.init 5758
ro.boottime.init.selinux 160
ro.boottime.init.cold_boot_wait 429
boottime.bootloader.total 0
absolute_boot_time 26
boot_reason 1
factory_reset_current_time 1499671056
factory_reset 1499670715
time_since_last_boot 341
boot_complete_no_encryption 26
boot_complete 26
factory_reset_record_value 1499670715
time_since_factory_reset 341
hikey:/ #
================================================
auto time_since_epoch = android::base::boot_clock::now().time_since_epoch();
auto uptime = std::chrono::duration_cast<std::chrono::seconds>(time_since_epoch);
uptime.count()
time_t current_time_utc = time(nullptr);
-------------------------------------
#type=1400 audit(1499683876.156:131): avc: denied { write } for pid=2435 comm="bootstat" name="logd" dev="tmpfs" ino=10352 scontext=u:r:bootstat:s0 tcontext=u:object_r:logd_socket:s0 tclass=sock_file permissive=1
#type=1400 audit(31.215:138): avc: denied { connectto } for pid=2378 comm="bootstat" path="/dev/socket/logd" scontext=u:r:bootstat:s0 tcontext=u:r:logd:s0 tclass=unix_stream_socket permissive=1
---------------------------------------
|