linux perf record: difference between count (-c) and frequency (-F) options

杀马特。学长 韩版系。学妹 提交于 2020-08-07 09:14:12

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/53449001/linux-perf-record-difference-between-count-c-and-frequency-f-options

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!