1LIBPFM(3) Linux Programmer's Manual LIBPFM(3)
2
3
4
6 pfm_get_event_encoding - get raw event encoding
7
9 #include <perfmon/pfmlib.h>
10
11 int pfm_get_event_encoding(const char *str,int dfl_plm, char **fstr, int *idx, uint64_t *code, int *count);
12
13
15 This function is used to retrieve the raw event encoding corresponding
16 to the event string in str. The string may contain unit masks and mod‐
17 ifiers. The default privilege level mask is passed in dfl_plm. It may
18 be used depending on the event.
19
20 This function is deprecated. It is superseded by
21 pfm_get_os_event_encoding() where the OS is set to PFM_OS_NONE. Encod‐
22 ing is retrieve through the pfm_pmu_encode_arg_t structure.
23
24 The following examples illustrates the transition:
25
26 int i, count = 0;
27 uint64_t *codes;
28
29 ret = pfm_get_event_encoding("RETIRED_INSTRUCTIONS", PFM_PLM3, NULL, &codes, &count);
30 if (ret != PFM_SUCCESS)
31 err(1", cannot get encoding %s", pfm_strerror(ret));
32
33 for(i=0; i < count; i++)
34 printf("count[%d]=0x%"PRIx64"\n", i, codes[i]);
35
36 is equivalent to:
37
38 pfm_pmu_encode_arg_t arg;
39 int i;
40
41 memset(&arg, 0, sizeof(arg));
42 arg.size = sizeof(arg);
43
44 ret = pfm_get_os_event_encoding("RETIRED_INSTRUCTIONS", PFM_PLM3, PFM_OS_NONE, &arg);
45 if (ret != PFM_SUCCESS)
46 err(1", cannot get encoding %s", pfm_strerror(ret));
47
48 for(i=0; i < arg.count; i++)
49 printf("count[%d]=0x%"PRIx64"\n", i, arg.codes[i]);
50
51 free(arg.codes);
52
53 The encoding may take several 64-bit integers. The function can use the array passed in code if the number
54 of entries passed in count is big enough. However, if both *codes is NULL and count
55 is 0, the function allocates the memory necessary to store the encoding. It is up to the caller to
56 eventually free the memory. The number of 64-bit entries in codes is reflected in *count upon
57 return regardless of whether the codes was allocated or used as is. If the number of 64-bit integers is
58 greater than one, then the order in which each component is returned is PMU-model specific. Refer to the PMU
59 specific man page.
60
61 The raw encoding means the encoding as mandated by the underlying PMU model. It may not be directly suitable
62 to pass to a kernel API. You may want to use API-specific library calls to ensure the correct encoding is passed.
63
64 If fstr is not NULL, it will point to the fully qualified event string upon successful return. The string
65 contains the event name, any umask set, and the value of all the modifiers. It reflects what the encoding will
66 actually measure. The function allocates the memory to store the string. The caller must eventually free the
67 string.
68
69 Here is a example of how this function could be used:
70 #include <inttypes.h>
71 #include <err.h>
72 #include <perfmon/pfmlib.h>
73 int main(int argc, char **argv)
74 {
75 uint64_t *codes 0;
76 int count = 0;
77 int ret;
78
79 ret = pfm_initialize();
80 if (ret != PFMLIB_SUCCESS)
81 err(1", cannot initialize library %s", pfm_strerror(ret));
82
83 ret = pfm_get_event_encoding("RETIRED_INSTRUCTIONS", PFM_PLM3, NULL, &codes, &count);
84 if (ret != PFM_SUCCESS)
85 err(1", cannot get encoding %s", pfm_strerror(ret));
86
87 for(i=0; i < count; i++)
88 printf("count[%d]=0x%"PRIx64"\n", i, codes[i]);
89
90 free(codes);
91 return 0;
92 }
93
95 The function returns in *codes the encoding of the event and in *count
96 the number of 64-bit integers to support that encoding. Upon success,
97 PFM_SUCCESS is returned otherwise a specific error code is returned.
98
100 PFM_ERR_TOOSMALL
101 The code argument is too small for the encoding.
102
103 PFM_ERR_INVAL
104 The code or count argument is NULL.
105
106 PFM_ERR_NOMEM
107 Not enough memory.
108
109 PFM_ERR_NOTFOUND
110 Event not found.
111
112 PFM_ERR_ATTR
113 Invalid event attribute (unit mask or modifier)
114
115 PFM_ERR_ATTR_VAL
116 Invalid modifier value.
117
118 PFM_ERR_ATTR_SET
119 attribute already set, cannot be changed.
120
121 PFM_ERR_ATTR_UMASK
122 Missing unit mask.
123
124 PFM_ERR_ATTR_FEATCOMB
125 Unit masks or features cannot be combined into a single event.
126
128 Stephane Eranian <eranian@gmail.com>
129
131 pfm_get_os_event_encoding(3)
132
133
134
135 September, 2009 LIBPFM(3)