linux perf 记录:计数(-c)和频率(-F)选项之间的差异 [英] linux perf record: difference between count (-c) and frequency (-F) options

查看:16
本文介绍了linux perf 记录:计数(-c)和频率(-F)选项之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解 perf record 的 -c 和 -F 选项的真正作用,但我无法解释我所看到的.我正在运行这些命令:

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

perf record -a -c <count> sleep 1

尝试频率计数的不同值.我得到的结果是以下

trying different values of frequency and count. The results I get are the following

在第一个表中我设置了频率,在第二个表中设置了计数.频率和计数如何影响事件的数量?我认为事件的数量与频率和计数无关,但显然事实并非如此.perf 实际上有什么作用?

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?

推荐答案

Countfrequency 是使用 perf 时调整采样率的两个基本开关记录(在内部进行采样).

Count and frequency are two fundamental switches that tune the rate of sampling when using perf record (which does sampling internally).

计数

当您运行 perf record -c 时,您指定了采样周期(其中number"是采样周期).也就是说,对于事件的每个第"次出现,将记录一个样本.当跟踪事件数量的性能计数器溢出时,将记录样本.

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.

我猜您是在 perf report 的帮助下获取事件数量的.请注意,perf report 永远不会报告实际的事件数量,而只是一个近似值.随着您不断调整采样周期,事件数量将不断变化.perf report 只会读取perf record 生成的perf.data 文件,并根据生成的文件的大小进行假设记录的样本数量(通过了解内存中记录的样本大小).实际记录的事件数通过-

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 -

事件数 = 固定采样周期 * 采集的样本数

其中固定采样周期是您使用 perf record -c 指定的时间.

where Fixed Sample Period is what you specified with perf record -c.

频率

这是表示采样周期的另一种方式,即指定每秒采样的平均速率(频率)——您可以使用 perf record -F 来实现.所以 perf record -F 1000 每秒将记录大约 1000 个样本,这些样本将在对应于事件的硬件/PMU 计数器溢出时生成.这意味着内核会动态调整采样周期,以确保采样过程符合采样频率.

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.

这是采样周期会动态更新.

采样频率越高,收集的样本数量越多(几乎成比例).

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.

这篇关于linux perf 记录:计数(-c)和频率(-F)选项之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆