3

I have tried the command perf record and then perf record -P, which is supposed to allow me to specify the sample period, but it does not work. The result of perf record -P is the same as the one obtained from perf record.

So what does perf record -P do in fact?

AN00
  • 325
  • 4
  • 13

3 Answers3

2

@Alina,

If you read the man page for perf record, you can see that perf record -P will be used to record the sample period, and not specify it.

If you want to record more/less samples and modify the period, you have to specify the command like perf record -c 2 (--count=) where 2 is the sampling period. This will mean that for every 2 occurrences of the event that you are measuring, you will have a sample for that. You can then modify the sampling period and test various values.

The other way around to express the sampling period, 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.

osgx
  • 90,338
  • 53
  • 357
  • 513
Arnabjyoti Kalita
  • 2,325
  • 1
  • 18
  • 31
  • `perf record -C` is not sample period, it is `--cpu` for selecting cpu to profile: http://man7.org/linux/man-pages/man1/perf-record.1.html "*`-C, --cpu` Collect samples only on the list of CPUs provided. Multiple CPUs can be provided as a comma-separated list with no space: `0,1`*". Probably you mean `-c` (small c) - "*`-c, --count=` Event period to sample.*" with bigger numbers like 1000 or 10000 or 100000. There is also `-F` for frequency, but only `-c` will set exact period sample value, and `-F` will tune actual event overflow count to generate around the frequency. – osgx May 23 '17 at 02:29
  • Hi @osgx, I meant -c only, not -C , which as you said is for cpu. – Arnabjyoti Kalita May 23 '17 at 04:50
1

The sampling period can be specified with the -c option, though there is also a -F option to specify the sampling frequency. The defaults are 1000 samples/sec or 1000Hz according to the perf wiki:

Period and rate

The perf_events interface allows two modes to express the sampling period:

  • the number of occurrences of the event (period)
  • the average rate of samples/sec (frequency)

The perf tool defaults to the average rate. It is set to 1000Hz, or 1000 samples/sec. That means that the kernel is dynamically adjusting the sampling period to achieve the target average rate. The adjustment in period is reported in the raw profile data. In contrast, with the other mode, the sampling period is set by the user and does not vary between samples. There is currently no support for sampling period randomization.

As for what the -P option is doing, the commit message for perf (and the related kernel patch) contains some background. If I interpret it correctly, the option means that for efficiency reasons many equal samples can be merged into a single event that also contains the sample period. The original intent is to reduce the number of generated samples to avoid hitting a "rate limit" that would result in lost samples.

Lekensteyn
  • 64,486
  • 22
  • 159
  • 192
0

From manual page for perf record:

-P, --period

Record the sample period.

The perf documentation is classically short and not saying anything important. Certainly it does not allow you to add an argument. Reading through the code does not give any better idea what this option can be for.

Community
  • 1
  • 1
Jakuje
  • 24,773
  • 12
  • 69
  • 75
  • Yes, I understand that it records the sample period, but what is this sample period? How long is it? And if possible, how can I change it? – AN00 Aug 02 '16 at 20:07