aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorMatt Fleming <matt.fleming@intel.com>2014-09-24 10:04:06 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2014-09-29 14:03:57 -0400
commit46441bdc76fee08e297ebcf17e4ca91013b1ee9e (patch)
tree21787b6918ed42578cf673d284d119585bfb6ace /tools
parent07394b5f13a04f86b27e0ddd96a36c7d9bfe1a4f (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')
-rw-r--r--tools/perf/util/parse-events.c9
-rw-r--r--tools/perf/util/pmu.c38
-rw-r--r--tools/perf/util/pmu.h7
3 files changed, 33 insertions, 21 deletions
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 61be3e695ec2..9522cf22ad81 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -634,10 +634,9 @@ int parse_events_add_pmu(struct list_head *list, int *idx,
634 char *name, struct list_head *head_config) 634 char *name, struct list_head *head_config)
635{ 635{
636 struct perf_event_attr attr; 636 struct perf_event_attr attr;
637 struct perf_pmu_info info;
637 struct perf_pmu *pmu; 638 struct perf_pmu *pmu;
638 struct perf_evsel *evsel; 639 struct perf_evsel *evsel;
639 const char *unit;
640 double scale;
641 640
642 pmu = perf_pmu__find(name); 641 pmu = perf_pmu__find(name);
643 if (!pmu) 642 if (!pmu)
@@ -656,7 +655,7 @@ int parse_events_add_pmu(struct list_head *list, int *idx,
656 return evsel ? 0 : -ENOMEM; 655 return evsel ? 0 : -ENOMEM;
657 } 656 }
658 657
659 if (perf_pmu__check_alias(pmu, head_config, &unit, &scale)) 658 if (perf_pmu__check_alias(pmu, head_config, &info))
660 return -EINVAL; 659 return -EINVAL;
661 660
662 /* 661 /*
@@ -671,8 +670,8 @@ int parse_events_add_pmu(struct list_head *list, int *idx,
671 evsel = __add_event(list, idx, &attr, pmu_event_name(head_config), 670 evsel = __add_event(list, idx, &attr, pmu_event_name(head_config),
672 pmu->cpus); 671 pmu->cpus);
673 if (evsel) { 672 if (evsel) {
674 evsel->unit = unit; 673 evsel->unit = info.unit;
675 evsel->scale = scale; 674 evsel->scale = info.scale;
676 } 675 }
677 676
678 return evsel ? 0 : -ENOMEM; 677 return evsel ? 0 : -ENOMEM;
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
213static 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 */
647int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms, 655int 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}
diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h
index 0f5c0a88fdc8..fe90a012c003 100644
--- a/tools/perf/util/pmu.h
+++ b/tools/perf/util/pmu.h
@@ -25,6 +25,11 @@ struct perf_pmu {
25 struct list_head list; /* ELEM */ 25 struct list_head list; /* ELEM */
26}; 26};
27 27
28struct perf_pmu_info {
29 const char *unit;
30 double scale;
31};
32
28struct perf_pmu *perf_pmu__find(const char *name); 33struct perf_pmu *perf_pmu__find(const char *name);
29int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr, 34int perf_pmu__config(struct perf_pmu *pmu, struct perf_event_attr *attr,
30 struct list_head *head_terms); 35 struct list_head *head_terms);
@@ -33,7 +38,7 @@ int perf_pmu__config_terms(struct list_head *formats,
33 struct list_head *head_terms, 38 struct list_head *head_terms,
34 bool zero); 39 bool zero);
35int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms, 40int perf_pmu__check_alias(struct perf_pmu *pmu, struct list_head *head_terms,
36 const char **unit, double *scale); 41 struct perf_pmu_info *info);
37struct list_head *perf_pmu__alias(struct perf_pmu *pmu, 42struct list_head *perf_pmu__alias(struct perf_pmu *pmu,
38 struct list_head *head_terms); 43 struct list_head *head_terms);
39int perf_pmu_wrap(void); 44int perf_pmu_wrap(void);