android性能测试bootchart篇

一:简介


bootchart是一个用于linux启动过程性能分析的开源软件工具。
在系统启动过程自动收集CPU占用率、进程等信息。
并以图形方式显示分析结果,可用作指导优化系统启动过程

二: Android 支持 bootchart 


Android系统编译时,默认的没有打开bootchart的编译开关,
即没有把bootchart编译进系统中。
Android对bootchart 的支持在init 中


三:编译


编译带有bootchart的bootimage
source build/envsetup.sh
touch system/core/init/init.c
export INIT_BOOTCHART=true
make


四:准备

设备准备:
NFS:将编译好的init替换到rootfs下
Emmc:重新烧写boot.img

服务器准备:

sudo apt-get install bootchart
sudo apt-get install pybootchartgui

脚本准备:
通过脚本从设备获取数据生成图片(脚本下载:http://download.csdn.net/detail/a624731186/8186283)
#!/bin/sh
TMPDIR=`date +%s`
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)
cd $TMPDIR
bootchart $TARBALL
echo "look at ${TMPDIR}/bootchart.png "

五:测试

启动设备, 设备终端下执行
echo 40 > /data/bootchart-start
sync
此处的 40 代表 bootchart 收集 40 秒的数据
重启设备

六:生成启动图片

重启后连接 adb(网络/USB) ,
等待 40 秒后,服务器任意目录执行脚本 ./bootchart_pic.sh

android性能测试bootchart篇_第1张图片

图片如下:设备启动已优化,目前 设备12秒左右开机
android性能测试bootchart篇_第2张图片

附:

1: 执行脚本时,如提示如下错误:

parsing 'header'
parsing 'proc_stat.log'
parsing 'proc_ps.log'
warning: no parent for pid '2' with ppid '0'
parsing 'proc_diskstats.log'
parsing 'kernel_pacct'
merged 0 logger processes
pruned 63 process, 0 exploders, 2 threads, and 0 runs
False
Traceback (most recent call last):
File "/usr/bin/bootchart", line 23, in
sys.exit(main())
File "/usr/lib/pymodules/python2.6/pybootchartgui/main.py", line
137, in main
render()
File "/usr/lib/pymodules/python2.6/pybootchartgui/main.py", line
128, in render
batch.render(writer, res, options, filename)
File "/usr/lib/pymodules/python2.6/pybootchartgui/batch.py", line
41, in render
draw.render(ctx, options, *res)
File "/usr/lib/pymodules/python2.6/pybootchartgui/draw.py", line
282, in render
draw_chart(ctx, IO_COLOR, True, chart_rect, [(sample.time,
sample.util) for sample in disk_stats], proc_tree)
File "/usr/lib/pymodules/python2.6/pybootchartgui/draw.py", line
201, in draw_chart
yscale = float(chart_bounds[3]) / max(y for (x,y) in data)
ZeroDivisionError: float division

服务器修改如下:
/usr/share/pyshared/pybootchartgui/目录的draw.py, parsing.py, samples.py三个文件。
分别修改如下://(文件下载:http://download.csdn.net/detail/a624731186/8186283)
draw.py
将200, 201行由:
xscale = float(chart_bounds[2]) / max(x for (x,y) in data)
yscale = float(chart_bounds[3]) / max(y for (x,y) in data)
改为:
xscale = float(chart_bounds[2]) / max(0.00001, max(x for (x,y) in data))
yscale = float(chart_bounds[3]) / max(0.00001, max(y for (x,y) in data))
parsing.py
在156行后添加:
if interval == 0:
interval = 1
修改后如下:
sums = [ a - b for a, b in zip(sample1.diskdata, sample2.diskdata) ]
if interval == 0:
interval = 1
samples.py
在81行后添加:
if interval == 0:
interval = 1
修改后如下:
def calc_load(self, userCpu, sysCpu, interval):
if interval == 0:

interval = 1

2: 执行脚本时,如提示如下错误:
Traceback (most recent call last):
File "/usr/bin/bootchart", line 23, in
sys.exit(main())
File "/usr/lib/pymodules/python2.6/pybootchartgui/main.py", line 137, in main
render()
File "/usr/lib/pymodules/python2.6/pybootchartgui/main.py", line 128, in render
batch.render(writer, res, options, filename)
File "/usr/lib/pymodules/python2.6/pybootchartgui/batch.py", line 41, in render
draw.render(ctx, options, *res)
File "/usr/lib/pymodules/python2.6/pybootchartgui/draw.py", line 299, in render
draw_process_bar_chart(ctx, proc_tree, times, curr_y + bar_h, w, h)
File "/usr/lib/pymodules/python2.6/pybootchartgui/draw.py", line 319, in draw_process_bar_chart
draw_processes_recursively(ctx, root, proc_tree, y, proc_h, chart_rect)
File "/usr/lib/pymodules/python2.6/pybootchartgui/draw.py", line 357, in
draw_processes_recursively
child_x, child_y = draw_processes_recursively(ctx, child, proc_tree, next_y, proc_h, rect)
File "/usr/lib/pymodules/python2.6/pybootchartgui/draw.py", line 349, in
draw_processes_recursively
draw_process_activity_colors(ctx, proc, proc_tree, x, y, w, proc_h, rect)
File "/usr/lib/pymodules/python2.6/pybootchartgui/draw.py", line 376, in
draw_process_activity_colors
state = get_proc_state( sample.state )
File "/usr/lib/pymodules/python2.6/pybootchartgui/draw.py", line 105, in get_proc_state
return "RSDTZXW".index(flag) + 1
ValueError: substring not found

服务器修改如下:
/usr/share/pyshared/pybootchartgui/目录的 draw.py 文件。
修改如下:
将105行:
return "RSDTZXW".index(flag) + 1
改为:
return "RSDTZXW".find(flag) + 1






你可能感兴趣的:(android)