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

Packit Service a1973e
.TH LIBPFM 3  "September, 2009" "" "Linux Programmer's Manual"
Packit Service a1973e
.SH NAME
Packit Service a1973e
pfm_get_event_encoding \- get raw event encoding
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_encoding(const char *" str ",int " dfl_plm ", char **" fstr ", int *" idx ", uint64_t *"code ", int *" count ");"
Packit Service a1973e
.sp
Packit Service a1973e
.SH DESCRIPTION
Packit Service a1973e
This function is used to retrieve the raw event encoding corresponding to the event string in \fBstr\fR.
Packit Service a1973e
Only one event per call can be encoded. As such, \fBstr\fR can contain only one symbolic event name.
Packit Service a1973e
The string may contain unit masks and modifiers. The default privilege level mask is passed in \fBdfl_plm\fR.
Packit Service a1973e
It may be used depending on the event.
Packit Service a1973e
Packit Service a1973e
This function is \fBdeprecated\fR. It is superseded by \fBpfm_get_os_event_encoding()\fR where the OS is set to
Packit Service a1973e
\fBPFM_OS_NONE\fR. Encoding is retrieve through the \fBpfm_pmu_encode_arg_t\fR structure.
Packit Service a1973e
Packit Service a1973e
The following examples illustrates the transition:
Packit Service a1973e
Packit Service a1973e
.nf
Packit Service a1973e
   int i, count = 0;
Packit Service a1973e
   uint64_t *codes;
Packit Service a1973e
Packit Service a1973e
   ret = pfm_get_event_encoding("RETIRED_INSTRUCTIONS", PFM_PLM3, NULL, &codes, &count);
Packit Service a1973e
   if (ret != PFM_SUCCESS)
Packit Service a1973e
      err(1", cannot get encoding %s", pfm_strerror(ret));
Packit Service a1973e
Packit Service a1973e
   for(i=0; i < count; i++)
Packit Service a1973e
      printf("count[%d]=0x%"PRIx64"\\n", i, codes[i]);
Packit Service a1973e
.fi
Packit Service a1973e
Packit Service a1973e
is equivalent to:
Packit Service a1973e
Packit Service a1973e
.nf
Packit Service a1973e
   pfm_pmu_encode_arg_t arg;
Packit Service a1973e
   int i;
Packit Service a1973e
Packit Service a1973e
   memset(&arg, 0, sizeof(arg));
Packit Service a1973e
   arg.size = sizeof(arg);
Packit Service a1973e
Packit Service a1973e
   ret = pfm_get_os_event_encoding("RETIRED_INSTRUCTIONS", PFM_PLM3, PFM_OS_NONE, &arg;;
Packit Service a1973e
   if (ret != PFM_SUCCESS)
Packit Service a1973e
      err(1", cannot get encoding %s", pfm_strerror(ret));
Packit Service a1973e
Packit Service a1973e
   for(i=0; i < arg.count; i++)
Packit Service a1973e
      printf("count[%d]=0x%"PRIx64"\\n", i, arg.codes[i]);
Packit Service a1973e
Packit Service a1973e
   free(arg.codes);
Packit Service a1973e
.nf
Packit Service a1973e
Packit Service a1973e
The encoding may take several 64-bit integers. The function can use the array passed in \fBcode\fR if the number
Packit Service a1973e
of entries passed in \fBcount\fR is big enough. However, if both \fB*codes\fR is \fBNULL\fR and \fBcount\fR
Packit Service a1973e
is 0, the function allocates the memory necessary to store the encoding. It is up to the caller to
Packit Service a1973e
eventually free the memory. The number of 64-bit entries in \fBcodes\fR is reflected in \fB*count\fR upon
Packit Service a1973e
return regardless of whether the \fBcodes\fR was allocated or used as is. If the number of 64-bit integers is
Packit Service a1973e
greater than one, then the order in which each component is returned is PMU-model specific. Refer to the PMU
Packit Service a1973e
specific man page.
Packit Service a1973e
Packit Service a1973e
The raw encoding means the encoding as mandated by the underlying PMU model. It may not be directly suitable
Packit Service a1973e
to pass to a kernel API. You may want to use API-specific library calls to ensure the correct encoding is passed.
Packit Service a1973e
Packit Service a1973e
If \fBfstr\fR is not NULL, it will point to the fully qualified event string upon successful return. The string
Packit Service a1973e
contains the event name, any umask set, and the value of all the modifiers. It reflects what the encoding will
Packit Service a1973e
actually measure. The function allocates the memory to store the string. The caller must eventually free the
Packit Service a1973e
string.
Packit Service a1973e
Packit Service a1973e
Here is a example of how this function could be used:
Packit Service a1973e
.nf
Packit Service a1973e
#include <inttypes.h>
Packit Service a1973e
#include <err.h>
Packit Service a1973e
#include <perfmon/pfmlib.h>
Packit Service a1973e
int main(int argc, char **argv)
Packit Service a1973e
{
Packit Service a1973e
   uint64_t *codes 0;
Packit Service a1973e
   int count = 0;
Packit Service a1973e
   int ret;
Packit Service a1973e
Packit Service a1973e
   ret = pfm_initialize();
Packit Service a1973e
   if (ret != PFMLIB_SUCCESS)
Packit Service a1973e
      err(1", cannot initialize library %s", pfm_strerror(ret));
Packit Service a1973e
Packit Service a1973e
   ret = pfm_get_event_encoding("RETIRED_INSTRUCTIONS", PFM_PLM3, NULL, &codes, &count);
Packit Service a1973e
   if (ret != PFM_SUCCESS)
Packit Service a1973e
      err(1", cannot get encoding %s", pfm_strerror(ret));
Packit Service a1973e
Packit Service a1973e
   for(i=0; i < count; i++)
Packit Service a1973e
      printf("count[%d]=0x%"PRIx64"\\n", i, codes[i]);
Packit Service a1973e
Packit Service a1973e
   free(codes);
Packit Service a1973e
   return 0;
Packit Service a1973e
}
Packit Service a1973e
.fi
Packit Service a1973e
.SH RETURN
Packit Service a1973e
The function returns in \fB*codes\fR the encoding of the event and in \fB*count\fR the number
Packit Service a1973e
of 64-bit integers to support that encoding. Upon success, \fBPFM_SUCCESS\fR is returned otherwise
Packit Service a1973e
a specific error code is returned.
Packit Service a1973e
.SH ERRORS
Packit Service a1973e
.TP
Packit Service a1973e
.B PFM_ERR_TOOSMALL
Packit Service a1973e
The \fBcode\fR argument is too small for the encoding.
Packit Service a1973e
.TP
Packit Service a1973e
.B PFM_ERR_INVAL
Packit Service a1973e
The \fBcode\fR or \fBcount\fR argument is \fBNULL\fR or the \fBstr\fR contains more than one symbolic event.
Packit Service a1973e
.TP
Packit Service a1973e
.B PFM_ERR_NOMEM
Packit Service a1973e
Not enough memory.
Packit Service a1973e
.TP
Packit Service a1973e
.B PFM_ERR_NOTFOUND
Packit Service a1973e
Event not found.
Packit Service a1973e
.TP
Packit Service a1973e
.B PFM_ERR_ATTR
Packit Service a1973e
Invalid event attribute (unit mask or modifier)
Packit Service a1973e
.TP
Packit Service a1973e
.B PFM_ERR_ATTR_VAL
Packit Service a1973e
Invalid modifier value.
Packit Service a1973e
.TP
Packit Service a1973e
.B PFM_ERR_ATTR_SET
Packit Service a1973e
attribute already set, cannot be changed.
Packit Service a1973e
.TP
Packit Service a1973e
.B PFM_ERR_ATTR_UMASK
Packit Service a1973e
Missing unit mask.
Packit Service a1973e
.TP
Packit Service a1973e
.B PFM_ERR_ATTR_FEATCOMB
Packit Service a1973e
Unit masks or features cannot be combined into a single event.
Packit Service a1973e
.SH AUTHOR
Packit Service a1973e
Stephane Eranian <eranian@gmail.com>
Packit Service a1973e
.SH SEE ALSO
Packit Service a1973e
pfm_get_os_event_encoding(3)