安卓性能检测
如何使用跟踪视图
将安卓- SDK-window sools路径添加到路径
2 .编写测试代码:
packagecom.wwj.traceview;
importjava.util.ArrayList;
importjava.util.List;
importandroid.app.Activity;
importandroid.os.Bundle;
importandroid.os.Debug;
importandroid.view.View;
importandroid.widget.Toast;
publicclassmainactivityextendsactivity {
privateListlist1=newArrayList (;
@Override
公共语音创建(bundlesavedinstancestate )。
super.oncreate (savedinstancestate;
setcontentview (r.layout.activity _ main;
}
//最初的测试方法
公共语音测试1 () {
在List1对象中添加10000个
for(inti=0; I
list1.add(I;
}
}
//第二种测试方法
公共语音测试2 () {
依次获取List对象中的元素
for(inti=0; I
list1.get(I;
}
}
公共void onclick _ test (view view ) {
try{
获取执行test1方法之前的时间点(单位:毫秒) )
long start1=system.current time millis (;
test1(;
longen D1=system.current time millis (;
获取执行test2方法之前的时间点(单位:毫秒)
long start2=system.current time millis (;
test2(;
longend2=system.current time millis (;
//显示测试结果
toast.maketext(this,' test1方法的执行时间:'(end1-start1) )毫秒
test2方法的执行时间: '
(end2-start2)、毫秒)、Toast.LENGTH_LONG )、show ); */
获取调用test1方法之前的内存
/*longstart1=Memory.used (;
test1(;
获取调用test1方法后的内存
longend1=Memory.used (;
获取调用test1方法之前的内存
longstart2=Memory.used (;
test2(;
获取调用test1方法后的内存
longend2=Memory.used (;
toast.maketext(this,' test1 )方法消耗的内存: ' (end1- start1) )字节
test2方法消耗的内存: '
(end2-start2)、“字节”、Toast.LENGTH_LONG )、 show );
*/
//开始监视方法
debug.startmethodtracing (wwj _ trace );
test1(;
test2(;
Debug.stopMethodTracing (;
}catch(exceptione ) {
e .打印任务跟踪(;
}
}
}
3 .记住设置权限:
单击按钮时,会在SD卡的根目录中生成后缀为trace的文件
4 .将此文件导出到您要放置的位置。 例如,c:wwj_trace.trace
5 .运行5.traceviewc:wwj_trace.trace命令将显示traceview视图
接触安卓一段时间的童鞋一定知道traceview这个工具。 因为本人最近也有必要进行性能检查,所以要学习这个工具的使用方法。 很简单。 这里主要介绍这个工具的重要参数的含义。 我是根据自己的理解写的。 也不知道是否正确。
各参数的含义:
Inl Cpu Time% :在执行过程中调用方法的时间占总时间的百分比。
Incl Cpu Time :每次调用该方法所用的总时间(包括调用子函数所用的时间)每次调用该方法所用的时间*执行次数。
Excl Cpu Time% :方法本身消耗的时间。 调用其他方法所消耗的时间除外。 占总时间的百分比。
Excl Cpu Time :方法本身消耗的时间。
Incl Real Time% :方法实际执行的时间占总时间的百分比。
Incl Real Time :方法实际执行的时间。
Excl Real Time% :方法实际执行的时间占总时间的百分比
Excl Real Time :实际执行方法所消耗的时间
Calls RecurCalls/Total :方法被调用的次数重复调用的次数
Cpu Time/Call :每次执行方法时的时间
Real Time/Call :方法的实际执行时间
关于traceview工具的学习记录到此为止。 如果发现童鞋错了,请改正。