LIBPFM(3)
π LIBPFM(3) π
okay bestie, welcome to the Linux Programmer's Manual page for LIBPFM(3) β yes the whole libpfm situation β and today we're hyperfixating on exactly one function. sit down, grab a strawberry drink π, and let's get into it.
β¨ NAME β¨
pfm_get_event_info β bestie, it gets you event information. that's the whole job. she's focused, she's employed, she's serving.
π¦ SYNOPSIS π¦
#include <perfmon/pfmlib.h>
int pfm_get_event_info(int idx, pfm_os_t os, pfm_event_info_t *info);
look at her. three args. no notes. π
πΈ DESCRIPTION πΈ
so this function drops info about one specific event into info. which event? the one with that opaque, unique little identifier idx β and it's for the operating system you name in os. that's it, that's the vibe check. β¨
the pfm_event_info_t structure is defined like this, and bestie I am copying this character for character, do not come for me:
typedef struct {
const char *name;
const char *desc;
const char *equiv;
size_t size;
uint64_t code;
pfm_pmu_t pmu;
pfm_dtype_t dtype
int idx;
int nattrs;
struct {
unsigned int is_precise:1;
unsigned int reserved_bits:31;
};
} pfm_event_info_t;
and now, the fields, one by one, no skips, no skimming, we read here π:
nameβ the name of the event. it's a read-only string. hands off, she's not yours to edit.descβ the description of the event. also read-only. it can have multiple sentences in it, so she's a talker, we love that for her.equivβ okay so some events are literally just variations of actual events, offered as handy lil shortcuts so you don't have to type out a long list of attributes. for those events this field is notNULLand it holds the complete equivalent event string. iykyk.codeβ the raw event code. do not confuse this with the encoding of the event, bestie, that's a different thing. this field is only the event selection code β no unit mask, no attribute settings, none of that. just the code.pmuβ which PMU model this event belongs to. it's of typepfm_pmu_t. and if you take this value plus thepfm_get_pmu_infofunction, you can get PMU information. combo move π₯.dtypeβ this field returns the representation of the event data. by default it'sPFM_DATA_UINT64.idxβ the event's unique opaque identifier. it's identical to theidxyou passed in, and it's there for completeness. she's showing up to be thorough, periodt.nattrsβ how many attributes this event supports. attributes can be unit masks or modifiers. if the event has no attribute at all, this field is just0. simple as that.sizeβ the size of the struct you passed in. this field exists so the struct can be extended without breaking backward compatibility, which is honestly iconic engineering behavior π. you should set it tosizeof(pfm_event_info_t). but if you pass0instead, the library assumes the struct you handed over is identical to the first ABI version, whose size isPFM_EVENT_INFO_ABI0. so if fields got added after that first ABI, the library will not set them. and yes, the library does check that bytes beyond what's implemented are zeroes. she verifies. she's meticulous. πis_preciseβ this bitfield says whether or not the event supports precise sampling. precise sampling is a hardware mechanism that avoids instruction address skid when you're using interrupt-based sampling. when the event has umasks, this field means at least one umask supports precise sampling. on Intel X86 processors, this tells you whether the event supports Precise Event-Based Sampling, aka PEBS. π hardware lore.is_speculativeβ this bitfield says whether or not the event includes occurrences happening during speculative execution, for both the wrong and correct path. and because this kind of event info isn't always available from vendors, this field uses multiple bits:PFM_EVENT_INFO_SPEC_NAβ speculation info is not available. π€·PFM_EVENT_INFO_SPEC_TRUEβ the event does count during speculative execution.PFM_EVENT_INFO_SPEC_FALSβ the event does not count during speculative execution.
π the pfm_os_t enumeration π
she gives you these choices, pick your fighter:
PFM_OS_NONEβ what you get back pertains only to what the PMU hardware exports. no operating system attributes are taken into account. raw. unfiltered. au naturel.PFM_OS_PERF_EVENTβ what you get back includes the actual PMU hardware plus the extra attributes exported by theperf_eventskernel interface. thoseperf_eventattributes pertain only to the PMU hardware. and heads up: ifperf_eventsisn't detected, you get an error back. π¨PFM_OS_PERF_EVENT_EXTβ everythingPFM_OS_PERF_EVENTalready gives you, plus all the software attributes controlled byperf_events, like sampling period and precise sampling. the deluxe edition π.
β RETURN β
if it works, the function returns PFM_SUCCESS and the event information lands in info. if not, you get an error code. no in-between, she doesn't do ambiguity.
π ERRORS π
PFMLIB_ERR_NOINITβ the library has not been initialized properly. she woke up and nobody set her up. πPFMLIB_ERR_INVALβ theidxargument is invalid, orinfoisNULL, orsizeis not zero.PFMLIB_ERR_NOTSUPPβ theosyou requested is not detected or supported. not on the menu, bestie.
π«Ά AUTHOR π«Ά
Stephane Eranian <eranian@gmail.com>
okay that's the whole page, you absolutely ate this read π go forth and query your events responsibly.
mwah π this was the Linux Programmer's Manual, LIBPFM(3), dated December, 2009 β and that's the sign-off, bestie, love u, bye πβ¨π¦
π¦ 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