Android 性能评测
Android 评测 性能
  请移步 Android性能优化典范
背景知识
 

- Memory Churn内存抖动,内存抖动是因为大量的对象被创建又在短时间内马上被释放。 
瞬间产生大量的对象会严重占用Young Generation的内存区域,当达到阀值,剩余空间不够的时候,也会触发GC。 
- 即使每次分配的对象占用了很少的内存,但是他们叠加在一起会增加Heap的压力,从而触发更多其他类型的GC。这个操作有可能会影响到帧率,并使得用户感知到性能问题。
 
  通过Allocation Tracker来查看在短时间内,同一个栈中不断进出的相同对象。这是内存抖动的典型信号之一。
时间
API
- System.currentTimeMillis 
 
- System.nanoTime 
 
- Debug.threadCpuTimeNanos 
 
- SystemClock.currentThreadTimeMillis
 
- SystemClock.elapsedRealtime 
 
- SystemClock.uptimeMillis 
 
跟踪
- startMethodTracing() 
 
- startMethodTracing(String traceName) 
 
- startMethodTracing(String traceName, int bufferSize) 
 
- startMethodTracing(String traceName, int bufferSize, int flags) 
 
- Debug.stopMethodTracing() 
 
Debug.startMethodTracing(“/sdcard/awesometrace.trace”); // perform operation you want to trace here BigInteger fN = Fibonacci.computeRecursivelyWithCache(100000); Debug.stopMethodTracing(); 
使用 Traceview 工具
参数说明
- Name: the name of the method 
 
- Incl %: the percentage of time spent in that method (including children methods) 
 
- Inclusive: the time in milliseconds spent in that method (including children methods) 
 
- Excl %: the percentage of time spent in that method (excluding children methods) 
 
- Exclusive: the time in milliseconds spent in that method (excluding children methods) 
 
- Calls+RecurCalls/Total: the number of calls and recursive calls 
 
- Time/Call: the average time per call in milliseconds 
 
  使用说明 
  1. 仅使用上述参数的时间值作为评估方法执行的快慢; 
  2. Traceview 并不完美
Native Tracing
使用说明
- 示例 “emulator –trace mytrace –avd myavd”
 
- Debug.startNativeTracing() 和 Debug.stopNativeTracing() 
 
- 或者按 F9 键 (第 1 下打开跟踪,第 2 下关闭)
 
查看报告
- 在 AVD 目录下将生成一个命名为 mytrace 的文件夹,其包含以下报告: 
- qtrace.bb 
 
- qtrace.exc 
 
- qtrace.insn 
 
- qtrace.method 
 
- qtrace.pid 
 
- qtrace.static 
 
 
开发者选项
- 选择 Show GPU Overdraw 

 
- 选择 Profile GPU Rendering,选中 On screen as bars 的选项 
 
 
