Blame src/libpfm4/docs/man3/pfm_get_event_next.3

Packit Service a1973e
.TH LIBPFM 3  "September, 2009" "" "Linux Programmer's Manual"
Packit Service a1973e
.SH NAME
Packit Service a1973e
pfm_get_event_next \- iterate over events
Packit Service a1973e
.SH SYNOPSIS
Packit Service a1973e
.nf
Packit Service a1973e
.B #include <perfmon/pfmlib.h>
Packit Service a1973e
.sp
Packit Service a1973e
.BI "int pfm_get_event_next(int "idx ");"
Packit Service a1973e
.sp
Packit Service a1973e
.SH DESCRIPTION
Packit Service a1973e
Events are uniquely identified with opaque integer identifiers.
Packit Service a1973e
There is no guaranteed order within identifiers. Thus, to list 
Packit Service a1973e
all the events, it is necessary to use iterators.
Packit Service a1973e
Packit Service a1973e
Events are grouped in tables within the library. A table usually
Packit Service a1973e
corresponds to a PMU model or family. The library contains support
Packit Service a1973e
for multiple PMU models, thus it has multiple tables. Based on the
Packit Service a1973e
host hardware and software environments, tables get activated when
Packit Service a1973e
the library is initialized via \fBpfm_initialize()\fR. Events from
Packit Service a1973e
activated tables are called active events. Events from
Packit Service a1973e
non-activated tables are called supported events.
Packit Service a1973e
Packit Service a1973e
Event identifiers are usually retrieved via \fBpfm_find_event()\fR or
Packit Service a1973e
when encoding events.
Packit Service a1973e
Packit Service a1973e
To iterate over a list of events for a given PMU model, all that is
Packit Service a1973e
needed is an initial identifier for the PMU. The first event identifier
Packit Service a1973e
is usually obtained via \fBpfm_get_pmu_info()\fR.
Packit Service a1973e
Packit Service a1973e
The \fBpfm_get_event_next()\fR function returns the identifier of
Packit Service a1973e
next supported event after the one passed in \fBidx\fR. This iterator
Packit Service a1973e
stops when the last event for the PMU is passed as argument, in which
Packit Service a1973e
case the function returns \-1.
Packit Service a1973e
.sp
Packit Service a1973e
.nf
Packit Service a1973e
void list_pmu_events(pfm_pmu_t pmu)
Packit Service a1973e
{
Packit Service a1973e
   struct pfm_event_info info;
Packit Service a1973e
   struct pfm_pmu_info pinfo;
Packit Service a1973e
   int i, ret;
Packit Service a1973e
Packit Service a1973e
   memset(&info, 0, sizeof(info));
Packit Service a1973e
   memset(&pinfo, 0, sizeof(pinfo));
Packit Service a1973e
Packit Service a1973e
   info.size = sizeof(info);
Packit Service a1973e
   pinfo.size = sizeof(pinfo);
Packit Service a1973e
Packit Service a1973e
   ret = pfm_get_pmu_info(pmu, &pinfo);
Packit Service a1973e
   if (ret != PFM_SUCCESS)
Packit Service a1973e
      errx(1, "cannot get pmu info");
Packit Service a1973e
Packit Service a1973e
   for (i = pinfo.first_event; i != \-1; i = pfm_get_event_next(i)) {
Packit Service a1973e
      ret = pfm_get_event_info(i, &info;;
Packit Service a1973e
      if (ret != PFM_SUCCESS)
Packit Service a1973e
        errx(1, "cannot get event info");
Packit Service a1973e
Packit Service a1973e
        printf("%s Event: %s::%s\\n",
Packit Service a1973e
               pinfo.present ? "Active" : "Supported",
Packit Service a1973e
               pinfo.name, info.name);
Packit Service a1973e
  }
Packit Service a1973e
}
Packit Service a1973e
.fi
Packit Service a1973e
Packit Service a1973e
.SH RETURN
Packit Service a1973e
The function returns the identifier of the next
Packit Service a1973e
supported event. It returns \-1 when the argument is already the last
Packit Service a1973e
event for the PMU.
Packit Service a1973e
Packit Service a1973e
.SH ERRORS
Packit Service a1973e
No error code, besides \-1, is returned by this function.
Packit Service a1973e
.SH SEE ALSO
Packit Service a1973e
pfm_find_event(3)
Packit Service a1973e
.SH AUTHOR
Packit Service a1973e
Stephane Eranian <eranian@gmail.com>
Packit Service a1973e
.PP