19.2. 通过 perf circular buffer 收集特定数据以监控性能瓶颈


使用 perf 工具,您可以创建由您指定的事件触发的环形缓冲,以仅收集您感兴趣的数据。要创建收集事件数据的 circular 缓冲,请将 --overwrite--switch-output-event 选项用于 perf

先决条件

  • 已安装 perf 用户空间工具。如需更多信息,请参阅安装 perf
  • 您已在对进程或应用程序感兴趣的位置在需要监控的进程或应用程序中放置了一个 uprobe

    # perf probe -x </path/to/executable> -a function
    
    Added new event:
      probe_executable:function   (on function in /path/to/executable)
    
    You can now use it in all perf tools, such as:
    
        perf record -e probe_executable:function -aR sleep 1
    Copy to Clipboard Toggle word wrap

流程

  • 使用 uprobe 作为触发器事件创建环形缓冲:

    # perf record --overwrite -e cycles --switch-output-event probe_executable:function ./executable
    [ perf record: dump data: Woken up 1 times ]
    [ perf record: Dump perf.data.2021021012231959 ]
    [ perf record: dump data: Woken up 1 times ]
    [ perf record: Dump perf.data.2021021012232008 ]
    ^C[ perf record: dump data: Woken up 1 times ]
    [ perf record: Dump perf.data.2021021012232082 ]
    [ perf record: Captured and wrote 5.621 MB perf.data.<timestamp> ]
    Copy to Clipboard Toggle word wrap

    此命令启动可执行文件并收集 cpu 周期,在 option -e 选项后指定,直到 perf 检测到 uprobe,该触发器事件在 --switch-output-event 选项后指定的触发器事件。此时,perf 采用循环缓冲区中所有数据的快照,并将其存储在由时间戳标识的唯一 perf.data 文件中。本例生成总计 2 个快照,最后的 perf.data 文件是通过按 Ctrl+C 强制的。

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat