tracer ftrace笔记(17)——atrace命令抓trace

发布时间 2023-05-27 16:42:28作者: Hello-World3

一、atrace命令解析

1. 帮助信息

# atrace -h

用法:usage: atrace [options] [categories...]

选项包括:
   -a appname        为逗号分隔的 cmdlines 列表启用应用程序级跟踪; * 是匹配任何进程的通配符
   -b N              使用大小为 N KB 的跟踪缓冲区
   -c                跟踪到循环缓冲区
   -f filename       使用写在文件中的类别作为一行中的空格分隔值
   -k fname,...      跟踪列出的内核函数. 实测 atrace -k cpu_stopper_thread/workqueue_execute_start 都失败。
   -n                忽略信号
   -s N              在跟踪前休眠 N 秒 [默认 0]
   -t N              跟踪 N 秒 [默认 5]
   -z                压缩trace dump
   --async_start     开始循环跟踪并立即返回
   --async_dump      转储循环跟踪缓冲区的当前内容
   --async_stop      停止跟踪并转储循环跟踪缓冲区的当前内容
   --stream          在进入跟踪缓冲区时流式跟踪到标准输出。注意:这可能会占用大量 CPU 时间,最好用于测量不受 CPU 性能影响的事物,例如页面缓存使用情况。
   --list_categories 列出可用的跟踪类别
  -o filename        将跟踪写入指定文件而不是标准输出。

2. 支持抓取的条目

# atrace --list_categories
         gfx - Graphics
       input - Input
        view - View System
     webview - WebView         //会显示什么内容?
          wm - Window Manager
          am - Activity Manager
          sm - Sync Manager
       audio - Audio
       video - Video
      camera - Camera
         hal - Hardware Modules
         res - Resource Loading
      dalvik - Dalvik VM
          rs - RenderScript
      bionic - Bionic C Library
       power - Power Management
          pm - Package Manager
          ss - System Server
    database - Database
     network - Network
         adb - ADB
    vibrator - Vibrator
        aidl - AIDL calls
       nnapi - NNAPI
         rro - Runtime Resource Overlay
         pdx - PDX services
       sched - CPU Scheduling
         irq - IRQ Events
      irqoff - IRQ-disabled code section tracing
  preemptoff - Preempt-disabled code section tracing
         i2c - I2C Events
        freq - CPU Frequency
        idle - CPU Idle
        disk - Disk I/O
         mmc - eMMC commands
        sync - Synchronization
       workq - Kernel Workqueues
  memreclaim - Kernel Memory Reclaim
  regulators - Voltage and Current Regulators
  binder_driver - Binder Kernel driver
  binder_lock - Binder global lock trace
   pagecache - Page cache
      memory - Memory
     thermal - Thermal event
         gfx - Graphics (HAL)
         ion - ION allocation (HAL)

 

二、atrace使用

1. 常用抓取命令配置

adb shell atrace -c -b 20480 --async_start gfx input view webview wm am sched idle freq disk workq

adb shell atrace -c -b 20480 --async_stop gfx input view webview wm am sched idle freq disk workq -o /sdcard/test_webview.trace


2. 可以检索某项trace

adb shell "atrace gfx -b 20480 -t 1 | grep releaseBufferCallbackLocked"


3. 可不间断循环抓取

//开始:
adb shell atrace -c -b 10240 --async_start gfx

//循环输出
adb shell atrace -c -b 10240 --async_dump gfx > a1.trace
adb shell atrace -c -b 10240 --async_dump gfx > a2.trace
...

//停止
adb shell atrace -c -b 10240 --async_stop