Android 6.0起動時間分析ツールbootchartの使用

5008 ワード

前言
最近、電源を入れて最適化する任務に割り当てられて、何気なくbootchartというツールを見て、使った後にとても良い感じがして、特にこの記録を共有します.
ソース分析
システムソースシステム/core/init/ディレクトリに入ると、次のようなソースファイルが表示されます.
bootchart.cpp bootchart.h grab-bootchart.sh readme.txt
以下、これらのファイルを分析します.sh
#!/bin/sh # # This script is used to retrieve a bootchart log generated by init. # All options are passed to adb, for better or for worse. # See the readme in this directory for more on bootcharting. TMPDIR=/tmp/android-bootchart rm -rf $TMPDIR mkdir -p $TMPDIR LOGROOT=/data/bootchart TARBALL=bootchart.tgz FILES="header PRoc_stat.log proc_ps.log proc_diskstats.log kernel_pacct"for f in $FILES; do adb "${@}"pull $LOGROOT/$f $TMPDIR/$f 2>&1 >/dev/null done (cd $TMPDIR && tar -czf $TARBALL $FILES) bootchart ${TMPDIR}/${TARBALL} gnome-open ${TARBALL%.tgz}.png echo "Clean up ${TMPDIR}/and ./${TARBALL%.tgz}.png when done"
このスクリプトは主に/data/bootchartディレクトリの下で生成されたファイルを圧縮パッケージbootchartにパッケージする.tgz.bootchartを実行してbootchartを通過する.tgz圧縮パケットは、対応するpngピクチャを生成する.このスクリプトは主にlinuxシステム向けで、Windowsシステムを使っているので、ここで直接手動で対応するコマンドを入力すればいいです.主に役立つ2つのコマンド:tar -czf bootchart.tgz header proc_stat.log proc_ps.log proc_diskstats.log kernel_pacct bootchart bootchart.tgzreadme.txt
Bootcharting ------------ This version of init contains code to perform "bootcharting": generating log files that can be later processed by the tools provided by www.bootchart.org. On the emulator, use the -bootchart option to boot with bootcharting activated for seconds. On a device, create/data/bootchart/start with a command like the following: adb shell 'echo $TIMEOUT >/data/bootchart/start' Where the value of $TIMEOUT corresponds to the desired bootcharted period in seconds. Bootcharting will stop after that many seconds have elapsed. You can also stop the bootcharting at any moment by doing the following: adb shell 'echo 1 >/data/bootchart/stop' Note that/data/bootchart/stop is deleted automatically by init at the end of the bootcharting. This is not the case with/data/bootchart/start, so don't forget to delete it when you're done collecting data. The log files are written to/data/bootchart/. A script is provided to retrieve them and create a bootchart.tgz file that can be used with the bootchart command-line utility: sudo apt-get install pybootchartgui # grab-bootchart.sh uses $ANDROID_SERIAL. $ANDROID_BUILD_TOP/system/core/init/grab-bootchart.sh One thing to watch for is that the bootchart will show init as if it started running at 0s. You'll have to look at dmesg to work out when the kernel actually started init.
readmeでは主にbootchartの情報収集とbootchartのインストール方法を紹介しています.readmeにはpybootchartguiがインストールされていますが、私が実際にインストールしたのはbootchartなので、ここでは主にbootchartを使用しています.主に役立つ2つのコマンド:adb shell echo 120 > /data/bootchart/start sudo apt-get install bootchartbootchart.cppとbootchart.hは完全なコードを貼らないで、どのように実行を開始する部分のコードを貼ります.
#define LOG_ROOT "/data/bootchart"#define LOG_STARTFILE LOG_ROOT"/start"static int bootchart_init(){int timeout=0;std::string start;//ここでは/data/bootchart/startファイルの情報android::base::ReadFileToString(LOG_STARTFILE,&start);if(!start.empty(){timeout=atoi(start.c_str();}else {//When running with emulator, androidboot.bootchart=//might be passed by as kernel parameters to specify the bootchart//timeout. this is useful when using -wipe-data since the/data//partition is fresh. std::string cmdline; android::base::ReadFileToString("/proc/cmdline", &cmdline); #define KERNEL_OPTION "androidboot.bootchart="if (strstr(cmdline.c_str(), KERNEL_OPTION) != NULL) { timeout = atoi(cmdline.c_str() + sizeof(KERNEL_OPTION) - 1); } } if (timeout == 0) return 0; .... }
bootchartを通ります.cppソースコードは、bootchartが/data/bootchart/startの情報を読み取ることを知っています.これは、`echo 120>/data/bootchart/startを使用していたからです.従って、読み出し処理の時間は120秒である.そして、次の情報収集操作を実行します.
実戦で戦争を始める.
まず、私の開発環境を紹介します.
Windows 7 Linuxサーバ
OK、やめて.1.起動情報を収集し、Windows環境でadbコマンドを使用します.
adb shell//shell環境echo 120>/data/bootchart/start//startファイルに120 reboot//adb shell//再起動後再びshell環境cd/data/bootchart/ls//このディレクトリには多くのファイルが書き込まれています.それらのファイルは私たちが必要とする起動情報ファイルです.
2.圧縮起動情報のパッケージ化
//shell環境では、/data/bootchart/ディレクトリでtarパッケージ圧縮tar-czf bootchartを実行する.tgz proc_stat.log proc_ps.log proc_diskstats.log kernel_pacct//shell環境exit//パッケージを引き出し、私たちのサーバにadb pull/data/bootchart/bootchartをコピーします.tgz D:\
3.pngピクチャの生成
pngピクチャを生成するにはbootchartツールが必要ですが、このツールの使用にはlinux環境が必要です.bootchartをインストールしていない場合は、インストールする必要があります.インストールコマンドは次のとおりです.
sudo apt-get install bootchart
インストールが完了したらbootchartコマンドを使用できます.Linuxサーバで実行
bootchart bootchart.tgz
コマンドが終了すると、対応するpngピクチャが生成されます.
OK、大成功.
まとめ
ここで最も重要な3つのステップをまとめます
echo 120 >/data/bootchart/start tar -czf bootchart.tgz header proc_stat.log proc_ps.log proc_diskstats.log kernel_pacct bootchart bootchart.tgz
この3つのステップで基本的に起動情報の画像を得ることができます.