对流程执行子集进行性能监控 [英] performance monitoring for subset of process execution

查看:93
本文介绍了对流程执行子集进行性能监控的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算收集Linux应用程序程序执行情况的一小部分的统计信息.该子集可以定义为前n个指令或前n个周期.

I intend to collect the statistics of a linux application for a small subset of its program execution. This subset can be defined as first n instructions, or first n cycles.

对于已定义的子集,我们对诸如分支预测准确性,高速缓存命中率和核心IPC之类的统计数据感兴趣.

For the defined subset, we are interested in statistics like branch prediction accuracy, cache hit-rates, and the IPC of the core.

性能工具似乎是进行此类监视的最佳选择.但是,在perf中指定子集的方法是通过运行提供子集信息的命令.

perf tool looks like the best bet for such monitoring. However, the way to specify a subset in perf is by running a command which gives the subset information.

示例:如果要在最初的n秒内收集数据,则必须运行以下命令.

Example : If I want to collect data for first n seconds, I have to run the following command.

性能统计-p PID睡眠n

在这里,我必须运行该程序,然后使用其PID将perf附加到该程序. 性能监视器将使用pid PID 收集该进程的数据,直到sleep命令运行为止. 但是,从我的程序开始执行到执行该过程所附加的性能,可能已经执行了 x 条指令.由于x是随机的,因此绝对无法知道perf对哪些指令进行了配置.

Here, I have to run the program, and then attach perf to this program using its PID. The perf collects the data for the process with pid PID till the sleep command runs. However, from the time my program started execution, to the time that the perf attached to the process, x number of instructions could have been executed. Since x is random, there is absolutely no way of knowing which instructions were profiled by perf.

我会提供一些建议,使我可以监视程序的执行情况

I would be helpful of suggestions which allow me to monitor the execution of a program

  1. 在头n秒内,或
  2. 从程序执行的确定点开始(某些函数名称或指令指针)

推荐答案

我们使用了一个简单的技巧作为解决此问题的方法.

We used a simple hack as a workaround for this problem.

让我们将被监视程序称为M,x秒是需要收集性能统计信息的时间.

Let us call the monitored program M, and x seconds is the time for which the performance statistics need to be collected.

我们编写了一个程序P,该程序分叉M,然后睡眠x秒.从睡眠中醒来之后,程序P杀死了自己及其所有后代.

We wrote a program P, which forks M, and then sleeps for x seconds. After waking up from sleep, program P kills itself and all its descendants.

if(fork()!=0)
then
     sleep x seconds
     kill me
else
     execute monitored program
endif

在程序P上运行perf(性能收集实用程序).统计信息反映了程序P和M的特征.由于程序P没有做任何繁重的操作,因此不会对性能统计数据产生太大影响.

Run perf (performance collection utility) on program P. The statistics reflect the characteristics of program P and M. Since program P is not doing any heavy operation, it won't affect the performance statistics much.

必须注意,程序的监视持续时间必须足够长,以使程序P的统计数据蒙上阴影.

It must be noted that the monitoring duration of the program must be large enough to overshadow the statistics of the program P.

这篇关于对流程执行子集进行性能监控的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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