【问题标题】:Using the perf events from perf list programatically以编程方式使用 perf 列表中的 perf 事件
【发布时间】:2020-12-18 13:06:18
【问题描述】:

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

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

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

【问题讨论】:

  • 性能列表有几个事件集,检查perf list -h:hw|sw|cache|tracepoint|pmu|sdt|event_glob。大多数事件来自缓存和 pmu 集。您可以从mirrors.edge.kernel.org/pub/linux/kernel/tools/perf 下载性能源并检查函数cmd_list from builtin-list.c file,然后打印_pmu_events。有些是从 /sys/bus/event_source/devices/cpu/events 扫描的,有些是从文件 pmu-events/pmu-events.c 的内部列表中打印出来的

标签: linux performance perf intel-pmu


【解决方案1】:

如果不使用第三方(或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-eventsthere is readme file,其中指出 perf 使用 jevents(perf 有 8 MB x86 json 事件列表,tools/perf/pmu-events/arch/x86)

此目录的内容允许用户在他们的 CPU 按其符号名称而不是原始事件代码(参见下面的示例)。 此目录中的主程序是“jevents”,它是构建和 执行 BEFORE 构建 perf 二进制文件本身。 “jevents”程序尝试在目录中定位和处理 JSON 文件 树工具/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_events_map (pmu-events/pmu-events.c) 中检测到的 perf_pmu__find_map (util/pmu.c) 从 pmu_add_cpu_aliases 调用,从 pmu_lookup 调用,从 perf_pmu__find,从 perf_pmu__scan 从 cmd_list 的 print_pmu_events (perf list 内置命令的处理程序)。

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

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

【讨论】:

    猜你喜欢
    • 2022-01-15
    • 2017-06-29
    • 2019-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-17
    • 2020-07-22
    • 2020-09-07
    相关资源
    最近更新 更多