I'm trying to understand what the -c and -F options of perf record really do but I cannot explain what I'm seeing. I'm running these commands:
perf record -a -F <frequency> sleep 1
and
perf record -a -c <count> sleep 1
trying different values of frequency and count. The results I get are the following
In the first table I set the frequency and in the second one the count. How do frequency and count affect the number of events? I thought the number of events was independent on the frequency and count, but clearly it's not the case. What does perf actually do?
A perf record command was used to trace the block:block_rq_issue probe, which fires when a block device I/O request is issued (disk I/O). Options included -a to trace all CPUs, and -g to capture call graphs (stack traces). Trace data is written to a perf. data file, and tracing ended when Ctrl-C was hit.
There is builtin perf. data parser and printer in perf tool of linux tools with subcommand "script". perf-script - Read perf. data (created by perf record) and display trace output This command reads the input file and displays the trace recorded.
Perf works on the Model Specific Registers of your CPU for measurements like cycles or branch-misses or so. A special Part called PMU(Performance Measurement Unit) is counting all kinds of events.
The perf tool records events until you terminate it by pressing Control and C (Ctrl+C).
Count
and frequency
are two fundamental switches that tune the rate of sampling when using perf record
(which does sampling internally).
Count
When you run perf record -c <number>
, you are specifying the sample period (where "number" is the sample period). That is, for every "number"th occurrence of the event a sample will be recorded. The sample will be recorded when the performance counter that keeps track of the number of events has overflowed.
I am guessing you are obtaining the number of events with the help of perf report
. Note that perf report
will never report the actual number of events, but only an approximate. The number of events will keep changing as you keep tweaking the sample period. perf report
will only read the perf.data
file that perf record
generates, and based on the size of the file generated, it makes an assumption of the number of samples recorded (by knowing the size of a sample recorded in memory). The actual number of events recorded is obtained by -
Number of events = Fixed Sample Period * Number of samples collected
where Fixed Sample Period is what you specified with perf record -c
.
Frequency
This is the other way around to express the sampling period, that is to specify the average rate of samples per second (frequency) - which you can do using perf record -F. So perf record -F 1000
will record around 1000 samples per second and these samples will be generated when the hardware/PMU counter corresponding to the event overflows. This means that the kernel will dynamically adjust the sampling period to make sure that the sampling
process adheres to the sampling frequency.
This is how the sample period gets updated dynamically.
Higher the sampling frequency, higher the number of samples collected (almost proportionately).
The variation in the sampling period can be seen by running the command -
sudo perf report -D -i perf.data | fgrep RECORD_SAMPLE
Whenever the sampling period keeps varying, the total number of events will keep incrementing with the variation in the sampling period. And when the sampling period remains fixed, the total number of events remain fixed and is obtained by the formula showed above. The total number of events will be approximate in both the cases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With