Android Bootchart使用

目录

  • 1,bootchart简介
  • 2,bootchart 在 android 平台的使用步骤(复杂方式, old)
  • 3,bootchart 在 android 平台的使用步骤(方便方式, new)
  • 4,修改bootchart抓取的停止时间
  • 5,可能遇到得问题
  • 6,bootchart 图形分析

1. bootchart 简介

bootchart 是一个用于 linux 启动过程性能分析的开源工具软件,在系统启动过程中自动收集 CPU 占用率、磁盘吞吐率、进程等信息,并以图形方式显示分析结果,可用作指导优化系统启动过程。bootchart 让用户可以很直观的查看系统启动的过程和各个过程耗费的时间,以便让用户能够分析启动过程,从而进行优化以提高启动时间。它由 bootchartd 服务和 bootchart-render 两部分组成,后者主要负责生成启动流程的分析结果图。
Android 系统源码中有 bootchart 的实现,路径在 system/core/init/bootchart.cpp 中, bootchart 通过内嵌在 init 进程中实现,在后台执行测量。不过 bootchart 的测量时段是 init 进程启动之后,不包含 uboot 和 kernel 的启动时间。

2,bootchart 在 android 平台的使用步骤(复杂方式, old)

2.1,使能调试设备的bootchart程序,进行设备必要的开机log: adb shell ‘touch /data/bootchart/enabled’
2.2,在reboot调试设备后,进入/data/bootchart目录,先行删除enabled, 再执行 tar -zcf bootchart.tgz *, 接着adb pull /data/bootchart/bootchart.tgz 到本地,拷贝到ubuntu;
2.3,ubuntu 机安装 bootchart 工具:
sudo apt-get install bootchart
sudo apt-get install pybootchartgui
2.4,生成bootchart图表:
bootchart bootchart.tgz

3,bootchart 在 android 平台的使用步骤(方便方式, new)

3.1,使能调试设备的bootchart程序,进行设备必要的开机log: adb shell ‘touch /data/bootchart/enabled’
3.2, 在adb reboot调试设备后,ubuntu电脑连接调试设备,终端android根目录执行命令:
android$ ./system/core/init/grab-bootchart.sh
bootchart的图标即生成在android根目录

4,修改bootchart抓取的停止时间

android高版本上不支持简单的设置方式调整bootchart的结束时间,只能在init.rc中修改,bootchart的启动和结束方式如下:

...
	# Start bootcharting as soon as possible after the data partition is
    # mounted to collect more data.
    mkdir /data/bootchart 0755 shell shell encryption=Require
    bootchart start
    ...
on property:sys.boot_completed=1
	bootchart stop

原生的逻辑中,在开机完成时,系统会设置sys.boot_completed属性=1,此时bootchart停止抓取信息;
我们可以更改stop的条件,自定义一个属性来实现停止,我自己实现可控停止方式如下,在开机后,手动去设置这个属性值=1:

on property:vendor.boot.complete=1
    bootchart stop

5,可能遇到得问题

在ubuntu里生成bootchart表时,可能会遇到如下问题

uluxy181@ubuntu16-010:~/workspace/phase5/android$ ./system/core/init/grab-bootchart.sh
18 KB/s (1194 bytes in 0.062s)
327 KB/s (42942 bytes in 0.127s)
589 KB/s (2440734 bytes in 4.045s)
366 KB/s (102575 bytes in 0.273s)
parsing '/tmp/android-bootchart/bootchart.tgz'
parsing 'header'
parsing 'proc_stat.log'
parsing 'proc_ps.log'
warning: no parent for pid '2' with ppid '0'
parsing 'proc_diskstats.log'
merged 0 logger processes
pruned 146 process, 0 exploders, 4 threads, and 0 runs
False
Traceback (most recent call last):
  File "/usr/bin/pybootchartgui", line 23, in <module>
    sys.exit(main())
  File "/usr/lib/python2.7/dist-packages/pybootchartgui/main.py", line 137, in main
    render()
  File "/usr/lib/python2.7/dist-packages/pybootchartgui/main.py", line 128, in render
    batch.render(writer, res, options, filename)
  File "/usr/lib/python2.7/dist-packages/pybootchartgui/batch.py", line 41, in render
    draw.render(ctx, options, *res)
  File "/usr/lib/python2.7/dist-packages/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/python2.7/dist-packages/pybootchartgui/draw.py", line 201, in draw_chart
    yscale = float(chart_bounds[3]) / max(y for (x,y) in data)
ZeroDivisionError: float division by zero
Clean up /tmp/android-bootchart/ and ./bootchart.png when done
uluxy181@ubuntu16-010:~/workspace/phase5/android$ 

解决办法:vim 打开/usr/lib/python2.7/dist-packages/pybootchartgui/draw.py
找到下面两行,将其修改为新得两行
#xscale = float(chart_bounds[2]) / max(x for (x,y) in data) //old
#yscale = float(chart_bounds[3]) / max(y for (x,y) in data) //old

xscale = float(chart_bounds[2]) / max(0.00001, max(x for (x,y) in data)) //new
yscale = float(chart_bounds[3]) / max(0.00001, max(y for (x,y) in data)) //new

6,bootchart 图形分析

整个图表以时间线为横轴,图标上方为 CPU 和 磁盘的利用情况,下方是各进程的运行状态条,显示各个进程的开始时间与结束时间以及对 CPU、I/O 的利用情况,我们关心的各个进程的运行时间以及 CPU 的使用情况,进而优化系统。
可以通过 Laucher 的启动完成时间判断开机完成完成时间,也就是开机动画结束的时间。
在这里插入图片描述

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值