performance - 采样率对性能的性能影响 - 更高的采样率在 NXP S32 上花费*更少*开销?
问题描述
我在采样模式下使用 perf 从运行 Linux 4.19 的 NXP S32 平台捕获在多核平台上运行的程序的性能统计数据。
例如配置
核心 0 - App0,核心 1 - App1,核心 2 - App2
没有采样,即在程序级别,App0 需要 6.9 秒。
以 100 万个周期采样时,App0 需要 6.3 秒
在 200 万个周期采样时,App0 需要 6.4 秒
在 500 万个周期采样时,App0 需要 6.5 秒
在 1 亿次循环采样时,App0 需要 6.8 秒。
正如您所看到的,随着采样周期的增加(1 亿次),App0 需要更长的时间来完成执行。
实际上,我会预料到相反的情况,即与 1 亿个周期相比,由于生成的样本数量(性能开销)更高,因此以 100 万个周期进行采样应该会导致程序花费更多的时间来执行?
我无法解释这种行为,您认为是什么原因造成的?
任何线索都会有所帮助。
PS - 在 Pi3B 上,行为与预期一致,即与 1 亿个周期相比,以 100 万个周期进行采样会导致执行时间更长。
更新:我不使用命令行中的 perf,而是使用perf event
带有以下标志的struct perf_event_attr
.
struct perf_event_attr hw_event;
pid_t pid = proccess_id; // measure the current process/thread
int cpu = -1; // measure on any cpu
unsigned long flags = 0;
int fd_current;
memset(&hw_event, 0, sizeof(struct perf_event_attr));
hw_event.type = event_type;
hw_event.size = sizeof(struct perf_event_attr);
hw_event.config = event;
if(group_fd == -1)
{
hw_event.sample_period = 2000000;
hw_event.sample_type = PERF_SAMPLE_READ;
hw_event.precise_ip = 1;
}
hw_event.disabled = 1; // off by default. specifies whether the counter starts out disabled or enabled.
hw_event.exclude_kernel = 0; // excluding events that happen in the kernel-space
hw_event.exclude_hv = 1; // excluding events that happen in the hypervisor
hw_event.pinned = pinned; // specifies the counter to be on the CPU if at all possible. applies only to hardware counters and only to group leaders.
hw_event.exclude_user = 0; // excludes events that happen in user space
hw_event.exclude_callchain_kernel = 0; // Do not include kernel callchains.
hw_event.exclude_callchain_user = 0; // Do not include user callchains.
hw_event.read_format = PERF_FORMAT_GROUP; // Allows all counter values in an event group to be read with one read
fd_current = syscall(__NR_perf_event_open, &hw_event, pid, cpu, group_fd, flags);
if (fd_current == -1) {
printf("Error opening leader %llx\n", hw_event.config);
exit(EXIT_FAILURE);
}
return fd_current;
解决方案
推荐阅读
- ios - 从 Mac 读取 iPhone 日志文件内容
- powershell - 如何使用调整后的设置在 /silent 模式下运行安装
- angular - 如何将 Angular 6 部署到 Azure Web App - 您没有权限
- xml - 通过匹配标签值删除xml中的前/后行
- ios - 如何使用 Firestore 中的集合和子集合在数组中创建数组?
- java - 调用访问器方法的方法可以是访问器方法吗
- java - 制作字符串所需的旋转次数
- c# - 获取蓝牙 COM 端口
- php - 为什么自定义 404 PHP 错误页面仅适用于涉及不存在目录的 URL,无论文件是否存在?
- ios - 如何检查我的联系人列表成员是否像 whatsapp 一样在我的应用程序中注册?