From f93db4b827818806ca4cee80e6ec954d7aa40632 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsuda Date: Mon, 15 Jun 2015 18:49:35 +0900 Subject: [PATCH] Introduce a mechanism to trace boot sequence. This CL adds a trigger and a service so that Systrace can be used for tracing events during boot. persist.debug.atrace.boottrace property is used for switching on and off tracing during boot. /data/misc/boottrace/categories file is used for specifying the categories to be traced. These property and file are rewritten by Systrace when the newly added option --boot is specified. Here is an example of tracing events of am and wm catetories during boot. $ external/chromium-trace/systrace am wm --boot This command will cause the device to reboot. Once the device has booted up, the trace report is created by hitting Ctrl+C. As written in readme.txt, this mechanism relies on persistent property, so tracing events that are emitted before that are not recorded. This is enough for tracing events after zygote is launched though. This only works on userdebug or eng build for security reason. BUG: 21739901 Change-Id: I03f2963d77a678f47eab5e3e29fc7e91bc9ca3a4 --- init/readme.txt | 23 +++++++++++++++++++++++ rootdir/init.rc | 1 + rootdir/init.trace.rc | 8 ++++++++ 3 files changed, 32 insertions(+) diff --git a/init/readme.txt b/init/readme.txt index 5a758d7fa..d70c6f3e2 100644 --- a/init/readme.txt +++ b/init/readme.txt @@ -377,6 +377,29 @@ system_server: 15350 15150 (-200) bootanimation ends at: 33790 31230 (-2560) +Systrace +-------- +Systrace [1] can be used for obtaining performance analysis reports during boot +time on userdebug or eng builds. +Here is an example of trace events of "wm" and "am" categories: + + $ANDROID_BUILD_TOP/external/chromium-trace/systrace.py wm am --boot + +This command will cause the device to reboot. After the device is rebooted and +the boot sequence has finished, the trace report is obtained from the device +and written as trace.html on the host by hitting Ctrl+C. + +LIMITATION +Recording trace events is started after persistent properties are loaded, so +the trace events that are emitted before that are not recorded. Several +services such as vold, surfaceflinger, and servicemanager are affected by this +limitation since they are started before persistent properties are loaded. +Zygote initialization and the processes that are forked from the zygote are not +affected. + +[1] http://developer.android.com/tools/help/systrace.html + + Debugging init -------------- By default, programs executed by init will drop stdout and stderr into diff --git a/rootdir/init.rc b/rootdir/init.rc index f5febdea7..12999bd8a 100644 --- a/rootdir/init.rc +++ b/rootdir/init.rc @@ -259,6 +259,7 @@ on post-fs-data chmod 0660 /data/misc/wifi/wpa_supplicant.conf mkdir /data/local 0751 root root mkdir /data/misc/media 0700 media media + mkdir /data/misc/boottrace 0771 system shell # For security reasons, /data/local/tmp should always be empty. # Do not place files or directories in /data/local/tmp diff --git a/rootdir/init.trace.rc b/rootdir/init.trace.rc index 50944e6c4..ed4629e8d 100644 --- a/rootdir/init.trace.rc +++ b/rootdir/init.trace.rc @@ -33,3 +33,11 @@ on boot # Allow only the shell group to read and truncate the kernel trace. chown root shell /sys/kernel/debug/tracing/trace chmod 0660 /sys/kernel/debug/tracing/trace + +on property:persist.debug.atrace.boottrace=1 + start boottrace + +# Run atrace with the categories written in a file +service boottrace /system/bin/atrace --async_start -f /data/misc/boottrace/categories + disabled + oneshot