[Android systrace series] capture the startup process of systrace

Time:2021-6-27

————————————————————————-

The small goal of this article is to understand the steps of grabbing systrace in the boot process

————————————————————————-

 

Mobile phone boot process, involving a lot of code, if you can use systrace to analyze, get twice the result with half the effort.

First, decompose the time-consuming of each startup stage to facilitate subsequent comparison.

Just filter the boot in the events log_ Progress keyword, you can get the boot time of each stage.

device:/ $ logcat -b events | grep boot_progress
07-17 08:33:00.241 400 400 I boot_progress_start: 4826
11-29 09:53:34.968 400 400 I boot_progress_preload_start: 7577
11-29 09:53:36.154 400 400 I boot_progress_preload_end: 8763
11-29 09:53:36.519 2072 2072 I boot_progress_system_run: 9127
11-29 09:53:37.088 2072 2072 I boot_progress_pms_start: 9697
11-29 09:53:37.238 2072 2072 I boot_progress_pms_system_scan_start: 9847
11-29 09:53:37.402 2072 2072 I boot_progress_pms_data_scan_start: 10011
11-29 09:53:37.430 2072 2072 I boot_progress_pms_scan_end: 10039
11-29 09:53:37.925 2072 2072 I boot_progress_pms_ready: 10533
11-29 09:53:39.394 2072 2072 I boot_progress_ams_ready: 12003
11-29 09:53:41.324 2072 2637 I boot_progress_enable_screen: 13933

 

Before grabbing systrace, you might as well refer to[Android systrace series] where does systrace information come fromTo get familiar with the mask of the systrace log category and the path of the ftrace event.

 

Here are the steps to capture the boot systrace, where you need to compile theuserdebugedition

1. Search all RC files globally, andAllClose the command comment of trace, such as write / sys / kernel / debug / tracing / instances / WiFi / tracing_ on 0

After modifying the RC file, compile the mobile phone ROM.

skill:You can only search RC files in the out folder, narrow the search scope, and then modify and edit the ROM.

 

2. Modify build.prop and push to mobile phone

two point one   First, extract the build. Prop from the mobile phone

adb pull /system/build.prop

2.2 add the attribute debug.atrace.tags.enableflags, and the value is the mask to enable the required systrace category.

Mask can refer to the source code / / Android / system / core / libcutils / include / cutils / trace. H, atrace_ Macro definition starting with tag.

Debug.atrace.tags.enableflags can be hexadecimal starting with 0, octal starting with 0, or decimal not starting with 0.

debug.atrace.tags.enableflags=0xC402A

2.3 push buid.prop back to mobile phone

adb root
adb remount
adb push build.prop /system/

Tips:You can also add the attribute debug.atrace.tags.enableflags in device.mk, and then compile the mobile phone ROM

 

3. Modify atrace.rc and push it to the mobile phone

3.1 first extract atrace.rc from mobile phone

adb pull /system/etc/init/atrace.rc

On the next line where the buffer permissions are changed, expand the buffer size to accommodate logs that are long enough

chmod 0666 /sys/kernel/debug/tracing/buffer_size_kb
write /sys/kernel/debug/tracing/buffer_size_kb 51200

3.2 select the kernel ftrace event to capture.

You can turn off all the switches first, which is the mobile directory  / All traces under sys / kernel / debug / tracing / events / are listed in the following four lines as examples

write /sys/kernel/debug/tracing/events/power/enable 0
write /sys/kernel/debug/tracing/events/sched/enable 0
write /sys/kernel/debug/tracing/events/vmscan/enable 0
write /sys/kernel/debug/tracing/events/block/enable 0

Then turn on the required switch, you can refer to the array K of atrace.cpp_ categories

write /sys/kernel/debug/tracing/events/power/cpu_frequency/enable 1
write /sys/kernel/debug/tracing/events/power/idle/enable 1
write /sys/kernel/debug/tracing/events/sched/sched_switch/enable 1
write /sys/kernel/debug/tracing/events/sched/sched_wakeup/enable 1
write /sys/kernel/debug/tracing/events/block/block_rq_issue/enable 1
write /sys/kernel/debug/tracing/events/block/block_rq_complete/enable 1

3.3 as mentioned in point 1, in atrace.rc, the command to turn off trace should be annotated, because trace is turned off by default during startup.

#write /sys/kernel/debug/tracing/tracing_on 0
#write /sys/kernel/tracing/tracing_on 0

3.4 in order to avoid continuously outputting trace to flush the boot log after the boot is completed, stop trace after the boot is completed, and enter theAt the backAdd the following two lines:

Be careful not to add on the two lines mentioned in 3.3, because on property will be considered as the beginning of another action block

on property:sys.boot_completed=1
    write /sys/kernel/debug/tracing/tracing_on 0

3.5 push atrace.rc to / system / etc / init / atrace.rc

adb root
adb remount
adb push atrace.rc /system/etc/init/atrace.rc

 

4. Restart the machine and execute ADB shell “cat / sys / kernel / debug / tracing / trace” > trace.out

At this point, you can try to chrome://tracing Click load to load trace. Out.

Tips:If the file is too large or the individual log is incomplete, the loading will fail.

If there is an error loading, continue with the following steps.

5. (optional step) if the trace.out file is too large, you can cut out the startup phase to be analyzed in plain text, save it as part.out separately, and then try to load it.

6. If the trace file fails to load due to incomplete log (whether it has been cut or not), it can be converted by trace2html.py instead of systrace.py, because the latter will also have errors

First, Download catapult, https://github.com/catapult-project/catapult

Trace2html.py path://catapult/tracing/bin/ trace2html.py

The conversion command is trace2html. Py trace. Out

 

 

Please indicate the source of Reprint: https://www.cnblogs.com/zzcperf/p/14054555.html