1

I want to do something like this: After 100 million instructions have passed, query the Linux perf HW CPU cycles and record it in a file. I want to use this code to characterize the performance of applications/benchmark programs during different phases of program execution.

I have a hint that I need to setup Intel PEBS which overflows after 100 million instructions have passed and query the linux perf counters HW cpu cycles counter.

Any pointer on where to start and if someone has already done that. I want to do this in a low overhead manner. I will write the code in C/C++.

Regards...

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • That's what perf does. Where is the issue? Yes 100 millions is too much, just make it smaller. – Matthieu Brucher Feb 13 '19 at 16:17
  • So a program is running, which may have 1000 billions instructions. But I want that after every 100 million instructions, the number of cpu cycles passed to execute that 100 million instructions be recorded in a file. This is the problem. – user3591871 Feb 13 '19 at 16:32
  • Don't use 100 million, use less. Any internal hardware counter could have overflown, especially the cycle one. That's why profilers use far less increments, usually lower than 1 million. And they are low overhead. – Matthieu Brucher Feb 13 '19 at 16:34
  • You can use `perf record -e instructions:u -c 100000000` to capture a sample every 100M instructions. Then you can see the timestamps using `perf script -F time`, but they are in microseconds, not cycles. @MatthieuBrucher – Hadi Brais Feb 14 '19 at 12:30
  • Well, you can specify what hardware counter to save as well, so you can get cycles. – Matthieu Brucher Feb 14 '19 at 14:16
  • @MatthieuBrucher How to do that exactly? – Hadi Brais Feb 14 '19 at 15:11
  • You add `cycles` to the `-e` argument. Then maybe perf is not the best, I'm more used to PAPI which can use several counters at the same time, but still uses perf underneath. – Matthieu Brucher Feb 14 '19 at 15:14
  • @MatthieuBrucher But then if you add both `instructions` and `cycles` to the -e argument, the threshold specified to the -c argument would apply to both counters I think, not just the instruction counter. The OP is asking how to set a threshold on the instructions counter but also include the cycles counter in every sample (when the number of instructions reaches 100M). – Hadi Brais Feb 14 '19 at 15:54
  • 2
    Does https://stackoverflow.com/q/54781746/620382 (In your case `perf record -c 100000000 -e '{instructions,cycles}:S'`) work for you? Then I would suggest to close as duplicate. – Zulan Feb 21 '19 at 15:59

0 Answers0