1 #include <linux/list.h>
2 #include <linux/compiler.h>
11 #include <api/fs/fs.h>
15 #include "parse-events.h"
18 #include "pmu-events/pmu-events.h"
22 struct perf_pmu_format {
25 DECLARE_BITMAP(bits, PERF_PMU_FORMAT_BITS);
26 struct list_head list;
29 #define EVENT_SOURCE_DEVICE_PATH "/bus/event_source/devices/"
31 int perf_pmu_parse(struct list_head *list, char *name);
32 extern FILE *perf_pmu_in;
34 static LIST_HEAD(pmus);
37 * Parse & process all the sysfs attributes located under
38 * the directory specified in 'dir' parameter.
40 int perf_pmu__format_parse(char *dir, struct list_head *head)
42 struct dirent *evt_ent;
46 format_dir = opendir(dir);
50 while (!ret && (evt_ent = readdir(format_dir))) {
52 char *name = evt_ent->d_name;
55 if (!strcmp(name, ".") || !strcmp(name, ".."))
58 snprintf(path, PATH_MAX, "%s/%s", dir, name);
61 file = fopen(path, "r");
66 ret = perf_pmu_parse(head, name);
75 * Reading/parsing the default pmu format definition, which should be
77 * /sys/bus/event_source/devices/<dev>/format as sysfs group attributes.
79 static int pmu_format(const char *name, struct list_head *format)
83 const char *sysfs = sysfs__mountpoint();
88 snprintf(path, PATH_MAX,
89 "%s" EVENT_SOURCE_DEVICE_PATH "%s/format", sysfs, name);
91 if (stat(path, &st) < 0)
92 return 0; /* no error if format does not exist */
94 if (perf_pmu__format_parse(path, format))
100 static int convert_scale(const char *scale, char **end, double *sval)
106 * save current locale
108 lc = setlocale(LC_NUMERIC, NULL);
111 * The lc string may be allocated in static storage,
112 * so get a dynamic copy to make it survive setlocale
122 * force to C locale to ensure kernel
123 * scale string is converted correctly.
124 * kernel uses default C locale.
126 setlocale(LC_NUMERIC, "C");
128 *sval = strtod(scale, end);
132 setlocale(LC_NUMERIC, lc);
137 static int perf_pmu__parse_scale(struct perf_pmu_alias *alias, char *dir, char *name)
145 snprintf(path, PATH_MAX, "%s/%s.scale", dir, name);
147 fd = open(path, O_RDONLY);
151 if (fstat(fd, &st) < 0)
154 sret = read(fd, scale, sizeof(scale)-1);
158 if (scale[sret - 1] == '\n')
159 scale[sret - 1] = '\0';
163 ret = convert_scale(scale, NULL, &alias->scale);
169 static int perf_pmu__parse_unit(struct perf_pmu_alias *alias, char *dir, char *name)
175 snprintf(path, PATH_MAX, "%s/%s.unit", dir, name);
177 fd = open(path, O_RDONLY);
181 sret = read(fd, alias->unit, UNIT_MAX_LEN);
187 if (alias->unit[sret - 1] == '\n')
188 alias->unit[sret - 1] = '\0';
190 alias->unit[sret] = '\0';
195 alias->unit[0] = '\0';
200 perf_pmu__parse_per_pkg(struct perf_pmu_alias *alias, char *dir, char *name)
205 snprintf(path, PATH_MAX, "%s/%s.per-pkg", dir, name);
207 fd = open(path, O_RDONLY);
213 alias->per_pkg = true;
217 static int perf_pmu__parse_snapshot(struct perf_pmu_alias *alias,
218 char *dir, char *name)
223 snprintf(path, PATH_MAX, "%s/%s.snapshot", dir, name);
225 fd = open(path, O_RDONLY);
229 alias->snapshot = true;
234 static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name,
235 char *desc, char *val,
236 char *long_desc, char *topic,
237 char *unit, char *perpkg,
241 struct perf_pmu_alias *alias;
245 alias = malloc(sizeof(*alias));
249 INIT_LIST_HEAD(&alias->terms);
251 alias->unit[0] = '\0';
252 alias->per_pkg = false;
253 alias->snapshot = false;
255 ret = parse_events_terms(&alias->terms, val);
257 pr_err("Cannot parse alias %s: %d\n", val, ret);
262 alias->name = strdup(name);
265 * load unit name and scale if available
267 perf_pmu__parse_unit(alias, dir, name);
268 perf_pmu__parse_scale(alias, dir, name);
269 perf_pmu__parse_per_pkg(alias, dir, name);
270 perf_pmu__parse_snapshot(alias, dir, name);
273 alias->metric_expr = metric_expr ? strdup(metric_expr) : NULL;
274 alias->metric_name = metric_name ? strdup(metric_name): NULL;
275 alias->desc = desc ? strdup(desc) : NULL;
276 alias->long_desc = long_desc ? strdup(long_desc) :
277 desc ? strdup(desc) : NULL;
278 alias->topic = topic ? strdup(topic) : NULL;
280 if (convert_scale(unit, &unit, &alias->scale) < 0)
282 snprintf(alias->unit, sizeof(alias->unit), "%s", unit);
284 alias->per_pkg = perpkg && sscanf(perpkg, "%d", &num) == 1 && num == 1;
285 alias->str = strdup(val);
287 list_add_tail(&alias->list, list);
292 static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FILE *file)
297 ret = fread(buf, 1, sizeof(buf), file);
303 return __perf_pmu__new_alias(list, dir, name, NULL, buf, NULL, NULL, NULL,
307 static inline bool pmu_alias_info_file(char *name)
312 if (len > 5 && !strcmp(name + len - 5, ".unit"))
314 if (len > 6 && !strcmp(name + len - 6, ".scale"))
316 if (len > 8 && !strcmp(name + len - 8, ".per-pkg"))
318 if (len > 9 && !strcmp(name + len - 9, ".snapshot"))
325 * Process all the sysfs attributes located under the directory
326 * specified in 'dir' parameter.
328 static int pmu_aliases_parse(char *dir, struct list_head *head)
330 struct dirent *evt_ent;
333 event_dir = opendir(dir);
337 while ((evt_ent = readdir(event_dir))) {
339 char *name = evt_ent->d_name;
342 if (!strcmp(name, ".") || !strcmp(name, ".."))
346 * skip info files parsed in perf_pmu__new_alias()
348 if (pmu_alias_info_file(name))
351 snprintf(path, PATH_MAX, "%s/%s", dir, name);
353 file = fopen(path, "r");
355 pr_debug("Cannot open %s\n", path);
359 if (perf_pmu__new_alias(head, dir, name, file) < 0)
360 pr_debug("Cannot set up %s\n", name);
369 * Reading the pmu event aliases definition, which should be located at:
370 * /sys/bus/event_source/devices/<dev>/events as sysfs group attributes.
372 static int pmu_aliases(const char *name, struct list_head *head)
376 const char *sysfs = sysfs__mountpoint();
381 snprintf(path, PATH_MAX,
382 "%s/bus/event_source/devices/%s/events", sysfs, name);
384 if (stat(path, &st) < 0)
385 return 0; /* no error if 'events' does not exist */
387 if (pmu_aliases_parse(path, head))
393 static int pmu_alias_terms(struct perf_pmu_alias *alias,
394 struct list_head *terms)
396 struct parse_events_term *term, *cloned;
400 list_for_each_entry(term, &alias->terms, list) {
401 ret = parse_events_term__clone(&cloned, term);
403 parse_events_terms__purge(&list);
406 list_add_tail(&cloned->list, &list);
408 list_splice(&list, terms);
413 * Reading/parsing the default pmu type value, which should be
415 * /sys/bus/event_source/devices/<dev>/type as sysfs attribute.
417 static int pmu_type(const char *name, __u32 *type)
423 const char *sysfs = sysfs__mountpoint();
428 snprintf(path, PATH_MAX,
429 "%s" EVENT_SOURCE_DEVICE_PATH "%s/type", sysfs, name);
431 if (stat(path, &st) < 0)
434 file = fopen(path, "r");
438 if (1 != fscanf(file, "%u", type))
445 /* Add all pmus in sysfs to pmu list: */
446 static void pmu_read_sysfs(void)
451 const char *sysfs = sysfs__mountpoint();
456 snprintf(path, PATH_MAX,
457 "%s" EVENT_SOURCE_DEVICE_PATH, sysfs);
463 while ((dent = readdir(dir))) {
464 if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, ".."))
466 /* add to static LIST_HEAD(pmus): */
467 perf_pmu__find(dent->d_name);
473 static struct cpu_map *pmu_cpumask(const char *name)
478 struct cpu_map *cpus;
479 const char *sysfs = sysfs__mountpoint();
480 const char *templates[] = {
481 "%s/bus/event_source/devices/%s/cpumask",
482 "%s/bus/event_source/devices/%s/cpus",
485 const char **template;
490 for (template = templates; *template; template++) {
491 snprintf(path, PATH_MAX, *template, sysfs, name);
492 if (stat(path, &st) == 0)
499 file = fopen(path, "r");
503 cpus = cpu_map__read(file);
509 * Return the CPU id as a raw string.
511 * Each architecture should provide a more precise id string that
512 * can be use to match the architecture's "mapfile".
514 char * __weak get_cpuid_str(void)
520 * From the pmu_events_map, find the table of PMU events that corresponds
521 * to the current running CPU. Then, add all PMU events from that table
524 static void pmu_add_cpu_aliases(struct list_head *head, const char *name)
527 struct pmu_events_map *map;
528 struct pmu_event *pe;
532 cpuid = getenv("PERF_CPUID");
534 cpuid = strdup(cpuid);
536 cpuid = get_cpuid_str();
541 pr_debug("Using CPUID %s\n", cpuid);
547 map = &pmu_events_map[i++];
551 if (!strcmp(map->cpuid, cpuid))
556 * Found a matching PMU events table. Create aliases
562 pe = &map->table[i++];
566 pname = pe->pmu ? pe->pmu : "cpu";
567 if (strncmp(pname, name, strlen(pname)))
570 /* need type casts to override 'const' */
571 __perf_pmu__new_alias(head, NULL, (char *)pe->name,
572 (char *)pe->desc, (char *)pe->event,
573 (char *)pe->long_desc, (char *)pe->topic,
574 (char *)pe->unit, (char *)pe->perpkg,
575 (char *)pe->metric_expr,
576 (char *)pe->metric_name);
583 struct perf_event_attr * __weak
584 perf_pmu__get_default_config(struct perf_pmu *pmu __maybe_unused)
589 static struct perf_pmu *pmu_lookup(const char *name)
591 struct perf_pmu *pmu;
597 * The pmu data we store & need consists of the pmu
598 * type value and format definitions. Load both right
601 if (pmu_format(name, &format))
605 * Check the type first to avoid unnecessary work.
607 if (pmu_type(name, &type))
610 if (pmu_aliases(name, &aliases))
613 pmu_add_cpu_aliases(&aliases, name);
614 pmu = zalloc(sizeof(*pmu));
618 pmu->cpus = pmu_cpumask(name);
620 INIT_LIST_HEAD(&pmu->format);
621 INIT_LIST_HEAD(&pmu->aliases);
622 list_splice(&format, &pmu->format);
623 list_splice(&aliases, &pmu->aliases);
624 pmu->name = strdup(name);
626 list_add_tail(&pmu->list, &pmus);
628 pmu->default_config = perf_pmu__get_default_config(pmu);
633 static struct perf_pmu *pmu_find(const char *name)
635 struct perf_pmu *pmu;
637 list_for_each_entry(pmu, &pmus, list)
638 if (!strcmp(pmu->name, name))
644 struct perf_pmu *perf_pmu__scan(struct perf_pmu *pmu)
647 * pmu iterator: If pmu is NULL, we start at the begin,
648 * otherwise return the next pmu. Returns NULL on end.
652 pmu = list_prepare_entry(pmu, &pmus, list);
654 list_for_each_entry_continue(pmu, &pmus, list)
659 struct perf_pmu *perf_pmu__find(const char *name)
661 struct perf_pmu *pmu;
664 * Once PMU is loaded it stays in the list,
665 * so we keep us from multiple reading/parsing
666 * the pmu format definitions.
668 pmu = pmu_find(name);
672 return pmu_lookup(name);
675 static struct perf_pmu_format *
676 pmu_find_format(struct list_head *formats, const char *name)
678 struct perf_pmu_format *format;
680 list_for_each_entry(format, formats, list)
681 if (!strcmp(format->name, name))
687 __u64 perf_pmu__format_bits(struct list_head *formats, const char *name)
689 struct perf_pmu_format *format = pmu_find_format(formats, name);
696 for_each_set_bit(fbit, format->bits, PERF_PMU_FORMAT_BITS)
697 bits |= 1ULL << fbit;
703 * Sets value based on the format definition (format parameter)
704 * and unformated value (value parameter).
706 static void pmu_format_value(unsigned long *format, __u64 value, __u64 *v,
709 unsigned long fbit, vbit;
711 for (fbit = 0, vbit = 0; fbit < PERF_PMU_FORMAT_BITS; fbit++) {
713 if (!test_bit(fbit, format))
716 if (value & (1llu << vbit++))
717 *v |= (1llu << fbit);
719 *v &= ~(1llu << fbit);
723 static __u64 pmu_format_max_value(const unsigned long *format)
728 for_each_set_bit(fbit, format, PERF_PMU_FORMAT_BITS)
735 * Term is a string term, and might be a param-term. Try to look up it's value
736 * in the remaining terms.
737 * - We have a term like "base-or-format-term=param-term",
738 * - We need to find the value supplied for "param-term" (with param-term named
739 * in a config string) later on in the term list.
741 static int pmu_resolve_param_term(struct parse_events_term *term,
742 struct list_head *head_terms,
745 struct parse_events_term *t;
747 list_for_each_entry(t, head_terms, list) {
748 if (t->type_val == PARSE_EVENTS__TERM_TYPE_NUM) {
749 if (!strcmp(t->config, term->config)) {
758 printf("Required parameter '%s' not specified\n", term->config);
763 static char *pmu_formats_string(struct list_head *formats)
765 struct perf_pmu_format *format;
767 struct strbuf buf = STRBUF_INIT;
773 /* sysfs exported terms */
774 list_for_each_entry(format, formats, list)
775 if (strbuf_addf(&buf, i++ ? ",%s" : "%s", format->name) < 0)
778 str = strbuf_detach(&buf, NULL);
780 strbuf_release(&buf);
786 * Setup one of config[12] attr members based on the
787 * user input data - term parameter.
789 static int pmu_config_term(struct list_head *formats,
790 struct perf_event_attr *attr,
791 struct parse_events_term *term,
792 struct list_head *head_terms,
793 bool zero, struct parse_events_error *err)
795 struct perf_pmu_format *format;
800 * If this is a parameter we've already used for parameterized-eval,
801 * skip it in normal eval.
807 * Hardcoded terms should be already in, so nothing
808 * to be done for them.
810 if (parse_events__is_hardcoded_term(term))
813 format = pmu_find_format(formats, term->config);
816 printf("Invalid event/parameter '%s'\n", term->config);
818 char *pmu_term = pmu_formats_string(formats);
820 err->idx = term->err_term;
821 err->str = strdup("unknown term");
822 err->help = parse_events_formats_error_string(pmu_term);
828 switch (format->value) {
829 case PERF_PMU_FORMAT_VALUE_CONFIG:
832 case PERF_PMU_FORMAT_VALUE_CONFIG1:
835 case PERF_PMU_FORMAT_VALUE_CONFIG2:
843 * Either directly use a numeric term, or try to translate string terms
844 * using event parameters.
846 if (term->type_val == PARSE_EVENTS__TERM_TYPE_NUM) {
847 if (term->no_value &&
848 bitmap_weight(format->bits, PERF_PMU_FORMAT_BITS) > 1) {
850 err->idx = term->err_val;
851 err->str = strdup("no value assigned for term");
857 } else if (term->type_val == PARSE_EVENTS__TERM_TYPE_STR) {
858 if (strcmp(term->val.str, "?")) {
860 pr_info("Invalid sysfs entry %s=%s\n",
861 term->config, term->val.str);
864 err->idx = term->err_val;
865 err->str = strdup("expected numeric value");
870 if (pmu_resolve_param_term(term, head_terms, &val))
875 max_val = pmu_format_max_value(format->bits);
878 err->idx = term->err_val;
879 if (asprintf(&err->str,
880 "value too big for format, maximum is %llu",
881 (unsigned long long)max_val) < 0)
882 err->str = strdup("value too big for format");
886 * Assume we don't care if !err, in which case the value will be
887 * silently truncated.
891 pmu_format_value(format->bits, val, vp, zero);
895 int perf_pmu__config_terms(struct list_head *formats,
896 struct perf_event_attr *attr,
897 struct list_head *head_terms,
898 bool zero, struct parse_events_error *err)
900 struct parse_events_term *term;
902 list_for_each_entry(term, head_terms, list) {
903 if (pmu_config_term(formats, attr, term, head_terms,
912 * Configures event's 'attr' parameter based on the:
913 * 1) users input - specified in terms parameter
914 * 2) pmu format definitions - specified by pmu parameter
916 int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr,
917 struct list_head *head_terms,
918 struct parse_events_error *err)
920 bool zero = !!pmu->default_config;
922 attr->type = pmu->type;
923 return perf_pmu__config_terms(&pmu->format, attr, head_terms,
927 static struct perf_pmu_alias *pmu_find_alias(struct perf_pmu *pmu,
928 struct parse_events_term *term)
930 struct perf_pmu_alias *alias;
933 if (parse_events__is_hardcoded_term(term))
936 if (term->type_val == PARSE_EVENTS__TERM_TYPE_NUM) {
937 if (term->val.num != 1)
939 if (pmu_find_format(&pmu->format, term->config))
942 } else if (term->type_val == PARSE_EVENTS__TERM_TYPE_STR) {
943 if (strcasecmp(term->config, "event"))
945 name = term->val.str;
950 list_for_each_entry(alias, &pmu->aliases, list) {
951 if (!strcasecmp(alias->name, name))
958 static int check_info_data(struct perf_pmu_alias *alias,
959 struct perf_pmu_info *info)
962 * Only one term in event definition can
963 * define unit, scale and snapshot, fail
964 * if there's more than one.
966 if ((info->unit && alias->unit[0]) ||
967 (info->scale && alias->scale) ||
968 (info->snapshot && alias->snapshot))
972 info->unit = alias->unit;
975 info->scale = alias->scale;
978 info->snapshot = alias->snapshot;
984 * Find alias in the terms list and replace it with the terms
985 * defined for the alias
987 int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms,
988 struct perf_pmu_info *info)
990 struct parse_events_term *term, *h;
991 struct perf_pmu_alias *alias;
994 info->per_pkg = false;
997 * Mark unit and scale as not set
998 * (different from default values, see below)
1002 info->snapshot = false;
1003 info->metric_expr = NULL;
1004 info->metric_name = NULL;
1006 list_for_each_entry_safe(term, h, head_terms, list) {
1007 alias = pmu_find_alias(pmu, term);
1010 ret = pmu_alias_terms(alias, &term->list);
1014 ret = check_info_data(alias, info);
1019 info->per_pkg = true;
1020 info->metric_expr = alias->metric_expr;
1021 info->metric_name = alias->metric_name;
1023 list_del(&term->list);
1028 * if no unit or scale foundin aliases, then
1029 * set defaults as for evsel
1030 * unit cannot left to NULL
1032 if (info->unit == NULL)
1035 if (info->scale == 0.0)
1041 int perf_pmu__new_format(struct list_head *list, char *name,
1042 int config, unsigned long *bits)
1044 struct perf_pmu_format *format;
1046 format = zalloc(sizeof(*format));
1050 format->name = strdup(name);
1051 format->value = config;
1052 memcpy(format->bits, bits, sizeof(format->bits));
1054 list_add_tail(&format->list, list);
1058 void perf_pmu__set_format(unsigned long *bits, long from, long to)
1065 memset(bits, 0, BITS_TO_BYTES(PERF_PMU_FORMAT_BITS));
1066 for (b = from; b <= to; b++)
1070 static int sub_non_neg(int a, int b)
1077 static char *format_alias(char *buf, int len, struct perf_pmu *pmu,
1078 struct perf_pmu_alias *alias)
1080 struct parse_events_term *term;
1081 int used = snprintf(buf, len, "%s/%s", pmu->name, alias->name);
1083 list_for_each_entry(term, &alias->terms, list) {
1084 if (term->type_val == PARSE_EVENTS__TERM_TYPE_STR)
1085 used += snprintf(buf + used, sub_non_neg(len, used),
1086 ",%s=%s", term->config,
1090 if (sub_non_neg(len, used) > 0) {
1094 if (sub_non_neg(len, used) > 0) {
1098 buf[len - 1] = '\0';
1103 static char *format_alias_or(char *buf, int len, struct perf_pmu *pmu,
1104 struct perf_pmu_alias *alias)
1106 snprintf(buf, len, "%s OR %s/%s/", alias->name, pmu->name, alias->name);
1120 static int cmp_sevent(const void *a, const void *b)
1122 const struct sevent *as = a;
1123 const struct sevent *bs = b;
1125 /* Put extra events last */
1126 if (!!as->desc != !!bs->desc)
1127 return !!as->desc - !!bs->desc;
1128 if (as->topic && bs->topic) {
1129 int n = strcmp(as->topic, bs->topic);
1134 return strcmp(as->name, bs->name);
1137 static void wordwrap(char *s, int start, int max, int corr)
1143 int wlen = strcspn(s, " \t");
1145 if (column + wlen >= max && column > start) {
1146 printf("\n%*s", start, "");
1147 column = start + corr;
1149 n = printf("%s%.*s", column > start ? " " : "", wlen, s);
1158 void print_pmu_events(const char *event_glob, bool name_only, bool quiet_flag,
1159 bool long_desc, bool details_flag)
1161 struct perf_pmu *pmu;
1162 struct perf_pmu_alias *alias;
1166 struct sevent *aliases;
1168 int columns = pager_get_columns();
1173 while ((pmu = perf_pmu__scan(pmu)) != NULL) {
1174 list_for_each_entry(alias, &pmu->aliases, list)
1176 if (pmu->selectable)
1179 aliases = zalloc(sizeof(struct sevent) * len);
1184 while ((pmu = perf_pmu__scan(pmu)) != NULL) {
1185 list_for_each_entry(alias, &pmu->aliases, list) {
1186 char *name = alias->desc ? alias->name :
1187 format_alias(buf, sizeof(buf), pmu, alias);
1188 bool is_cpu = !strcmp(pmu->name, "cpu");
1190 if (event_glob != NULL &&
1191 !(strglobmatch_nocase(name, event_glob) ||
1192 (!is_cpu && strglobmatch_nocase(alias->name,
1195 strglobmatch_nocase(alias->topic, event_glob))))
1198 if (is_cpu && !name_only && !alias->desc)
1199 name = format_alias_or(buf, sizeof(buf), pmu, alias);
1201 aliases[j].name = name;
1202 if (is_cpu && !name_only && !alias->desc)
1203 aliases[j].name = format_alias_or(buf,
1206 aliases[j].name = strdup(aliases[j].name);
1207 if (!aliases[j].name)
1210 aliases[j].desc = long_desc ? alias->long_desc :
1212 aliases[j].topic = alias->topic;
1213 aliases[j].str = alias->str;
1214 aliases[j].pmu = pmu->name;
1215 aliases[j].metric_expr = alias->metric_expr;
1216 aliases[j].metric_name = alias->metric_name;
1219 if (pmu->selectable &&
1220 (event_glob == NULL || strglobmatch(pmu->name, event_glob))) {
1222 if (asprintf(&s, "%s//", pmu->name) < 0)
1224 aliases[j].name = s;
1229 qsort(aliases, len, sizeof(struct sevent), cmp_sevent);
1230 for (j = 0; j < len; j++) {
1231 /* Skip duplicates */
1232 if (j > 0 && !strcmp(aliases[j].name, aliases[j - 1].name))
1235 printf("%s ", aliases[j].name);
1238 if (aliases[j].desc && !quiet_flag) {
1241 if (aliases[j].topic && (!topic ||
1242 strcmp(topic, aliases[j].topic))) {
1243 printf("%s%s:\n", topic ? "\n" : "",
1245 topic = aliases[j].topic;
1247 printf(" %-50s\n", aliases[j].name);
1248 printf("%*s", 8, "[");
1249 wordwrap(aliases[j].desc, 8, columns, 0);
1252 printf("%*s%s/%s/ ", 8, "", aliases[j].pmu, aliases[j].str);
1253 if (aliases[j].metric_name)
1254 printf(" MetricName: %s", aliases[j].metric_name);
1255 if (aliases[j].metric_expr)
1256 printf(" MetricExpr: %s", aliases[j].metric_expr);
1260 printf(" %-50s [Kernel PMU event]\n", aliases[j].name);
1263 if (printed && pager_in_use())
1266 for (j = 0; j < len; j++)
1267 zfree(&aliases[j].name);
1272 printf("FATAL: not enough memory to print PMU events\n");
1277 bool pmu_have_event(const char *pname, const char *name)
1279 struct perf_pmu *pmu;
1280 struct perf_pmu_alias *alias;
1283 while ((pmu = perf_pmu__scan(pmu)) != NULL) {
1284 if (strcmp(pname, pmu->name))
1286 list_for_each_entry(alias, &pmu->aliases, list)
1287 if (!strcmp(alias->name, name))
1293 static FILE *perf_pmu__open_file(struct perf_pmu *pmu, const char *name)
1296 char path[PATH_MAX];
1299 sysfs = sysfs__mountpoint();
1303 snprintf(path, PATH_MAX,
1304 "%s" EVENT_SOURCE_DEVICE_PATH "%s/%s", sysfs, pmu->name, name);
1306 if (stat(path, &st) < 0)
1309 return fopen(path, "r");
1312 int perf_pmu__scan_file(struct perf_pmu *pmu, const char *name, const char *fmt,
1319 va_start(args, fmt);
1320 file = perf_pmu__open_file(pmu, name);
1322 ret = vfscanf(file, fmt, args);