systrace小记

204 阅读1分钟

抓取systrace

  1. 抓取命令
py2 systrace.py gfx input view wm am bionic power sched camera freq idle video --app=com.android.camera2 -b 20480 -t 4 -o capture.html
  1. 参数解释
py2 systrace.py [模块...] --app=包名 -t 秒数 -o 输出地址 -b 输出文件大小 

线程状态

  • running
  • runnable
    • 可通过wake from tid 查看唤醒线程,同时查看该线程在CPU上的信息
  • sleep
  • Uninterruptible sleep - IO block
  • Uninterruptible Sleep

刷新率和FPS

刷新率一般为60hz, 90hz, 120hz指的是硬件上的,比如60hz 就是16.6ms绘制一次。 而 fps指的是软件上的每秒绘制60次。

  • 刷新率 > fps, 无效浪费帧率和功耗
  • 刷新率 < fps, 丢帧
  • 刷新率 = fps 最佳

Surfaceflinger

作用:

  1. 接收应用提交到缓冲区(根据显示设备状态选择性接收)
  2. Vsync 到达时,遍历缓冲区。如果有则用新的,没有则用旧的,收集完交给硬件HWC合成。 image.png

总流程: VsyncAPP -> 应用UI thread (doFrame, traversal, draw) -> 应用 Render Thread -> DrawFrame(dequebuffer从 SF 获取 buffer, app处理, 放回queuebuffer -> VsyncSF -> SF从 buffer 获取可用 buffer 进行合成。 -> onMessageReceived -> binder调用 HWC

Input 事件

system_server(inputreader - > inputdispather -> outboundqueue -> waitqueue待app 结果) app (pendinginput -> 执行动作)

Vsync

image.png

Choreographer

  • VsyncAPP到来时Choreographer做处理。

image.png

image.png

掉帧

从 SF + buffer有无内容判断

参考的博客

www.androidperformance.com/