2

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.

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

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.

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

perf stat -p PID sleep n

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. for the first n seconds, or
  2. from a determined point in the program execution (some function name or instruction pointer)
prathmesh.kallurkar
  • 5,468
  • 8
  • 39
  • 50

1 Answers1

1

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

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

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

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.

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

prathmesh.kallurkar
  • 5,468
  • 8
  • 39
  • 50