android提android.os.Debug类可以对程序进行跟踪调试
具体如下:
在需要开始跟踪的地方加入 Debug.startMethodTracing(“/sdcard/debug”);
最终在停止调试的地方加入 Debug.stopMethodTracing();
最终在sdcard上生成的debug文件我们可以用sdk/tools中的traceview来查看运行的结果。
debug中其它函数使用
1) 取毫微秒级的时间,用于计算时间
threadCpuTimeNanos()
2) 统计两点间的内存分配情况
startAllocCounting()
stopAllocCounting()
getGlobalAllocCount()
在代码中加入取样设定
import dalvik.system.SamplingProfiler
SamplingProfile sp = SamplingProfiler.getInstance();
sp.start(n); // n为设定每秒采样次数
sp.logSnapshot(sp.snapshot());
……
sp.shutDown();
它会启一个线程监测,在logcat中打印信息