代码改变世界

android TraceView (图形化性能测试工具)使用入门笔记

2011-09-26 21:43  youxiachai  阅读(2781)  评论(2编辑  收藏  举报

创建你TraceView

1.在开始使用TraceView你要注意:

  你的设备和模拟器必须设置SD card 和 你的程序拥有对SD card 具有读写操作的权限(

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />)

2.在你的程序中使用TraceView

 // 开始跟踪然后自动保存到 "/sdcard/test.trace"
    Debug.startMethodTracing("test");
    // ...
    // 停止跟踪
    Debug.stopMethodTracing();

使用traceView就只需要这两个方法了…

举个例子我们可以在:

//onCreate方法中调用
onCreate(){
Debug.startMethodTracing("test");
}
//.............

//onPause 方法中结束
onPause{
Debug.stopMethodTracing();

}

当然,你Debug的位置你可以随便设置,只要符合要求就行

然后,结束调试好,你会在eclipse 中的file explorer 中看到生成的文件

image

选择

image

把我们要的trace文件拿出来

image

这里注意,文件路径要大全,不然,无法显示…

时间片面板(Timeline panel)

image

分析面板(Profile panel)

image

以下是翻译

英语 中文
Incl 调用方法占用时间百分比
Inclusive 调用方法时间(ms)(包括了所有方法的调用)
Excl 执行方法占用时间百分比
Exclusive 执行方法占用时间(ms)(不包括子方法的调用)
Calls+Recur Calls/Total 调用和重复调用的次数
Time/Call 总的时间(ms)

 

文档中提及一个dmtracdedump 的工具 要预装Graphviz ,而且,还要写pytho脚本才能用…

image

效果就是这样,有兴趣的可以参考:

http://blog.csdn.net/zjujoe/article/details/6080738