diff options
author | Matt Fleming <matt.fleming@intel.com> | 2014-09-24 10:04:06 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2014-09-29 14:03:57 -0400 |
commit | 46441bdc76fee08e297ebcf17e4ca91013b1ee9e (patch) | |
tree | 21787b6918ed42578cf673d284d119585bfb6ace /tools/perf/util/pmu.c | |
parent | 07394b5f13a04f86b27e0ddd96a36c7d9bfe1a4f (diff) |
perf tools: Refactor unit and scale function parameters
Passing pointers to alias modifiers 'unit' and 'scale' isn't very
future-proof since if we add more modifiers to the list we'll end up
passing more arguments.
Instead wrap everything up in a struct perf_pmu_info, which can easily
be expanded when additional alias modifiers are necessary in the future.
Signed-off-by: Matt Fleming <matt.fleming@intel.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1411567455-31264-3-git-send-email-matt@console-pimps.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/pmu.c')
-rw-r--r-- | tools/perf/util/pmu.c | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c index 22a4ad5a927a..93a41ca96b8e 100644 --- a/tools/perf/util/pmu.c +++ b/tools/perf/util/pmu.c | |||
@@ -210,6 +210,19 @@ static int perf_pmu__new_alias(struct list_head *list, char *dir, char *name, FI | |||
210 | return 0; | 210 | return 0; |
211 | } | 211 | } |
212 | 212 | ||
213 | static inline bool pmu_alias_info_file(char *name) | ||
214 | { | ||
215 | size_t len; | ||
216 | |||
217 | len = strlen(name); | ||
218 | if (len > 5 && !strcmp(name + len - 5, ".unit")) | ||
219 | return true; | ||
220 | if (len > 6 && !strcmp(name + len - 6, ".scale")) | ||
221 | return true; | ||
222 | |||
223 | return false; | ||
224 | } | ||
225 | |||
213 | /* | 226 | /* |
214 | * Process all the sysfs attributes located under the directory | 227 | * Process all the sysfs attributes located under the directory |
215 | * specified in 'dir' parameter. | 228 | * specified in 'dir' parameter. |
@@ -218,7 +231,6 @@ static int pmu_aliases_parse(char *dir, struct list_head *head) | |||
218 | { | 231 | { |
219 | struct dirent *evt_ent; | 232 | struct dirent *evt_ent; |
220 | DIR *event_dir; | 233 | DIR *event_dir; |
221 | size_t len; | ||
222 | int ret = 0; | 234 | int ret = 0; |
223 | 235 | ||
224 | event_dir = opendir(dir); | 236 | event_dir = opendir(dir); |
@@ -234,13 +246,9 @@ static int pmu_aliases_parse(char *dir, struct list_head *head) | |||
234 | continue; | 246 | continue; |
235 | 247 | ||
236 | /* | 248 | /* |
237 | * skip .unit and .scale info files | 249 | * skip info files parsed in perf_pmu__new_alias() |
238 | * parsed in perf_pmu__new_alias() | ||
239 | */ | 250 | */ |
240 | len = strlen(name); | 251 | if (pmu_alias_info_file(name)) |
241 | if (len > 5 && !strcmp(name + len - 5, ".unit")) | ||
242 | continue; | ||
243 | if (len > 6 && !strcmp(name + len - 6, ".scale")) | ||
244 | continue; | 252 | continue; |
245 | 253 | ||
246 | snprintf(path, PATH_MAX, "%s/%s", dir, name); | 254 | snprintf(path, PATH_MAX, "%s/%s", dir, name); |
@@ -645,7 +653,7 @@ static int check_unit_scale(struct perf_pmu_alias *alias, | |||
645 | * defined for the alias | 653 | * defined for the alias |
646 | */ | 654 | */ |
647 | int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms, | 655 | int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms, |
648 | const char **unit, double *scale) | 656 | struct perf_pmu_info *info) |
649 | { | 657 | { |
650 | struct parse_events_term *term, *h; | 658 | struct parse_events_term *term, *h; |
651 | struct perf_pmu_alias *alias; | 659 | struct perf_pmu_alias *alias; |
@@ -655,8 +663,8 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms, | |||
655 | * Mark unit and scale as not set | 663 | * Mark unit and scale as not set |
656 | * (different from default values, see below) | 664 | * (different from default values, see below) |
657 | */ | 665 | */ |
658 | *unit = NULL; | 666 | info->unit = NULL; |
659 | *scale = 0.0; | 667 | info->scale = 0.0; |
660 | 668 | ||
661 | list_for_each_entry_safe(term, h, head_terms, list) { | 669 | list_for_each_entry_safe(term, h, head_terms, list) { |
662 | alias = pmu_find_alias(pmu, term); | 670 | alias = pmu_find_alias(pmu, term); |
@@ -666,7 +674,7 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms, | |||
666 | if (ret) | 674 | if (ret) |
667 | return ret; | 675 | return ret; |
668 | 676 | ||
669 | ret = check_unit_scale(alias, unit, scale); | 677 | ret = check_unit_scale(alias, &info->unit, &info->scale); |
670 | if (ret) | 678 | if (ret) |
671 | return ret; | 679 | return ret; |
672 | 680 | ||
@@ -679,11 +687,11 @@ int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms, | |||
679 | * set defaults as for evsel | 687 | * set defaults as for evsel |
680 | * unit cannot left to NULL | 688 | * unit cannot left to NULL |
681 | */ | 689 | */ |
682 | if (*unit == NULL) | 690 | if (info->unit == NULL) |
683 | *unit = ""; | 691 | info->unit = ""; |
684 | 692 | ||
685 | if (*scale == 0.0) | 693 | if (info->scale == 0.0) |
686 | *scale = 1.0; | 694 | info->scale = 1.0; |
687 | 695 | ||
688 | return 0; | 696 | return 0; |
689 | } | 697 | } |