学习https://www.bilibili.com/video/av77424850/

竟然发现Google中国在哔哩哔哩也有账号,i了i了=-=

trace分析对应的UI网址

https://ui.perfetto.dev/

官网:

https://perfetto.dev/

1.简介

https://perfetto.dev/docs/

Perfetto is a production-grade open-source stack for performance instrumentation and trace analysis. It offers services and libraries and for recording system-level and app-level traces, native + java heap profiling, a library for analyzing traces using SQL and a web-based UI to visualize and explore multi-GB traces.

简单来说就是性能检测和trace分析,了解到的是systrace的升级版

System-wide tracing on Android and Linux

On Linux and Anroid, Perfetto bundles a number of data sources that are able to gather detailed performance data from different system interfaces. For the full sets and details see the Data Sources section of the documentation. Same examples:

  • Kernel tracing: Perfetto integrates with Linux's ftrace and allows to record kernel events (e.g scheduling events, syscalls) into the trace.

  • /proc and /sys pollers, which allow to sample the state of process-wide or system-wide cpu and memory counters over time.

  • Integration with Android HALs modules for recording battery and energy-usage counters.

  • Native heap profiling: a low-overhead heap profiler for hooking malloc/free/new/delete and associating memory to callstacks, based on out-of-process unwinding, configurable sampling, attachable to already running processes.

  • Java heap profiling: an out-of-process profiler tightly integrated with the Android RunTime that allows to get full snapshots of the managed heap retention graph (types, field names, retained size and references to other objects) without, however, dumping the full heap contents (strings and bitmaps) and hence reducing the serialization time and output file size.

On Android, Perfetto is the next-generation system tracing system and replaces the chromium-based systrace. ATrace-based intstrumentation remains fully supported. See Android developer docs for more details.

简要说来举例说支持如下5个功能点

  • 内核跟踪
  • cpu和内存计数器跟踪
  • 电量使用情况跟踪
  • native heap分析
  • java heap 分析

提及说是systrace的下一代版本

Trace visualization

Perfetto provides also a brand new trace visualizer for opening and querying hours-long traces, available at ui.perfetto.dev. The new visualizer takes advantage of modern web platform technolgies. Its multi-threading design based WebWorkers keeps the UI always responsive; the analytical power of Trace Processor and SQLite is fully available in-browser through WebAssembly.

The Perfetto UI works fully offline after it has been opened once. Traces opened with the UI are processed locally by the browser and do not require any server-side interaction.

提及了ui.perfetto.dev是基于web的可视化工具,一次打开后就可以脱机工作,不与服务器做交互

2.Get Started

perfetto允许您从各种数据源(通过ftrace进行内核调度,通过atrace进行用户空间检测以及此站点中列出的所有其他数据源)收集来自Android设备的系统范围的性能跟踪。

Starting the tracing services

Due to Perfetto's service-based architecture , the traced and traced_probes services need to be running to record traces.

These services are shipped on Android system images by default since Android 9 (Pie) but are not always enabled by default. On Android 9 (P) and 10 (Q) those services are enabled by default only on Pixel phones and must be manually enabled on other phones. Since Android 11 (R), perfetto services are enabled by default on most devices.

To enable perfetto services run:

# Will start both traced and traced_probes.

adb shell setprop persist.traced.enable 1

简单来说就是要启动一下perfetto服务,我是从开发者选项中打开对应“系统跟踪”在systemUi的快捷键的,看了下这个值已经是true了

Recording a trace

You can collect a trace in the following ways:

  • Through the record page in the Perfetto UI.
  • Using the perfetto command line interface [reference].

记录trace方式一共有两种,UI和命令行

3.UI

可以看到Ui能进行更详细的设置,比如CPU,比如对应用等等,应用下面的用户注解ctrl+点击可以多选categories

浏览器连接adb需要支持https

测试了火狐和360都不行,Google浏览器可以adb连接上~

但是权限被拒绝了。。。打开了usb调试下面的3个开关都不行,后面试下native版本有没有用。。。

4. Perfetto CLI

https://perfetto.dev/docs/reference/perfetto-cli

https://developer.android.google.cn/studio/command-line/perfetto?hl=zh_cn

https://developer.android.google.cn/studio/command-line/perfetto?hl=en

This section describes how to use the perfetto commandline binary to capture traces. Examples are given in terms of an Android device connected over ADB.

perfetto has two modes for configuring the tracing session (i.e. what and how to collect):

  • lightweight mode: all config options are supplied as commandline flags, but the available data sources are restricted to ftrace and atrace. This mode is similar to systrace.
  • normal mode: the configuration is specified in a protocol buffer. This allows for full customisation of collected traces.

General options

The following table lists the available options when using perfetto in either mode.

Option Description
--background | -d Perfetto immediately exits the command-line interface and continues recording your trace in background.
--out OUT_FILE | -o OUT_FILE Specifies the desired path to the output trace file, or - for stdout. perfetto writes the output to the file described in the flags above. The output format compiles with the format defined in AOSP trace.proto.
--dropbox TAG Uploads your trace via the DropBoxManager API using the tag you specify.
--no-guardrails Disables protections against excessive resource usage when enabling the --dropbox flag during testing.
--reset-guardrails Resets the persistent state of the guardrails and exits (for testing).
--query Queries the service state and prints it as human-readable text.
--query-raw Similar to --query, but prints raw proto-encoded bytes of tracing_service_state.proto.
--help | -h Prints out help text for the perfetto tool.

Lightweight mode

The general syntax for using perfetto in lightweight mode is as follows:

 adb shell perfetto [ --time TIMESPEC ] [ --buffer SIZE ] [ --size SIZE ][ ATRACE_CAT | FTRACE_GROUP/FTRACE_NAME | FTRACE_GROUP/* ]...

The following table lists the available options when using perfetto in lightweight mode.

Option Description
--time TIME[s|m|h] | -t TIME[s|m|h] Specifies the trace duration in seconds, minutes, or hours. For example, --time 1m specifies a trace duration of 1 minute. The default duration is 10 seconds.
--buffer SIZE[mb|gb] | -b SIZE[mb|gb] Specifies the ring buffer size in megabytes (mb) or gigabytes (gb). The default parameter is --buffer 32mb.
--size SIZE[mb|gb] | -s SIZE[mb|gb] Specifies the max file size in megabytes (mb) or gigabytes (gb). By default perfetto uses only in-memory ring-buffer.

This is followed by a list of event specifiers:

Event Description
ATRACE_CAT Specifies the atrace categories you want to record a trace for. For example, the following command traces Window Manager using atrace: adb shell perfetto --out FILE wm. To record other categories, see this list of atrace categories.
FTRACE_GROUP/FTRACE_NAME Specifies the ftrace events you want to record a trace for. For example, the following command traces sched/sched_switch events: adb shell perfetto --out FILE sched/sched_switch
FTRACE_GROUP/* Record all events in group (e.g. sched/*). Specifies the group of ftrace events you want to record a trace for. For example, the following command traces sched/* events: adb shell perfetto --out FILE 'sched/*'

Normal mode

The general syntax for using perfetto in normal mode is as follows:

 adb shell perfetto [ --txt ] --config CONFIG_FILE

The following table lists the available options when using perfetto in normal mode.

Option Description
--config CONFIG_FILE | -c CONFIG_FILE Specifies the path to a configuration file. In normal mode, some configurations may be encoded in a configuration protocol buffer. This file must comply with the protocol buffer schema defined in AOSP trace_config.proto. You select and configure the data sources using the DataSourceConfig member of the TraceConfig, as defined in AOSP data_source_config.proto.
--txt Instructs perfetto to parse the config file as pbtxt. This flag is experimental, and it's not recommended that you enable it for production.

命令行有的连接点击不进去,我们可以退而求其次,我们看到Ui界面也有个命令行,这应该是将用户的UI选择换成命令行了

adb shell perfetto \-c - --txt \-o /data/misc/perfetto-traces/trace \
<<EOFbuffers: {size_kb: 8960fill_policy: DISCARD
}
buffers: {size_kb: 1280fill_policy: DISCARD
}
data_sources: {config {name: "linux.process_stats"target_buffer: 1process_stats_config {scan_all_processes_on_start: true}}
}
data_sources: {config {name: "linux.sys_stats"sys_stats_config {stat_period_ms: 1000stat_counters: STAT_CPU_TIMESstat_counters: STAT_FORK_COUNT}}
}
data_sources: {config {name: "linux.ftrace"ftrace_config {ftrace_events: "sched/sched_switch"ftrace_events: "power/suspend_resume"ftrace_events: "sched/sched_wakeup"ftrace_events: "sched/sched_wakeup_new"ftrace_events: "sched/sched_waking"ftrace_events: "power/cpu_frequency"ftrace_events: "power/cpu_idle"ftrace_events: "power/gpu_frequency"ftrace_events: "sched/sched_process_exit"ftrace_events: "sched/sched_process_free"ftrace_events: "task/task_newtask"ftrace_events: "task/task_rename"ftrace_events: "ftrace/print"atrace_categories: "gfx"atrace_categories: "view"atrace_categories: "wm"atrace_categories: "am"atrace_categories: "rs"atrace_categories: "pm"atrace_categories: "ss"}}
}
duration_ms: 10000EOF

normal的config不知道怎么写,用lightweight mode来吧

自己写了个类似的命令行

adb shell perfetto -t 30s -b 1gb -s 1gb --out /data/misc/perfetto-traces/trace.perfetto-trace wm gfx view am rs pm ss sched/* task/* ftrace/print

大概是30s抓一些设定了atrace和ftrace,如果不知道对应的categories,可以在ui上选好了,命令行那边会显示出来的

用perfetto可以看到哔哩哔哩的UI线程绘制流程了~

对比系统默认抓的perfetto,信息量少得可怜

补充下系统抓perfetto的方法

Supported data sources

This section describes the different sources that perfetto uses to generate your trace.

FTrace

The ftrace data source allows perfetto to get events from the kernel.

You can enable this source by setting ftrace_config in the DataSourceConfig.

The events that can be enabled include:

  • Scheduling activity:

    • sched/sched_switch
    • sched/sched_wakeup
    • sched/sched_wakeup_new
    • sched/sched_process_exec
    • sched/sched_process_exit
    • sched/sched_process_fork
    • sched/sched_process_free
    • sched/sched_process_hang
    • sched/sched_process_wait
  • Filesystem events:

    • ext4
    • f2fs
    • block
  • ATrace events

Depending on your device, OS version, and kernel, more events might be available. For more information, refer to the config protos.

Process Stats

The process stats data source allows you to get polled counters about the system and individual processes.

You can enable this source by setting process_stats_config and sys_stats_config in the DataSourceConfig.

The data that profetto generates includes:

  • System-wide

    • /proc/meminfo
    • /proc/vmstat
    • /proc/stat
  • Per process

    • /proc/<pid>/status
    • /proc/<pid>/oom_score_adj

Depending on your device, OS version, and kernel, more events might be available. To learn more, refer to the config protos for sys_stats and process_stats.

Heapprofd

Heapprofd allows you to sample the causes of native memory use.

You can enable this source by setting heapprofd_config in the DataSourceConfig.

This produces ProfilePackets. These include the Java frames of the callstack.

Additional information on how to use heapprofd can be found at perfetto.dev.

Other sources

Depending on your device, OS version, and kernel, more data-sources might be available. To learn more, refer to the data source config protos.

Additional information about perfetto can be found at perfetto.dev.

另外系统抓perfetto的方法

https://developer.android.google.cn/studio/profile/systrace/on-device

启用开发者选项(如果尚未启用此选项)。
        打开开发者选项设置屏幕。
        在调试部分中,选择系统跟踪。此时会打开“系统跟踪”应用,其中显示了应用菜单。

在应用菜单中,启用显示“快捷设置”图块,如图 2 所示。系统会将系统跟踪图块图块添加到快捷设置面板中,如图 1 所示:

导出trace

cd /path-to-traces-on-my-dev-machine && \
          adb pull /data/local/traces/ .

多选些atrace和ftrace,信息比默认的多好多了

总结

抓perfetto命令方法

  • ui(还有点问题,用native + google浏览器试试)
  • 命令行

adb shell perfetto -t 30s -b 1gb -s 1gb --out /data/misc/perfetto-traces/trace.perfetto-trace wm gfx view am rs pm ss sched/* task/* ftrace/print

具体atrace和ftrace 的 categories可以参考perfetto的https://ui.perfetto.dev/#!/record?p=instructions

待续

https://perfetto.dev/docs/quickstart/android-tracing

https://perfetto.dev/docs/concepts/config

之前看的https://ui.perfetto.dev/#!/record?p=instructions

其实就是开发者文档里的config文件,继续学习

(两百五十六)学习perfetto(一)相关推荐

  1. OpenCV学习笔记(五十六)——InputArray和OutputArray的那些事core OpenCV学习笔记(五十七)——在同一窗口显示多幅图片 OpenCV学习笔记(五十八)——读《Mast

    OpenCV学习笔记(五十六)--InputArray和OutputArray的那些事core 看过OpenCV源代码的朋友,肯定都知道很多函数的接口都是InputArray或者OutputArray ...

  2. JavaScript学习(五十六)—寄生式继承(临时构造器的使用)

    JavaScript学习(五十六)-寄生式继承(临时构造器的使用) 寄生式继承(临时构造器的使用): 之所以要使用临时构造器就是要在实现原型链继承时获取上级构造方法原型中的内容,而不要它的私有属性 默 ...

  3. Slicer学习笔记(五十六)slicer分割transformNode包含的信息与使用

    Slicer学习笔记(五十六)slicer分割transformNode包含的信息与使用 1.打印transformNode信息 2.测试 2.1.变换前 2.2.变换后 3.使用坐标变换 1.打印t ...

  4. 深度学习入门(五十六)循环神经网络——循环神经网络RNN

    深度学习入门(五十六)循环神经网络--循环神经网络RNN 前言 循环神经网络--循环神经网络RNN 课件 潜变量自回归模型 循环神经网络 使用循环神经网络的语言模型 困惑度(perplexity) 梯 ...

  5. MFC Windows 程序设计[五十六]之开启子对话框(附源码)

    MFC Windows 程序设计[五十六]之开启子对话框 程序之美 前言 主体 运行效果 核心代码 逻辑分析 结束语 程序之美 前言 MFC是微软公司提供的一个类库(class libraries), ...

  6. 【Visual C++】游戏开发五十六 浅墨DirectX教程二十三 打造游戏GUI界面(一)

    本系列文章由zhmxy555(毛星云)编写,转载请注明出处. 文章链接: http://blog.csdn.net/poem_qianmo/article/details/16384009 作者:毛星 ...

  7. [Python从零到壹] 五十六.图像增强及运算篇之图像平滑(中值滤波、双边滤波)

    欢迎大家来到"Python从零到壹",在这里我将分享约200篇Python系列文章,带大家一起去学习和玩耍,看看Python这个有趣的世界.所有文章都将结合案例.代码和作者的经验讲 ...

  8. 中国五十六个民族简介

    56个民族是中华人民共和国灿烂星空中(五十六个星座). 中华民族共包括56个民族,汉族是中国的主体民族,占全部人口的91.51%,其他还有55个民族,占8.49%(第六次人口普查).汉族和55个少数民 ...

  9. 【正点原子FPGA连载】第五十六章 双目OV5640摄像头HDMI显示实验 -摘自【正点原子】新起点之FPGA开发指南_V2.1

    1)实验平台:正点原子新起点V2开发板 2)平台购买地址:https://detail.tmall.com/item.htm?id=609758951113 3)全套实验源码+手册+视频下载地址:ht ...

最新文章

  1. 全国计算机二级vfp知识点,全国计算机二级VFP知识点总结
  2. 检查字符串是否为有效URL的最佳正则表达式是什么?
  3. python opencv卡尺测量边缘距离
  4. 正圆锥体空间方程_你也可以理解“麦克斯韦方程组”
  5. 2016年腾讯产品笔试真题
  6. r语言 adf检验_r语言中如何进行两组独立样本秩和检验
  7. jQuery 常用的方法
  8. Kubernetes在上汽集团云平台及AI方面的应用
  9. hibernate文档
  10. Bailian2717 基本数据类型【字符串匹配】
  11. 现代Web开发需要学习的15大技术
  12. Java编程:排序算法——快速排序
  13. 2022年高压电工操作证考试题库及在线模拟考试
  14. 软件工程毕业答辩常问的问题
  15. java开发工程师必看书籍
  16. 亚马逊封号潮不断,亚马逊封号最新进展,亚马逊账号关联要怎么解决?怎么使用vmlogin浏览做到账号防关联
  17. php 卡路里计算,那些每天计算卡路里的人,为什么永远也瘦不下来?
  18. 论文笔记 | Learning Deep Features for Discriminative Localization
  19. 分析Android 搜狗输入法在微信和QQ中发送图片和表情
  20. 怎么打开avi文件文件损坏_什么是AVI文件(以及如何打开一个文件)?

热门文章

  1. POJ 3264 Balanced Lineup
  2. css波浪动画使用图片
  3. Software Testing - UI自动化测试常用设计模式之工厂(Java)
  4. 腾讯云上申请免费的安全证书--【域名身份验证】
  5. 论文阅读: Spatial transformer networks
  6. PhpSpreadsheet实现Excel操作
  7. Autoware:ndt_mapping节点
  8. C语言程序设计教程蒋清明,C语言程序设计教程(第2版)
  9. mysql sysdatabases_未能在 sysdatabases 中找到数据库 aa1xxxx 所对应的条目。没有找到具有该名称的条目...
  10. 时间工具类、Instant、date、LocalDate、String、LocalDateTime 相互转换