systrace简介

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/rikeyone/article/details/86523375

简介

systrace是给予内核ftrace机制来实现的一套trace工具,android上层实现了Trace类,用于把trace信息写入ftrace buffer,最后再通过ftrace buffer抓取出来。因此想要使用systrace,必须设备使能了ftrace功能。另外User版本的固件不可以抓trace,userdebug和eng的固件才可以抓。

systrace在Android SDK中有包含这套工具:android-sdk-linux/platform-tools/systrace,主要是调用其中的systrace.py脚本来抓取数据。

systrace.py 命令参数

  -h, --help            show this help message and exit
  -o FILE               write HTML to FILE
  -t N, --time=N        trace for N seconds
  -b N, --buf-size=N    use a trace buffer size of N KB
  -k KFUNCS, --ktrace=KFUNCS
                        specify a comma-separated list of kernel functions to
                        trace
  -l, --list-categories
                        list the available categories and exit
  -a APP_NAME, --app=APP_NAME
                        enable application-level tracing for comma-separated
                        list of app cmdlines
  --no-fix-threads      don't fix missing or truncated thread names
  --no-fix-tgids        Do not run extra commands to restore missing thread to
                        thread group id mappings.
  --no-fix-circular     don't fix truncated circular traces
  --no-compress         Tell the device not to send the trace data in
                        compressed form.
  --link-assets         (deprecated)
  --boot                reboot the device with tracing during boot enabled.
                        The report is created by hitting Ctrl+C after the
                        device has booted up.
  --from-file=FROM_FILE
                        read the trace from a file (compressed) rather than
                        running a live trace
  --asset-dir=ASSET_DIR
                        (deprecated)
  -e DEVICE_SERIAL, --serial=DEVICE_SERIAL
                        adb device serial number
  --agent-dirs=AGENT_DIRS
                        the directories of additional systrace agent modules.
                        The directories should be comma separated, e.g.,
                        --agent-dirs=dir1,dir2,dir3. Directory |agents| is the
                        default agent directory and will always be checked.
  --target=TARGET       chose tracing target (android or linux)

categories

systrace可用的策略如下所示:

         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
         pdx - PDX services
       sched - CPU Scheduling
         irq - IRQ Events
         i2c - I2C Events
        freq - CPU Frequency
        idle - CPU Idle
        disk - Disk I/O
        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

命令实例

抓取一段8s的systrace log:

python systrace.py -b 16384 -t 8 gfx input view webview sm hal idle freq sched wm am res dalvik -o test_trace.html

输出结果到test_trace.html,只能使用chrome浏览器双击打开。我们也可以在浏览器中输入:

chrome://tracing/

然后load对应的trace文件。

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/rikeyone/article/details/86523375