美文网首页perfetto 官方文档翻译
Perfetto 翻译第九篇-案例学习-Android启动的时候

Perfetto 翻译第九篇-案例学习-Android启动的时候

作者: David_zhou | 来源:发表于2023-10-06 12:35 被阅读0次

    前言:虽然有翻译软件,虽然有chatgpt,毕竟语言隔阂,对这个工具还是一知半解,因此想通过翻译的方式和大家来一起学习下Perfetto这个强大的工具

    Perfetto 翻译第一篇
    Perfetto 翻译第二篇
    Perfetto 翻译第三篇
    Perfetto 翻译第四篇
    Perfetto 介绍第五篇
    Perfetto 翻译第六篇
    Perfetto 翻译第七篇
    Perfetto 翻译第八篇

    #####################以下分割线#####################
    英文原文在这里
    由于Android 13(T),perfetto可以配置为在启动时自动开始记录trace。这对于trace 启动过程非常有用。

    步骤

    1 以文本格式(非二进制)创建抓取trace的配置文件。示例(/test/configs/中的更多信息)

    # One buffer allocated within the central tracing binary for the entire trace,
    # shared by the two data sources below.
    buffers {
      size_kb: 32768
      fill_policy: DISCARD
    }
    
    # Ftrace data from the kernel, mainly the process scheduling events.
    data_sources {
      config {
        name: "linux.ftrace"
        target_buffer: 0
        ftrace_config {
          ftrace_events: "sched_switch"
          ftrace_events: "sched_waking"
          ftrace_events: "sched_wakeup_new"
    
          ftrace_events: "task_newtask"
          ftrace_events: "task_rename"
    
          ftrace_events: "sched_process_exec"
          ftrace_events: "sched_process_exit"
          ftrace_events: "sched_process_fork"
          ftrace_events: "sched_process_free"
          ftrace_events: "sched_process_hang"
          ftrace_events: "sched_process_wait"
        }
      }
    }
    
    # Resolve process commandlines and parent/child relationships, to better
    # interpret the ftrace events, which are in terms of pids.
    data_sources {
      config {
        name: "linux.process_stats"
        target_buffer: 0
      }
    }
    
    # 10s trace, but can be stopped prematurely via `adb shell pkill -u perfetto`.
    duration_ms: 10000
    

    2 将文件放在设备的 `/data/misc/perfetto-configs/boottrace.pbtxt这里

    adb push <yourfile> /data/misc/perfetto-configs/boottrace.pbtxt
    

    3 然后开启perfetto_trace_on_boot 这个service:

    adb shell setprop persist.debug.perfetto.boottrace 1
    

    这个属性会在重启的时候重置,为了能在下次启动的时候能够抓取trace。

    4 重启设备

    5 输出文件会输出在/data/misc/perfetto-traces/boottrace.perfetto-trace。当开始抓取trace时,这个文件会被覆盖。

    adb pull /data/misc/perfetto-traces/boottrace.perfetto-trace
    

    该文件将在录制停止后(请确保在配置中将duration_ms设置为合理的值)或在第一个flush_period_ms之后出现。

    6 boottrace.perfetto-trace使用ui.perfetto.dev中打开

    实现细节

    1 只有在加载了持久属性之后,trace才会开始,而持久属性是在挂载/data之后发生的。

    2 启动跟踪的命令被实现为 init中的oneshot服务。

    #####################以上分割线#####################

    后记:
    1 本次主要使用百度翻译,虽然被骂,但至少翻译这个工具降低了门槛。
    2 英文文档中的长难句真的是又长又难,基于百度的翻译,然后自己再调整下,水平实在有限。
    3 技术背景知识不够,有些专有名词不知道怎么翻译,也不知道百度翻译的是否准确,功夫在诗外。
    4 万事开头难,中间难不难,还不知道。中间的事后面再说,正确一天翻译一篇。
    5 虽然可能会有人不屑,但总要有人去做不起眼的小事。
    6 google 厉害,这个perfetto 工具也很厉害。君子善假于物也。
    7 工具的使用是最简单的入门,背后还有更多的东西值得学习。
    8 水平实在有限,闻过则喜,希望有更多的人反馈,期待更好的建议

    相关文章

      网友评论

        本文标题:Perfetto 翻译第九篇-案例学习-Android启动的时候

        本文链接:https://www.haomeiwen.com/subject/uzipbdtx.html