AN00
AN00

Reputation: 335

What does perf record -P do?

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?

Upvotes: 3

Views: 2540

Answers (3)

Arnabjyoti Kalita
Arnabjyoti Kalita

Reputation: 2431

@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.

Upvotes: 2

Lekensteyn
Lekensteyn

Reputation: 66485

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.

Upvotes: 1

Jakuje
Jakuje

Reputation: 26006

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.

Upvotes: 0

Related Questions