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
- for the first n seconds, or
- from a determined point in the program execution (some function name or instruction pointer)