【问题标题】:Read and parse perf.data读取和解析 perf.data
【发布时间】:2012-08-12 11:34:57
【问题描述】:

我正在使用 perf record 命令记录来自 linux 的性能计数器。

我想将结果 perf.data 用作其他编程应用程序的输入。你知道我应该如何读取和解析perf.data 中的数据吗?有没有办法将其转换为.text 文件或.csv?

【问题讨论】:

    标签: linux performance parsing profiling performancecounter


    【解决方案1】:

    linux工具的perf工具中有内置的perf.data解析器和打印机,子命令为“script”。

    转换perf.data文件

    perf script > perf.data.txt
    

    要在其他文件 (perf record -o filename.data) 中转换 perf 记录的输出,请使用 -i 选项:

    perf script -i filename.data > filename.data.txt
    

    perf script 记录在 man perf-script,可在线获取 http://man7.org/linux/man-pages/man1/perf-script.1.html

       perf-script - Read perf.data (created by perf record) and display
       trace output
    
       This command reads the input file and displays the trace recorded.
    
           'perf script' to see a detailed trace of the workload that was
           recorded.
    

    【讨论】:

    • perf script 的输出是文本并且是可读的,但是用 python/perl/awk/something 脚本解析它可能并不容易。
    • perf script 特别允许使用 python 和 perl 脚本处理 pref 事件。见man perf-script-python
    【解决方案2】:

    https://github.com/google/perf_data_converter的quipper子项目可以解析perf.data文件。

    【讨论】:

      【解决方案3】:

      perf data convert --to-json 4 月登陆。

      https://man7.org/linux/man-pages/man1/perf-data.1.html

      【讨论】:

      • 知道perf data convert --to-json 是否也需要使用LIBBABELTRACE=1 构建Linux。试图让它在开箱即用的 ubuntu 发行版上运行。
      【解决方案4】:

      将服务检查性能数据重定向到文本文件以供其他应用程序稍后处理的示例命令定义如下所示:

      define command{
      
          command_name    store-service-perfdata
      
          command_line    /bin/echo -e "$LASTSERVICECHECK$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICESTATE$\t$SERVICEATTEMPT$\t$SERVICESTATETYPE$\t$SERVICEEXECUTIONTIME$\t$SERVICELATENCY$\t$SERVICEOUTPUT$\t$SERVICEPERFDATA$" >> /usr/local/nagios/var/service-perfdata.dat
      
          }
      

      【讨论】:

      • 似乎很有趣..你能详细说明我应该如何使用这段代码吗?
      • 您必须为此更改您的 nagios 配置,以便将数据写入文本文件中。
      • @Yannick,这个问题不是关于 nagios,而是关于 linux-tools 的perf 命令行工具(内核的perf_events 子系统),它用于应用程序分析,而不是用于 nagios 集成或nagios perfdata assets.nagios.com/downloads/nagioscore/docs/nagioscore/3/en/… 考虑了 ping 的性能。
      猜你喜欢
      • 1970-01-01
      • 2021-11-26
      • 2017-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-01
      • 2011-12-28
      相关资源
      最近更新 更多