I am confused about the difference between perf record
and perf stat
when it comes to counting events like page-faults, cache-misses and anything else from perf list
. I have 2 questions below the answer to "Question 1" might also help answer "Question 2" but I wrote them out explicitly in the case that it doesn't.
Question 1:
It is my understanding that perf stat
gets a "summary" of counts but when used with the -I option gets the counts at the specified millisecond interval. With this option does it sum up the counts over the interval or get the average over the interval, or something else entirely? I assume it is summed up. The perf wiki states it is aggregated but I guess that could mean either.
Question 2:
Why doesn't perf stat -e <event1> -I 1000 sleep 5
give about the same counts as if I summed up the counts over each second for the following command perf record -e <event1> -F 1000 sleep 5
?
For example if I use "page-faults" as the event for event1 I get the following outputs I have listed below under each command. (I am assuming the period field is the counts for the event in perf record
's perf.data file)
PERF STAT
perf stat -e page-faults -I 1000 sleep 5
# time counts unit events
1.000252928 54 page-faults
2.000498389 <not counted> page-faults
3.000569957 <not counted> page-faults
4.000659987 <not counted> page-faults
5.000837864 2 page-faults
PERF RECORD
perf record -e page-faults -F 1000 sleep 5
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.016 MB perf.data (6 samples) ]
perf script -F period
1
1
1
5
38
164
I expected that if I summed up the counts from perf stat
I would get the same as the sum from perf record
. If I use the -c option with perf record
and give an argument of 1 I do get a close match. Is this just a coincidence because of the relatively low number of page faults?
References I have used so far:
- brendangregg's perf blog
- The perf record and stat links on this page mentioned above as "perf wiki"
- I dug around here to see how and when perf record actually records vs when it writes to perf.data.
Thanks in advance for any and all insight you can provide.
-I
interval forperf stat
will give more counts, for anything that happens at a steady rate (likecycles
). – Peter Cordes