LIBPFM(3)
LIBPFM(3) β the Linux Programmer's Manual, but make it cute π
okay bestie, sit down, hydrate, and let me tell you about pfm_find_event β she's a libpfm girlie and she's here to turn your little event strings into actual event identifiers. no cap. β¨
πΈ NAME πΈ
pfm_find_event β search for an event masks π
π SYNOPSIS π
#include <perfmon/pfmlib.h>
int pfm_find_event(const char *str);
π¦ DESCRIPTION π¦
So basically? This function takes the event string you shoved into str and converts it into an opaque event identifier, which is literally just the return value. that's the whole job. she ate. π
Events start their life as strings β they hold the event name, the sub-event names, and any optional filters and modifiers. This function reads that string and goes looking for the matching event. fr fr. π
The event string is a structured string, and it's built like this:
[pmu_name::]event_name[:unit_mask][:modifier|:modifier=val]
All the little pieces get separated by : or ::, and here's what each one actually means:
pmu_nameβ this is an optional prefix that says "hey, use this specific PMU model". With the prefix, the event matchingevent_nameis the one that gets used. And here's the tea: when multiple PMU models are activated, identical event names can conflict β they might mean the same thing, or they might mean totally different things. π When that happens, you have to fully specify the event with apmu_name. That string corresponds to whateverpfm_get_pmu_name()hands back.event_nameβ the event name, and it's required, no skipping. The library is not case sensitive on event strings, so don't stress the caps. But heads up: the event name must match the actual event name completely β it cannot be a substring. no partial credit, bestie. πunit_maskβ optional, and you can think of it like a sub-event of the major event. If an event has unit masks and there's no default, then you must pass at least one unit mask in the string. Also, multiple unit masks may be specified for a single event. the more the merrier honestly. π«Άmodifierβ an optional filter, provided either by the hardware register hosting the event or by the underlying kernel infrastructure. Typical modifiers include privilege level filters. Some modifiers are simple booleans, in which case just passing their names is the same as setting their value totrue. Other modifiers need a specific value, and that value goes after the equal sign. > π¨ No space is tolerated around the equal sign. none. zero. don't do it. π¨ The list of modifiers depends on the host PMU and the underlying kernel API, and they're documented in PMU-specific documentation. Multiple modifiers may be passed, and there is no order between unit masks and modifiers β they can vibe in whatever order they want.
The library uses the generic term attribute to mean both unit masks and modifiers. one word, two jobs, iconic.
β¨ examples, because we love a visual β¨
amd64::RETIRED_INSTRUCTIONS:u
Event RETIRED_INSTRUCTION on AMD64 processor, measured at user privilege level only. π
RS_UOPS_DISPATCHED:c=1:i:u
Event RS_UOPS_DISPATCHED measured at user privilege level only, and with counter-mask set to 1.
π§ the fine print, but make it friendly π§
For the purpose of this function, only the pmu_name and event_name are actually considered. Everything else is parsed β so it has to be valid β but it gets ignored. parsed and then ghosted, honestly. π»
And the function searches for only one event per call. As a convenience, it'll identify the event up to the first comma. In other words, if str is equal to "EVENTA,EVENTB", then the function will only look at EVENTA and will not return an error because of an invalid event string. Super handy when you're parsing constant event strings containing multiple, comma-separated, events. main character energy tbh. π
π RETURN π
She returns the opaque event identifier that corresponds to the event string. And if something goes wrong? A negative error code comes back instead. sad girl hours. π
π ERRORS π
PFMLIB_ERR_NOINITβ the library has not been initialized properly. she wasn't ready. πPFMLIB_ERR_INVALβ the event string isNULL.PFMLIB_ERR_NOMEMβ the library ran out of memory.PFMLIB_ERR_NOTFOUNDβ the event was not found. gone. vanished. πPFMLIB_ERR_ATTRβ invalid event attributePFMLIB_ERR_ATTR_VALβ invalid event attribute valuePFMLIB_ERR_TOOMANYβ too many event attributes passed
π AUTHOR π
Stephane Eranian <eranian@gmail.com> β legend behavior, honestly. π«Ά
okay that's the whole page, bestie!! this was LIBPFM(3), from the Linux Programmer's Manual, and it's dated September, 2009. go forth and find your events πβ¨πΈπ¦
π¦ where this page comes from
- arch rolling: libpfm 4.14.1-1 Β· MIT
- centos-stream 10: libpfm-devel 4.14.1-1.el10 Β· MIT
- centos-stream 9: libpfm-devel 4.14.1-1.el9 Β· MIT
- centos-stream 9: libpfm-devel 4.14.1-1.el9 Β· MIT
- debian bookworm: libpfm4-dev 4.13.0-1 Β· MIT
- debian trixie: libpfm4-dev 4.13.0+git99-gc5587f9-1 Β· MIT
- fedora 43: libpfm-devel 4.13.0-16.fc43 Β· MIT
- fedora 43: libpfm-devel 4.13.0-16.fc43 Β· MIT
- fedora 43: libpfm-devel 4.13.0-20.fc43
- fedora 43: libpfm-devel 4.13.0-20.fc43
- fedora 43: libpfm-devel 4.14.1-2.fc43 Β· MIT
- fedora 43: libpfm-devel 4.14.1-2.fc43 Β· MIT
- fedora 44: libpfm-devel 4.13.0-19.fc44 Β· MIT
- fedora 44: libpfm-devel 4.13.0-19.fc44 Β· MIT
- fedora 44: libpfm-devel 4.13.0-20.fc44
- fedora 44: libpfm-devel 4.13.0-20.fc44
- fedora 44: libpfm-devel 4.14.1-2.fc44 Β· MIT
- fedora 44: libpfm-devel 4.14.1-2.fc44 Β· MIT
- nixos 26.05: libpfm 4.13.0
- nixos 26.05: papi 7.2.0
- nixpkgs unstable: libpfm 4.14.1
- nixpkgs unstable: papi 7.2.0
- opensuse-leap 16.0: libpfm-devel 4.13.0-160000.3.1 Β· MIT
- opensuse-leap 16.0: libpfm-devel 4.13.0-160000.3.1 Β· MIT
- opensuse-leap 16.0: libpfm-devel 4.13.0-160000.3.1 Β· MIT
- opensuse-leap 16.0: libpfm-devel 4.13.0-160000.3.1 Β· MIT
- ubuntu jammy: libpfm4-dev 4.11.1+git32-gd0b85fb-1 Β· BSD-like
- ubuntu jammy: libpfm4-dev 4.11.1+git32-gd0b85fb-1ubuntu0.1 Β· BSD-like
- ubuntu noble: libpfm4-dev 4.13.0+git32-g0d4ed0e-1 Β· MIT
- ubuntu noble: libpfm4-dev 4.13.0+git32-g0d4ed0e-1ubuntu0.1 Β· MIT
- ubuntu questing: libpfm4-dev 4.13.0+git99-gc5587f9-1
- ubuntu resolute: libpfm4-dev 4.13.0+git106-g3e4031b-1 Β· MIT
- ubuntu resolute: libpfm4-dev 4.13.0+git106-g3e4031b-1ubuntu0.1 Β· MIT
- ubuntu stonking: libpfm4-dev 4.13.0+git106-g3e4031b-1ubuntu1 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms