54 #include <sys/types.h> 67 #include <linux/perf_event.h> 81 #include <perfmon/pfmlib.h> 95 struct perf_event_attr *
attr;
110 #define MAX_EVENT_NAME_CHARS 256 111 #define MAX_EVENT_DESC_CHARS 4096 113 #define EVENT_IS_PROFILABLE 0 114 #define EVENT_MAY_NOT_PROFILABLE 1 115 #define EVENT_FATAL_ERROR -1 134 return (p = strchr(s,
':')) && *(p+1) ==
':';
147 struct perf_event_attr event_attr;
148 memset(&event_attr, 0,
sizeof(event_attr));
149 event_attr.disabled = 1;
151 event_attr.size =
sizeof(
struct perf_event_attr);
152 event_attr.type = type;
153 event_attr.config = code;
156 event_attr.exclude_kernel = 1;
157 event_attr.exclude_hv = 1;
158 event_attr.exclude_idle = 1;
198 pfm_event_attr_info_t ainfo;
199 pfm_pmu_info_t pinfo;
202 memset(&ainfo, 0,
sizeof(ainfo));
203 memset(&pinfo, 0,
sizeof(pinfo));
205 pinfo.size =
sizeof(pinfo);
206 ainfo.size =
sizeof(ainfo);
208 ret = pfm_get_pmu_info(info->pmu, &pinfo);
210 EMSG(
"cannot get pmu info: %s", pfm_strerror(ret));
217 sprintf(buffer,
"%s::%s", pinfo.name, info->name);
225 sprintf(buffer_desc,
"%s (*)", info->desc);
229 pfm_for_each_event_attr(i, info) {
230 ret = pfm_get_event_attr_info(info->idx, i, PFM_OS_NONE, &ainfo);
231 if (ret == PFM_SUCCESS)
234 sprintf(buffer,
"%s::%s:%s", pinfo.name, info->name, ainfo.name);
244 sprintf(buffer_desc,
"%s (*)", ainfo.desc);
259 pfm_pmu_info_t pinfo;
260 pfm_event_info_t info;
261 int i, j, ret, match = 0, pname;
264 memset(&pinfo, 0,
sizeof(pinfo));
265 memset(&info, 0,
sizeof(info));
267 pinfo.size =
sizeof(pinfo);
268 info.size =
sizeof(info);
276 pfm_for_all_pmus(j) {
278 ret = pfm_get_pmu_info(j, &pinfo);
279 if (ret != PFM_SUCCESS)
283 if (!pname && !pinfo.is_present)
286 for (i = pinfo.first_event; i != -1; i = pfm_get_event_next(i)) {
287 ret = pfm_get_event_info(i, PFM_OS_NONE, &info);
288 if (ret != PFM_SUCCESS)
289 EMSG(
"cannot get event info: %s", pfm_strerror(ret));
297 printf(
"(*) The counter may not be profilable.\n\n");
320 struct perf_event_attr attr;
321 memset(&attr, 0,
sizeof(
struct perf_event_attr));
324 int ret = pfm_get_os_event_encoding(eventname, PFM_PLM0|PFM_PLM3, PFM_OS_PERF_EVENT_EXT, &arg);
326 if (ret == PFM_SUCCESS) {
327 memcpy(event_attr, arg.
attr,
sizeof(
struct perf_event_attr));
343 struct perf_event_attr attr;
344 memset(&attr, 0,
sizeof(
struct perf_event_attr));
347 int ret = pfm_get_os_event_encoding(eventname, PFM_PLM0|PFM_PLM3, PFM_OS_PERF_EVENT, &arg);
349 if (ret == PFM_SUCCESS) {
350 *type = arg.
attr->type;
351 *code = arg.
attr->config;
367 u64 eventcode, eventtype;
385 ret = setenv(
"LIBPFM_ENCODE_INACTIVE",
"1", 1);
387 EMSG(
"cannot force inactive encoding");
392 ret = pfm_initialize();
394 if (ret != PFM_SUCCESS) {
395 EMSG(
"libpfm: cannot initialize: %s", pfm_strerror(ret));
414 static char *argv_all =
".*";
416 int total_supported_events = 0;
417 int total_available_events = 0;
419 pfm_pmu_info_t pinfo;
421 memset(&pinfo, 0,
sizeof(pinfo));
422 pinfo.size =
sizeof(pinfo);
424 static const char *pmu_types[]={
431 printf(
"Detected PMU models:\n");
433 pfm_for_all_pmus(i) {
434 ret = pfm_get_pmu_info(i, &pinfo);
435 if (ret != PFM_SUCCESS)
438 if (pinfo.is_present) {
439 if (pinfo.type >= PFM_PMU_TYPE_MAX)
440 pinfo.type = PFM_PMU_TYPE_UNKNOWN;
442 printf(
"\t[%d, %s, \"%s\", %d events, %d max encoding, %d counters, %s PMU]\n",
448 pinfo.num_cntrs + pinfo.num_fixed_cntrs,
449 pmu_types[pinfo.type]);
451 total_supported_events += pinfo.nevents;
453 total_available_events += pinfo.nevents;
455 printf(
"Total events: %d available, %d supported\n", total_available_events, total_supported_events);
static int event_has_pname(char *s)
static int show_event_info(pfm_event_info_t *info)
int pfmu_isSupported(const char *eventname)
#define MAX_EVENT_DESC_CHARS
#define EVENT_FATAL_ERROR
#define MAX_EVENT_NAME_CHARS
long perf_event_open(struct perf_event_attr *hw_event, pid_t pid, int cpu, int group_fd, unsigned long flags)
struct perf_event_attr * attr
void display_event_info(FILE *output, const char *event, const char *desc)
int pfmu_getEventType(const char *eventname, u64 *code, u64 *type)
#define EVENT_IS_PROFILABLE
static int show_info(char *event)
void display_line_single(FILE *output)
int pfmu_getEventAttribute(const char *eventname, struct perf_event_attr *event_attr)
static int create_event(uint64_t code, uint64_t type)
static int test_pmu(char *evname)
#define EVENT_MAY_NOT_PROFILABLE