读取并解析perf.data。

11

我正在使用命令perf record从Linux记录性能计数器。

我想将结果perf.data用作其他编程应用程序的输入。请问您知道如何读取和解析perf.data中的数据吗?是否有一种方法可以将其转换为.text文件或.csv

4个回答

7

在Linux工具的perf工具中,有一个内置的perf.data解析器和打印机,可以使用子命令“script”。

要转换perf.data文件

perf script > perf.data.txt

要将perf record的输出转换为其他文件(perf record -o filename.data),请使用-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.

2
perf script的输出是文本,阅读起来很容易,但使用python/perl/awk或其他脚本解析它可能并不容易。 - osgx
2
perf script 具体允许使用 Python 和 Perl 脚本处理 perf 事件。请参阅 man perf-script-python - Zulan

4

你知道吗,如果要在开箱即用的Ubuntu发行版上运行perf data convert --to-json命令,是否需要使用LIBBABELTRACE=1编译Linux内核呢? - Noah

1

-3
下面是一个示例命令定义,将服务检查性能数据重定向到文本文件,以供其他应用程序稍后处理:
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

    }

1
听起来很有趣.. 你能详细说明一下我该如何使用这段代码吗? - Mohamad Ibrahim
你需要更改Nagios配置,以便数据被写入文本文件。 - Yannick
@Yannick,这个问题不是关于Nagios的,而是关于Linux-tools中的perf命令行工具(内核的perf_events子系统),用于应用程序分析,而不是用于Nagios集成或Nagios性能数据https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/3/en/perfdata.html其中考虑了ping的性能。 - osgx

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接