diff options
Diffstat (limited to 'tools/perf/util/pmu.c')
-rw-r--r-- | tools/perf/util/pmu.c | 87 |
1 files changed, 80 insertions, 7 deletions
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 4c6f9c490a8d..bc9d8069d376 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c | |||
@@ -73,7 +73,7 @@ int perf_pmu__format_parse(char *dir, struct list_head *head) | |||
73 | * located at: | 73 | * located at: |
74 | * /sys/bus/event_source/devices/<dev>/format as sysfs group attributes. | 74 | * /sys/bus/event_source/devices/<dev>/format as sysfs group attributes. |
75 | */ | 75 | */ |
76 | static int pmu_format(char *name, struct list_head *format) | 76 | static int pmu_format(const char *name, struct list_head *format) |
77 | { | 77 | { |
78 | struct stat st; | 78 | struct stat st; |
79 | char path[PATH_MAX]; | 79 | char path[PATH_MAX]; |
@@ -162,7 +162,7 @@ static int pmu_aliases_parse(char *dir, struct list_head *head) | |||
162 | * Reading the pmu event aliases definition, which should be located at: | 162 | * Reading the pmu event aliases definition, which should be located at: |
163 | * /sys/bus/event_source/devices/<dev>/events as sysfs group attributes. | 163 | * /sys/bus/event_source/devices/<dev>/events as sysfs group attributes. |
164 | */ | 164 | */ |
165 | static int pmu_aliases(char *name, struct list_head *head) | 165 | static int pmu_aliases(const char *name, struct list_head *head) |
166 | { | 166 | { |
167 | struct stat st; | 167 | struct stat st; |
168 | char path[PATH_MAX]; | 168 | char path[PATH_MAX]; |
@@ -208,7 +208,7 @@ static int pmu_alias_terms(struct perf_pmu_alias *alias, | |||
208 | * located at: | 208 | * located at: |
209 | * /sys/bus/event_source/devices/<dev>/type as sysfs attribute. | 209 | * /sys/bus/event_source/devices/<dev>/type as sysfs attribute. |
210 | */ | 210 | */ |
211 | static int pmu_type(char *name, __u32 *type) | 211 | static int pmu_type(const char *name, __u32 *type) |
212 | { | 212 | { |
213 | struct stat st; | 213 | struct stat st; |
214 | char path[PATH_MAX]; | 214 | char path[PATH_MAX]; |
@@ -266,7 +266,7 @@ static void pmu_read_sysfs(void) | |||
266 | closedir(dir); | 266 | closedir(dir); |
267 | } | 267 | } |
268 | 268 | ||
269 | static struct cpu_map *pmu_cpumask(char *name) | 269 | static struct cpu_map *pmu_cpumask(const char *name) |
270 | { | 270 | { |
271 | struct stat st; | 271 | struct stat st; |
272 | char path[PATH_MAX]; | 272 | char path[PATH_MAX]; |
@@ -293,7 +293,7 @@ static struct cpu_map *pmu_cpumask(char *name) | |||
293 | return cpus; | 293 | return cpus; |
294 | } | 294 | } |
295 | 295 | ||
296 | static struct perf_pmu *pmu_lookup(char *name) | 296 | static struct perf_pmu *pmu_lookup(const char *name) |
297 | { | 297 | { |
298 | struct perf_pmu *pmu; | 298 | struct perf_pmu *pmu; |
299 | LIST_HEAD(format); | 299 | LIST_HEAD(format); |
@@ -330,7 +330,7 @@ static struct perf_pmu *pmu_lookup(char *name) | |||
330 | return pmu; | 330 | return pmu; |
331 | } | 331 | } |
332 | 332 | ||
333 | static struct perf_pmu *pmu_find(char *name) | 333 | static struct perf_pmu *pmu_find(const char *name) |
334 | { | 334 | { |
335 | struct perf_pmu *pmu; | 335 | struct perf_pmu *pmu; |
336 | 336 | ||
@@ -356,7 +356,7 @@ struct perf_pmu *perf_pmu__scan(struct perf_pmu *pmu) | |||
356 | return NULL; | 356 | return NULL; |
357 | } | 357 | } |
358 | 358 | ||
359 | struct perf_pmu *perf_pmu__find(char *name) | 359 | struct perf_pmu *perf_pmu__find(const char *name) |
360 | { | 360 | { |
361 | struct perf_pmu *pmu; | 361 | struct perf_pmu *pmu; |
362 | 362 | ||
@@ -564,3 +564,76 @@ void perf_pmu__set_format(unsigned long *bits, long from, long to) | |||
564 | for (b = from; b <= to; b++) | 564 | for (b = from; b <= to; b++) |
565 | set_bit(b, bits); | 565 | set_bit(b, bits); |
566 | } | 566 | } |
567 | |||
568 | static char *format_alias(char *buf, int len, struct perf_pmu *pmu, | ||
569 | struct perf_pmu_alias *alias) | ||
570 | { | ||
571 | snprintf(buf, len, "%s/%s/", pmu->name, alias->name); | ||
572 | return buf; | ||
573 | } | ||
574 | |||
575 | static char *format_alias_or(char *buf, int len, struct perf_pmu *pmu, | ||
576 | struct perf_pmu_alias *alias) | ||
577 | { | ||
578 | snprintf(buf, len, "%s OR %s/%s/", alias->name, pmu->name, alias->name); | ||
579 | return buf; | ||
580 | } | ||
581 | |||
582 | static int cmp_string(const void *a, const void *b) | ||
583 | { | ||
584 | const char * const *as = a; | ||
585 | const char * const *bs = b; | ||
586 | return strcmp(*as, *bs); | ||
587 | } | ||
588 | |||
589 | void print_pmu_events(const char *event_glob, bool name_only) | ||
590 | { | ||
591 | struct perf_pmu *pmu; | ||
592 | struct perf_pmu_alias *alias; | ||
593 | char buf[1024]; | ||
594 | int printed = 0; | ||
595 | int len, j; | ||
596 | char **aliases; | ||
597 | |||
598 | pmu = NULL; | ||
599 | len = 0; | ||
600 | while ((pmu = perf_pmu__scan(pmu)) != NULL) | ||
601 | list_for_each_entry(alias, &pmu->aliases, list) | ||
602 | len++; | ||
603 | aliases = malloc(sizeof(char *) * len); | ||
604 | if (!aliases) | ||
605 | return; | ||
606 | pmu = NULL; | ||
607 | j = 0; | ||
608 | while ((pmu = perf_pmu__scan(pmu)) != NULL) | ||
609 | list_for_each_entry(alias, &pmu->aliases, list) { | ||
610 | char *name = format_alias(buf, sizeof(buf), pmu, alias); | ||
611 | bool is_cpu = !strcmp(pmu->name, "cpu"); | ||
612 | |||
613 | if (event_glob != NULL && | ||
614 | !(strglobmatch(name, event_glob) || | ||
615 | (!is_cpu && strglobmatch(alias->name, | ||
616 | event_glob)))) | ||
617 | continue; | ||
618 | aliases[j] = name; | ||
619 | if (is_cpu && !name_only) | ||
620 | aliases[j] = format_alias_or(buf, sizeof(buf), | ||
621 | pmu, alias); | ||
622 | aliases[j] = strdup(aliases[j]); | ||
623 | j++; | ||
624 | } | ||
625 | len = j; | ||
626 | qsort(aliases, len, sizeof(char *), cmp_string); | ||
627 | for (j = 0; j < len; j++) { | ||
628 | if (name_only) { | ||
629 | printf("%s ", aliases[j]); | ||
630 | continue; | ||
631 | } | ||
632 | printf(" %-50s [Kernel PMU event]\n", aliases[j]); | ||
633 | free(aliases[j]); | ||
634 | printed++; | ||
635 | } | ||
636 | if (printed) | ||
637 | printf("\n"); | ||
638 | free(aliases); | ||
639 | } | ||