gpt4 book ai didi

linux - 以编程方式使用性能列表中的性能事件

转载 作者:行者123 更新时间:2023-12-03 10:00:21 27 4
gpt4 key购买 nike

当我在我的 Linux 系统上运行 perf list 时,我得到了一长串可用的性能事件。

是否可以使用 perf_event_open(2) 从另一个进程以编程方式列出和使用这些事件? ?也就是说,我如何从另一个进程获取此列表并确定要填充到 perf_event_attr 中的相应值?

我不是在寻找使用另一个第三方事件列表的解决方案,例如。 libpfm4 或 jevents。我知道可以从 /sys/devices/cpu/events/ 中的文件(以及其他事件类型的类似文件)中重建一些事件,但这些只是 中事件的一小部分perf list 显示。

最佳答案

没有解决方案可以在不使用第三方(或 first party)列表的情况下从内核(使用任何系统调用,如 perf_event_open(2))获取原始事件的完整列表。 Perf 工具使用从 /sys/bus/event_source/devices/cpu/events 和类似的 sysfs 文件夹扫描的一些基本事件,但它有自己的 cpu 型号特定事件列表:https://elixir.bootlin.com/linux/v5.5.19/source/tools/perf/pmu-events , 和 there is readme file perf 使用哪些点 jevents (perf 有 8 MB 的 x86 json 事件列表,位于 tools/perf/pmu-events/arch/x86 )

The contents of this directory allow users to specify PMU events in theirCPUs by their symbolic names rather than raw event codes (see example below).The main program in this directory, is the 'jevents', which is built andexecuted BEFORE the perf binary itself is built.The 'jevents' program tries to locate and process JSON files in the directorytree tools/perf/pmu-events/arch/foo.

您可以从 https://mirrors.edge.kernel.org/pub/linux/kernel/tools/perf/ 下载 perf 源并使用一些源代码导航工具来检查 cmd_list 函数 builtin-list.c 文件(带有一些未记录的选项)。您还可以从这些来源构建 perf 工具,并且将在 perf 早期编译 jevents(HOSTCC pmu-events/jevents.oLINK pmu-events/jevents)建筑。

当前 cpu 模型是通过从 pmu_add_cpu_aliases 调用的 perf_pmu__find_map (util/pmu.c) 从表 pmu_events_map (pmu-events/pmu-events.c) 中检测到的,调用自 pmu_lookup ,来自 perf_pmu__find,来自 perf_pmu__scan 来自 print_pmu_events 来自 cmd_list(perf list 内置命令的处理程序)。

截至5.5 version of perf (来自 linux 内核 5.5,因为 perf 是 linux 内核的一部分),没有带有描述的事件列表的原始转储。有一个未记录的选项 perf list --raw-dump 它将打印每个可用监控单元的所有事件列表,例如 pmu:perf list --原始转储 pmu |tr ' ' '\n'。此原始转储的输出在 perf 版本之间不稳定。

perf_events 子系统的内核部分在 arch/x86/events 中没有完整的事件列表或 kernel/events文件夹,仅将标准 perf 事件(在 sysfs 中列出)如周期或 cpu/branch-misses/映射到特定 cpu 模型的原始事件。

关于linux - 以编程方式使用性能列表中的性能事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63653406/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com