1 #include <linux/list.h>
2 #include <linux/compiler.h>
12 #include <api/fs/fs.h>
16 #include "parse-events.h"
19 #include "pmu-events/pmu-events.h"
23 struct perf_pmu_format {
26 DECLARE_BITMAP(bits, PERF_PMU_FORMAT_BITS);
27 struct list_head list;
30 #define EVENT_SOURCE_DEVICE_PATH "/bus/event_source/devices/"
32 int perf_pmu_parse(struct list_head *list, char *name);
33 extern FILE *perf_pmu_in;
35 static LIST_HEAD(pmus);
38 * Parse & process all the sysfs attributes located under
39 * the directory specified in 'dir' parameter.
41 int perf_pmu__format_parse(char *dir, struct list_head *head)
43 struct dirent *evt_ent;
47 format_dir = opendir(dir);
51 while (!ret && (evt_ent = readdir(format_dir))) {
53 char *name = evt_ent->d_name;
56 if (!strcmp(name, ".") || !strcmp(name, ".."))
59 snprintf(path, PATH_MAX, "%s/%s", dir, name);
62 file = fopen(path, "r");
67 ret = perf_pmu_parse(head, name);
76 * Reading/parsing the default pmu format definition, which should be
78 * /sys/bus/event_source/devices/<dev>/format as sysfs group attributes.
80 static int pmu_format(const char *name, struct list_head *format)
84 const char *sysfs = sysfs__mountpoint();
89 snprintf(path, PATH_MAX,
90 "%s" EVENT_SOURCE_DEVICE_PATH "%s/format", sysfs, name);
92 if (stat(path, &st) < 0)
93 return 0; /* no error if format does not exist */
95 if (perf_pmu__format_parse(path, format))
101 static int convert_scale(const char *scale, char **end, double *sval)
107 * save current locale
109 lc = setlocale(LC_NUMERIC, NULL);
112 * The lc string may be allocated in static storage,
113 * so get a dynamic copy to make it survive setlocale
123 * force to C locale to ensure kernel
124 * scale string is converted correctly.
125 * kernel uses default C locale.
127 setlocale(LC_NUMERIC, "C");
129 *sval = strtod(scale, end);
133 setlocale(LC_NUMERIC, lc);
138 static int perf_pmu__parse_scale(struct perf_pmu_alias *alias, char *dir, char *name)
146 snprintf(path, PATH_MAX, "%s/%s.scale", dir, name);
148 fd = open(path, O_RDONLY);
152 if (fstat(fd, &st) < 0)
155 sret = read(fd, scale, sizeof(scale)-1);
159 if (scale[sret - 1] == '\n')
160 scale[sret - 1] = '\0';
164 ret = convert_scale(scale, NULL, &alias->scale);
170 static int perf_pmu__parse_unit(struct perf_pmu_alias *alias, char *dir, char *name)
176 snprintf(path, PATH_MAX, "%s/%s.unit", dir, name);
178 fd = open(path, O_RDONLY);
182 sret = read(fd, alias->unit, UNIT_MAX_LEN);
188 if (alias->unit[sret - 1] == '\n')
189 alias->unit[sret - 1] = '\0';
191 alias->unit[sret] = '\0';
196 alias->unit[0] = '\0';
201 perf_pmu__parse_per_pkg(struct perf_pmu_alias *alias, char *dir, char *name)
206 snprintf(path, PATH_MAX, "%s/%s.per-pkg", dir, name);
208 fd = open(path, O_RDONLY);
214 alias->per_pkg = true;
218 static int perf_pmu__parse_snapshot(struct perf_pmu_alias *alias,
219 char *dir, char *name)
224 snprintf(path, PATH_MAX, "%s/%s.snapshot", dir, name);
226 fd = open(path, O_RDONLY);
230 alias->snapshot = true;
235 static int __perf_pmu__new_alias(struct list_head *list, char *dir, char *name,
236 char *desc, char *val,
237 char *long_desc, char *topic,
238 char *unit, char *perpkg,
242 struct perf_pmu_alias *alias;
246 alias = malloc(sizeof(*alias));
250 INIT_LIST_HEAD(&alias->terms);
252 alias->unit[0] = '\0';
253 alias->per_pkg = false;
254 alias->snapshot = false;
256 ret = parse_events_terms(&alias->terms, val);
258 pr_err("Cannot parse alias %s: %d\n", val, ret);
263 alias->name = strdup(name);
266 * load unit name and scale if available
268 perf_pmu__parse_unit(alias, dir, name);
269 perf_pmu__parse_scale(alias, dir, name);
270 perf_pmu__parse_per_pkg(alias, dir, name);
271 perf_pmu__parse_snapshot(alias, dir, name);
274 alias->metric_expr = metric_expr ? strdup(metric_expr) : NULL;
275 alias->metric_name = metric_name ? strdup(metric_name): NULL;
276 alias->desc = desc ? strdup(desc) : NULL;
277 alias->long_desc = long_desc ? strdup(long_desc) :
278 desc ? strdup(desc) : NULL;
279 alias->topic = topic ? strdup(topic) : NULL;
281 if (convert_scale(unit, &unit, &alias->scale) < 0)
283 snprintf(alias->unit, sizeof(alias->unit), "%s", unit);
285 alias->per_pkg = perpkg && sscanf(perpkg, "%d", &num) == 1 && num == 1;
286 alias->str = strdup(val);
288 list_add_tail(&alias->list, list);
293 static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FILE *file)
298 ret = fread(buf, 1, sizeof(buf), file);
304 return __perf_pmu__new_alias(list, dir, name, NULL, buf, NULL, NULL, NULL,
308 static inline bool pmu_alias_info_file(char *name)
313 if (len > 5 && !strcmp(name + len - 5, ".unit"))
315 if (len > 6 && !strcmp(name + len - 6, ".scale"))
317 if (len > 8 && !strcmp(name + len - 8, ".per-pkg"))
319 if (len > 9 && !strcmp(name + len - 9, ".snapshot"))
326 * Process all the sysfs attributes located under the directory
327 * specified in 'dir' parameter.
329 static int pmu_aliases_parse(char *dir, struct list_head *head)
331 struct dirent *evt_ent;
334 event_dir = opendir(dir);
338 while ((evt_ent = readdir(event_dir))) {
340 char *name = evt_ent->d_name;
343 if (!strcmp(name, ".") || !strcmp(name, ".."))
347 * skip info files parsed in perf_pmu__new_alias()
349 if (pmu_alias_info_file(name))
352 snprintf(path, PATH_MAX, "%s/%s", dir, name);
354 file = fopen(path, "r");
356 pr_debug("Cannot open %s\n", path);
360 if (perf_pmu__new_alias(head, dir, name, file) < 0)
361 pr_debug("Cannot set up %s\n", name);
370 * Reading the pmu event aliases definition, which should be located at:
371 * /sys/bus/event_source/devices/<dev>/events as sysfs group attributes.
373 static int pmu_aliases(const char *name, struct list_head *head)
377 const char *sysfs = sysfs__mountpoint();
382 snprintf(path, PATH_MAX,
383 "%s/bus/event_source/devices/%s/events", sysfs, name);
385 if (stat(path, &st) < 0)
386 return 0; /* no error if 'events' does not exist */
388 if (pmu_aliases_parse(path, head))
394 static int pmu_alias_terms(struct perf_pmu_alias *alias,
395 struct list_head *terms)
397 struct parse_events_term *term, *cloned;
401 list_for_each_entry(term, &alias->terms, list) {
402 ret = parse_events_term__clone(&cloned, term);
404 parse_events_terms__purge(&list);
407 list_add_tail(&cloned->list, &list);
409 list_splice(&list, terms);
414 * Reading/parsing the default pmu type value, which should be
416 * /sys/bus/event_source/devices/<dev>/type as sysfs attribute.
418 static int pmu_type(const char *name, __u32 *type)
424 const char *sysfs = sysfs__mountpoint();
429 snprintf(path, PATH_MAX,
430 "%s" EVENT_SOURCE_DEVICE_PATH "%s/type", sysfs, name);
432 if (stat(path, &st) < 0)
435 file = fopen(path, "r");
439 if (1 != fscanf(file, "%u", type))
446 /* Add all pmus in sysfs to pmu list: */
447 static void pmu_read_sysfs(void)
452 const char *sysfs = sysfs__mountpoint();
457 snprintf(path, PATH_MAX,
458 "%s" EVENT_SOURCE_DEVICE_PATH, sysfs);
464 while ((dent = readdir(dir))) {
465 if (!strcmp(dent->d_name, ".") || !strcmp(dent->d_name, ".."))
467 /* add to static LIST_HEAD(pmus): */
468 perf_pmu__find(dent->d_name);
474 static struct cpu_map *pmu_cpumask(const char *name)
479 struct cpu_map *cpus;
480 const char *sysfs = sysfs__mountpoint();
481 const char *templates[] = {
482 "%s/bus/event_source/devices/%s/cpumask",
483 "%s/bus/event_source/devices/%s/cpus",
486 const char **template;
491 for (template = templates; *template; template++) {
492 snprintf(path, PATH_MAX, *template, sysfs, name);
493 if (stat(path, &st) == 0)
500 file = fopen(path, "r");
504 cpus = cpu_map__read(file);
510 * Return the CPU id as a raw string.
512 * Each architecture should provide a more precise id string that
513 * can be use to match the architecture's "mapfile".
515 char * __weak get_cpuid_str(void)
520 static char *perf_pmu__getcpuid(void)
525 cpuid = getenv("PERF_CPUID");
527 cpuid = strdup(cpuid);
529 cpuid = get_cpuid_str();
534 pr_debug("Using CPUID %s\n", cpuid);
540 struct pmu_events_map *perf_pmu__find_map(void)
542 struct pmu_events_map *map;
543 char *cpuid = perf_pmu__getcpuid();
548 map = &pmu_events_map[i++];
554 if (!strcmp(map->cpuid, cpuid))
562 * From the pmu_events_map, find the table of PMU events that corresponds
563 * to the current running CPU. Then, add all PMU events from that table
566 static void pmu_add_cpu_aliases(struct list_head *head, const char *name)
569 struct pmu_events_map *map;
570 struct pmu_event *pe;
572 map = perf_pmu__find_map();
577 * Found a matching PMU events table. Create aliases
583 pe = &map->table[i++];
585 if (pe->metric_group || pe->metric_name)
590 pname = pe->pmu ? pe->pmu : "cpu";
591 if (strncmp(pname, name, strlen(pname)))
594 /* need type casts to override 'const' */
595 __perf_pmu__new_alias(head, NULL, (char *)pe->name,
596 (char *)pe->desc, (char *)pe->event,
597 (char *)pe->long_desc, (char *)pe->topic,
598 (char *)pe->unit, (char *)pe->perpkg,
599 (char *)pe->metric_expr,
600 (char *)pe->metric_name);
604 struct perf_event_attr * __weak
605 perf_pmu__get_default_config(struct perf_pmu *pmu __maybe_unused)
610 static struct perf_pmu *pmu_lookup(const char *name)
612 struct perf_pmu *pmu;
618 * The pmu data we store & need consists of the pmu
619 * type value and format definitions. Load both right
622 if (pmu_format(name, &format))
626 * Check the type first to avoid unnecessary work.
628 if (pmu_type(name, &type))
631 if (pmu_aliases(name, &aliases))
634 pmu_add_cpu_aliases(&aliases, name);
635 pmu = zalloc(sizeof(*pmu));
639 pmu->cpus = pmu_cpumask(name);
641 INIT_LIST_HEAD(&pmu->format);
642 INIT_LIST_HEAD(&pmu->aliases);
643 list_splice(&format, &pmu->format);
644 list_splice(&aliases, &pmu->aliases);
645 pmu->name = strdup(name);
647 list_add_tail(&pmu->list, &pmus);
649 pmu->default_config = perf_pmu__get_default_config(pmu);
654 static struct perf_pmu *pmu_find(const char *name)
656 struct perf_pmu *pmu;
658 list_for_each_entry(pmu, &pmus, list)
659 if (!strcmp(pmu->name, name))
665 struct perf_pmu *perf_pmu__scan(struct perf_pmu *pmu)
668 * pmu iterator: If pmu is NULL, we start at the begin,
669 * otherwise return the next pmu. Returns NULL on end.
673 pmu = list_prepare_entry(pmu, &pmus, list);
675 list_for_each_entry_continue(pmu, &pmus, list)
680 struct perf_pmu *perf_pmu__find(const char *name)
682 struct perf_pmu *pmu;
685 * Once PMU is loaded it stays in the list,
686 * so we keep us from multiple reading/parsing
687 * the pmu format definitions.
689 pmu = pmu_find(name);
693 return pmu_lookup(name);
696 static struct perf_pmu_format *
697 pmu_find_format(struct list_head *formats, const char *name)
699 struct perf_pmu_format *format;
701 list_for_each_entry(format, formats, list)
702 if (!strcmp(format->name, name))
708 __u64 perf_pmu__format_bits(struct list_head *formats, const char *name)
710 struct perf_pmu_format *format = pmu_find_format(formats, name);
717 for_each_set_bit(fbit, format->bits, PERF_PMU_FORMAT_BITS)
718 bits |= 1ULL << fbit;
724 * Sets value based on the format definition (format parameter)
725 * and unformated value (value parameter).
727 static void pmu_format_value(unsigned long *format, __u64 value, __u64 *v,
730 unsigned long fbit, vbit;
732 for (fbit = 0, vbit = 0; fbit < PERF_PMU_FORMAT_BITS; fbit++) {
734 if (!test_bit(fbit, format))
737 if (value & (1llu << vbit++))
738 *v |= (1llu << fbit);
740 *v &= ~(1llu << fbit);
744 static __u64 pmu_format_max_value(const unsigned long *format)
749 for_each_set_bit(fbit, format, PERF_PMU_FORMAT_BITS)
756 * Term is a string term, and might be a param-term. Try to look up it's value
757 * in the remaining terms.
758 * - We have a term like "base-or-format-term=param-term",
759 * - We need to find the value supplied for "param-term" (with param-term named
760 * in a config string) later on in the term list.
762 static int pmu_resolve_param_term(struct parse_events_term *term,
763 struct list_head *head_terms,
766 struct parse_events_term *t;
768 list_for_each_entry(t, head_terms, list) {
769 if (t->type_val == PARSE_EVENTS__TERM_TYPE_NUM) {
770 if (!strcmp(t->config, term->config)) {
779 printf("Required parameter '%s' not specified\n", term->config);
784 static char *pmu_formats_string(struct list_head *formats)
786 struct perf_pmu_format *format;
788 struct strbuf buf = STRBUF_INIT;
794 /* sysfs exported terms */
795 list_for_each_entry(format, formats, list)
796 if (strbuf_addf(&buf, i++ ? ",%s" : "%s", format->name) < 0)
799 str = strbuf_detach(&buf, NULL);
801 strbuf_release(&buf);
807 * Setup one of config[12] attr members based on the
808 * user input data - term parameter.
810 static int pmu_config_term(struct list_head *formats,
811 struct perf_event_attr *attr,
812 struct parse_events_term *term,
813 struct list_head *head_terms,
814 bool zero, struct parse_events_error *err)
816 struct perf_pmu_format *format;
821 * If this is a parameter we've already used for parameterized-eval,
822 * skip it in normal eval.
828 * Hardcoded terms should be already in, so nothing
829 * to be done for them.
831 if (parse_events__is_hardcoded_term(term))
834 format = pmu_find_format(formats, term->config);
837 printf("Invalid event/parameter '%s'\n", term->config);
839 char *pmu_term = pmu_formats_string(formats);
841 err->idx = term->err_term;
842 err->str = strdup("unknown term");
843 err->help = parse_events_formats_error_string(pmu_term);
849 switch (format->value) {
850 case PERF_PMU_FORMAT_VALUE_CONFIG:
853 case PERF_PMU_FORMAT_VALUE_CONFIG1:
856 case PERF_PMU_FORMAT_VALUE_CONFIG2:
864 * Either directly use a numeric term, or try to translate string terms
865 * using event parameters.
867 if (term->type_val == PARSE_EVENTS__TERM_TYPE_NUM) {
868 if (term->no_value &&
869 bitmap_weight(format->bits, PERF_PMU_FORMAT_BITS) > 1) {
871 err->idx = term->err_val;
872 err->str = strdup("no value assigned for term");
878 } else if (term->type_val == PARSE_EVENTS__TERM_TYPE_STR) {
879 if (strcmp(term->val.str, "?")) {
881 pr_info("Invalid sysfs entry %s=%s\n",
882 term->config, term->val.str);
885 err->idx = term->err_val;
886 err->str = strdup("expected numeric value");
891 if (pmu_resolve_param_term(term, head_terms, &val))
896 max_val = pmu_format_max_value(format->bits);
899 err->idx = term->err_val;
900 if (asprintf(&err->str,
901 "value too big for format, maximum is %llu",
902 (unsigned long long)max_val) < 0)
903 err->str = strdup("value too big for format");
907 * Assume we don't care if !err, in which case the value will be
908 * silently truncated.
912 pmu_format_value(format->bits, val, vp, zero);
916 int perf_pmu__config_terms(struct list_head *formats,
917 struct perf_event_attr *attr,
918 struct list_head *head_terms,
919 bool zero, struct parse_events_error *err)
921 struct parse_events_term *term;
923 list_for_each_entry(term, head_terms, list) {
924 if (pmu_config_term(formats, attr, term, head_terms,
933 * Configures event's 'attr' parameter based on the:
934 * 1) users input - specified in terms parameter
935 * 2) pmu format definitions - specified by pmu parameter
937 int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr,
938 struct list_head *head_terms,
939 struct parse_events_error *err)
941 bool zero = !!pmu->default_config;
943 attr->type = pmu->type;
944 return perf_pmu__config_terms(&pmu->format, attr, head_terms,
948 static struct perf_pmu_alias *pmu_find_alias(struct perf_pmu *pmu,
949 struct parse_events_term *term)
951 struct perf_pmu_alias *alias;
954 if (parse_events__is_hardcoded_term(term))
957 if (term->type_val == PARSE_EVENTS__TERM_TYPE_NUM) {
958 if (term->val.num != 1)
960 if (pmu_find_format(&pmu->format, term->config))
963 } else if (term->type_val == PARSE_EVENTS__TERM_TYPE_STR) {
964 if (strcasecmp(term->config, "event"))
966 name = term->val.str;
971 list_for_each_entry(alias, &pmu->aliases, list) {
972 if (!strcasecmp(alias->name, name))
979 static int check_info_data(struct perf_pmu_alias *alias,
980 struct perf_pmu_info *info)
983 * Only one term in event definition can
984 * define unit, scale and snapshot, fail
985 * if there's more than one.
987 if ((info->unit && alias->unit[0]) ||
988 (info->scale && alias->scale) ||
989 (info->snapshot && alias->snapshot))
993 info->unit = alias->unit;
996 info->scale = alias->scale;
999 info->snapshot = alias->snapshot;
1005 * Find alias in the terms list and replace it with the terms
1006 * defined for the alias
1008 int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms,
1009 struct perf_pmu_info *info)
1011 struct parse_events_term *term, *h;
1012 struct perf_pmu_alias *alias;
1015 info->per_pkg = false;
1018 * Mark unit and scale as not set
1019 * (different from default values, see below)
1023 info->snapshot = false;
1024 info->metric_expr = NULL;
1025 info->metric_name = NULL;
1027 list_for_each_entry_safe(term, h, head_terms, list) {
1028 alias = pmu_find_alias(pmu, term);
1031 ret = pmu_alias_terms(alias, &term->list);
1035 ret = check_info_data(alias, info);
1040 info->per_pkg = true;
1041 info->metric_expr = alias->metric_expr;
1042 info->metric_name = alias->metric_name;
1044 list_del(&term->list);
1049 * if no unit or scale foundin aliases, then
1050 * set defaults as for evsel
1051 * unit cannot left to NULL
1053 if (info->unit == NULL)
1056 if (info->scale == 0.0)
1062 int perf_pmu__new_format(struct list_head *list, char *name,
1063 int config, unsigned long *bits)
1065 struct perf_pmu_format *format;
1067 format = zalloc(sizeof(*format));
1071 format->name = strdup(name);
1072 format->value = config;
1073 memcpy(format->bits, bits, sizeof(format->bits));
1075 list_add_tail(&format->list, list);
1079 void perf_pmu__set_format(unsigned long *bits, long from, long to)
1086 memset(bits, 0, BITS_TO_BYTES(PERF_PMU_FORMAT_BITS));
1087 for (b = from; b <= to; b++)
1091 static int sub_non_neg(int a, int b)
1098 static char *format_alias(char *buf, int len, struct perf_pmu *pmu,
1099 struct perf_pmu_alias *alias)
1101 struct parse_events_term *term;
1102 int used = snprintf(buf, len, "%s/%s", pmu->name, alias->name);
1104 list_for_each_entry(term, &alias->terms, list) {
1105 if (term->type_val == PARSE_EVENTS__TERM_TYPE_STR)
1106 used += snprintf(buf + used, sub_non_neg(len, used),
1107 ",%s=%s", term->config,
1111 if (sub_non_neg(len, used) > 0) {
1115 if (sub_non_neg(len, used) > 0) {
1119 buf[len - 1] = '\0';
1124 static char *format_alias_or(char *buf, int len, struct perf_pmu *pmu,
1125 struct perf_pmu_alias *alias)
1127 snprintf(buf, len, "%s OR %s/%s/", alias->name, pmu->name, alias->name);
1141 static int cmp_sevent(const void *a, const void *b)
1143 const struct sevent *as = a;
1144 const struct sevent *bs = b;
1146 /* Put extra events last */
1147 if (!!as->desc != !!bs->desc)
1148 return !!as->desc - !!bs->desc;
1149 if (as->topic && bs->topic) {
1150 int n = strcmp(as->topic, bs->topic);
1155 return strcmp(as->name, bs->name);
1158 static void wordwrap(char *s, int start, int max, int corr)
1164 int wlen = strcspn(s, " \t");
1166 if (column + wlen >= max && column > start) {
1167 printf("\n%*s", start, "");
1168 column = start + corr;
1170 n = printf("%s%.*s", column > start ? " " : "", wlen, s);
1179 void print_pmu_events(const char *event_glob, bool name_only, bool quiet_flag,
1180 bool long_desc, bool details_flag)
1182 struct perf_pmu *pmu;
1183 struct perf_pmu_alias *alias;
1187 struct sevent *aliases;
1189 int columns = pager_get_columns();
1194 while ((pmu = perf_pmu__scan(pmu)) != NULL) {
1195 list_for_each_entry(alias, &pmu->aliases, list)
1197 if (pmu->selectable)
1200 aliases = zalloc(sizeof(struct sevent) * len);
1205 while ((pmu = perf_pmu__scan(pmu)) != NULL) {
1206 list_for_each_entry(alias, &pmu->aliases, list) {
1207 char *name = alias->desc ? alias->name :
1208 format_alias(buf, sizeof(buf), pmu, alias);
1209 bool is_cpu = !strcmp(pmu->name, "cpu");
1211 if (event_glob != NULL &&
1212 !(strglobmatch_nocase(name, event_glob) ||
1213 (!is_cpu && strglobmatch_nocase(alias->name,
1216 strglobmatch_nocase(alias->topic, event_glob))))
1219 if (is_cpu && !name_only && !alias->desc)
1220 name = format_alias_or(buf, sizeof(buf), pmu, alias);
1222 aliases[j].name = name;
1223 if (is_cpu && !name_only && !alias->desc)
1224 aliases[j].name = format_alias_or(buf,
1227 aliases[j].name = strdup(aliases[j].name);
1228 if (!aliases[j].name)
1231 aliases[j].desc = long_desc ? alias->long_desc :
1233 aliases[j].topic = alias->topic;
1234 aliases[j].str = alias->str;
1235 aliases[j].pmu = pmu->name;
1236 aliases[j].metric_expr = alias->metric_expr;
1237 aliases[j].metric_name = alias->metric_name;
1240 if (pmu->selectable &&
1241 (event_glob == NULL || strglobmatch(pmu->name, event_glob))) {
1243 if (asprintf(&s, "%s//", pmu->name) < 0)
1245 aliases[j].name = s;
1250 qsort(aliases, len, sizeof(struct sevent), cmp_sevent);
1251 for (j = 0; j < len; j++) {
1252 /* Skip duplicates */
1253 if (j > 0 && !strcmp(aliases[j].name, aliases[j - 1].name))
1256 printf("%s ", aliases[j].name);
1259 if (aliases[j].desc && !quiet_flag) {
1262 if (aliases[j].topic && (!topic ||
1263 strcmp(topic, aliases[j].topic))) {
1264 printf("%s%s:\n", topic ? "\n" : "",
1266 topic = aliases[j].topic;
1268 printf(" %-50s\n", aliases[j].name);
1269 printf("%*s", 8, "[");
1270 wordwrap(aliases[j].desc, 8, columns, 0);
1273 printf("%*s%s/%s/ ", 8, "", aliases[j].pmu, aliases[j].str);
1274 if (aliases[j].metric_name)
1275 printf(" MetricName: %s", aliases[j].metric_name);
1276 if (aliases[j].metric_expr)
1277 printf(" MetricExpr: %s", aliases[j].metric_expr);
1281 printf(" %-50s [Kernel PMU event]\n", aliases[j].name);
1284 if (printed && pager_in_use())
1287 for (j = 0; j < len; j++)
1288 zfree(&aliases[j].name);
1293 printf("FATAL: not enough memory to print PMU events\n");
1298 bool pmu_have_event(const char *pname, const char *name)
1300 struct perf_pmu *pmu;
1301 struct perf_pmu_alias *alias;
1304 while ((pmu = perf_pmu__scan(pmu)) != NULL) {
1305 if (strcmp(pname, pmu->name))
1307 list_for_each_entry(alias, &pmu->aliases, list)
1308 if (!strcmp(alias->name, name))
1314 static FILE *perf_pmu__open_file(struct perf_pmu *pmu, const char *name)
1317 char path[PATH_MAX];
1320 sysfs = sysfs__mountpoint();
1324 snprintf(path, PATH_MAX,
1325 "%s" EVENT_SOURCE_DEVICE_PATH "%s/%s", sysfs, pmu->name, name);
1327 if (stat(path, &st) < 0)
1330 return fopen(path, "r");
1333 int perf_pmu__scan_file(struct perf_pmu *pmu, const char *name, const char *fmt,
1340 va_start(args, fmt);
1341 file = perf_pmu__open_file(pmu, name);
1343 ret = vfscanf(file, fmt, args);