LIBPFM(3)
π LIBPFM(3) β Linux Programmer's Manual π
okay bestie, sit down, hydrate, because we're talking about libpfm β yes the perfmon library, yes it's iconic, yes it lives in the Linux Programmer's Manual, and yes I'm about to make event iteration sound like the slay that it is. π
β¨ NAME β¨
pfm_get_event_next β literally just iterate over events, that's the whole job, she's a one-trick pony and the trick is flawless π¦
πΈ SYNOPSIS πΈ
#include <perfmon/pfmlib.h>
int pfm_get_event_next(int idx);
π DESCRIPTION π
okay so here's the tea. Events are uniquely identified with opaque integer identifiers. And the way those identifiers are numbered? There is no guaranteed order within them. None. Zero. Not a vibe you can rely on. π So if you wanna list all the events, you literally have to use iterators. That's not optional, that's the whole method.
Events are grouped into tables inside the library. A table usually corresponds to one PMU model or family. And because the library supports multiple PMU models, it obviously has multiple tables, like a little closet of tables. π
Based on the host hardware and software environments, tables get activated when the library is initialized via pfm_initialize(). So:
- events from activated tables are called active events β¨
- events from non-activated tables are called supported events β¨
Event identifiers are usually retrieved via pfm_find_event() or when encoding events. iykyk.
Now, to iterate over a list of events for a given PMU model, all you need is an initial identifier for that PMU. The first event identifier is usually obtained via pfm_get_pmu_info(). That's your entry point, bestie, your little doorway. πͺ
And pfm_get_event_next()? She returns the identifier of the next supported event after the one you passed in idx. And the iterator stops when the last event for the PMU is passed as the argument β in which case the function returns -1. That's it. That's the finish line. π
void list_pmu_events(pfm_pmu_t pmu)
{
struct pfm_event_info info;
struct pfm_pmu_info pinfo;
int i, ret;
memset(&info, 0, sizeof(info));
memset(&pinfo, 0, sizeof(pinfo));
info.size = sizeof(info);
pinfo.size = sizeof(pinfo);
ret = pfm_get_pmu_info(pmu, &pinfo);
if (ret != PFM_SUCCESS)
errx(1, "cannot get pmu info");
for (i = pinfo.first_event; i != -1; i = pfm_get_event_next(i)) {
ret = pfm_get_event_info(i, &info);
if (ret != PFM_SUCCESS)
errx(1, "cannot get event info");
printf("%s Event: %s::%s\n",
pinfo.present ? "Active" : "Supported",
pinfo.name, info.name);
}
}
look at that loop, she's gorgeous, she ate and left no crumbs. π
π«Ά RETURN π«Ά
The function returns the identifier of the next supported event. And she returns -1 when the argument is already the last event for the PMU. So -1 is not an error here, bestie, it's just the "we're done, go home" signal. π
π ERRORS π
No error code, besides -1, is returned by this function. That's the whole section. Short, sweet, no drama, no extra error codes hiding in the walls. periodt. π
π SEE ALSO π
π AUTHOR π
Stephane Eranian <eranian@gmail.com> β the icon, the legend, the moment. π
quick vibe check reminder: identifiers have no guaranteed order, so don't you dare assume the numbers go up nicely. always iterate, never guess. π§
okay that's the whole page, you're officially a pfm_get_event_next() girlie now. π
this lil masterpiece comes to you from September, 2009, straight out of the Linux Programmer's Manual, filed under LIBPFM(3) β mwah, bye bestie, go iterate something. π¦πΈβ¨
π¦ 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