1LIBPFM(3) Linux Programmer's Manual LIBPFM(3)
2
3
4
6 pfm_get_event_next - iterate over events
7
9 #include <perfmon/pfmlib.h>
10
11 int pfm_get_event_next(int idx);
12
13
15 Events are uniquely identified with opaque integer identifiers. There
16 is no guaranteed order within identifiers. Thus, to list all the
17 events, it is necessary to use iterators.
18
19 Events are grouped in tables within the library. A table usually corre‐
20 sponds to a PMU model or family. The library contains support for mul‐
21 tiple PMU models, thus it has multiple tables. Based on the host hard‐
22 ware and software environments, tables get activated when the library
23 is initialized via pfm_initialize(). Events from activated tables are
24 called active events. Events from non-activated tables are called sup‐
25 ported events.
26
27 Event identifiers are usually retrieved via pfm_find_event() or when
28 encoding events.
29
30 To iterate over a list of events for a given PMU model, all that is
31 needed is an initial identifier for the PMU. The first event identifier
32 is usually obtained via pfm_get_pmu_info().
33
34 The pfm_get_event_next() function returns the identifier of next sup‐
35 ported event after the one passed in idx. This iterator stops when the
36 last event for the PMU is passed as argument, in which case the func‐
37 tion returns -1.
38
39 void list_pmu_events(pfm_pmu_t pmu)
40 {
41 struct pfm_event_info info;
42 struct pfm_pmu_info pinfo;
43 int i, ret;
44
45 memset(&info, 0, sizeof(info));
46 memset(&pinfo, 0, sizeof(pinfo));
47
48 info.size = sizeof(info);
49 pinfo.size = sizeof(pinfo);
50
51 ret = pfm_get_pmu_info(pmu, &pinfo);
52 if (ret != PFM_SUCCESS)
53 errx(1, "cannot get pmu info");
54
55 for (i = pinfo.first_event; i != -1; i = pfm_get_event_next(i)) {
56 ret = pfm_get_event_info(i, &info);
57 if (ret != PFM_SUCCESS)
58 errx(1, "cannot get event info");
59
60 printf("%s Event: %s::%s\n",
61 pinfo.present ? "Active" : "Supported",
62 pinfo.name, info.name);
63 }
64 }
65
66
68 The function returns the identifier of the next supported event. It
69 returns -1 when the argument is already the last event for the PMU.
70
71
73 No error code, besides -1, is returned by this function.
74
76 pfm_find_event(3)
77
79 Stephane Eranian <eranian@gmail.com>
80
81 September, 2009 LIBPFM(3)