每1毫秒从PMU收集一次有轨车辆过程的数据 [英] Collecting the data for a partiulcar process from PMU for every 1 milli second

查看:84
本文介绍了每1毫秒从PMU收集一次有轨车辆过程的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想每1毫秒访问一次特定PID的硬件性能计数器,并将输出保存到文本文件中.

I would like to access the Hardware performance counters for a particular PID for every 1 milli second and save the output to a text file.

下面的代码收集系统在一定时间内并行运行的所有进程的数据,然后将其输出到文本文件.

The below code collects the data of all the processes running in the system in parallel for a certain duration and then outputs it to a text file.

    #!/bin/sh 
    #set -x 
    ps -ef | awk '{printf($2)"\n";}' > out.txt 
    sed '1d' out.txt > tmp 
    IFS=$'\n'
    while read tmp 
    do  
    3>results-$tmp perf stat -p $tmp --log-fd 3 sleep 5 > /dev/null &
    done <tmp

为了每1毫秒收集一个进程的统计信息,应该如何编写一个循环?

In order to collect the stats for every 1 milli second for a process, how should a loop be written ?

推荐答案

以这种速率读取性能计数器在开销方面有些困难.这正是perf stat具有下限10 ms个周期的原因.它运行一个用户空间任务,以这些间隔读取计数器.

Reading performance counters at this rate is a bit of a stretch in terms of overhead. That is exactly the reason why perf stat has a lower limit of 10 ms periods. It runs a userspace task for reading the counters in those intervals.

另一方面,perf record将设置性能事件,以便它们在计数器溢出时由内核本身记录.这样做的好处是开销较小,但是不一定必须以定期的时间间隔记录该事件.如果设置perf record --frequency 1000,则内核将调整计数器 trying 的溢出率,以达到请求的1毫秒间隔.除非您的事件发生率真正稳定,否则产生的时间间隔将不会恒定.如果您的事件发生率变化很大,时间间隔也会变化.

On the other hand, perf record will setup the perf events such that they are recorded by the kernel itself on an overflow of the counter. The advantage is that it has less overhead, but the event is not necessarily recorded in regular time intervals. If you set perf record --frequency 1000, the kernel will adapt the overflow rate of the counter trying to achieve the requested 1 millisecond intervals. The resulting time intervals will not be constant unless your event rate is really stable. If your event rate varies greatly, so will the time intervals.

请注意,内核中有一个机制,该机制将试图防止性能造成过多的开销.按照您要求的速率,您可能会击中它.

Note that there is a mechanism in the kernel that will try to prevent perf from causing too much overhead. At your requested rate you will probably hit it.

此外,您不应设置过多的pid记录,而应设置系统范围的记录,例如:

Also you should not setup recording for an excessive amount of pids, instead setup a system-wide recording e.g.:

perf record --all-cpus --timestamp --freq 1000 

您将获得一个可以根据pid处理的结果文件. perf script.除了文本输出外,perf script还允许您使用python或perl处理事件(请参见man perf-script-pythonman perf-script-perl).

You get one result file that you can process according to the pid. perf script. In addition to the text output, perf script allows you to process the events in python or perl (see man perf-script-python, man perf-script-perl).

这篇关于每1毫秒从PMU收集一次有轨车辆过程的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆