perf metric: Code cleanup with map_for_each_event()
PATCH v2 1/1 perf metric: Code cleanup with map_for_each_event()
Since we have introduced map_for_each_event() to walk the 'pmu_events_map', clean up metricgroup__print() and metricgroup__has_metric() with it.
Signed-off-by Wei Li <[email protected]>
Acked-by Namhyung Kim <[email protected]>
---
v1 -> v2:
- Move map_for_each_metric() after match_metric() to avoid potential use-before-declare.
--- tools/perf/util/metricgroup.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-)
tools/perf/util/metricgroup.c +13 -20
@@ -374,6 +374,17 @@ static bool match_metric(const char *n, const char *list)return false; } +#define map_for_each_event (__pe, __idx, __map) \ + for (__idx = 0, __pe = &__map->table[__idx]; \ + __pe->name || __pe->metric_group || __pe->metric_name; \ + __pe = &__map->table[++__idx]) + +#define map_for_each_metric (__pe, __idx, __map, __metric) \ + map_for_each_event(__pe, __idx, __map) \ + if (__pe->metric_expr && \ + (match_metric(__pe->metric_group, __metric) || \ + match_metric(__pe->metric_name, __metric))) +struct mep {struct rb_node nd;const char *name;
@@ -475,12 +486,9 @@ void metricgroup__print(bool metrics, bool metricgroups, char *filter, groups.node_new = mep_new; groups.node_cmp = mep_cmp; groups.node_delete = mep_delete; -for (i =0 ; ; i++) { +map_for_each_event (pe, i, map) {const char *g; - pe = &map->table[i]; -if (!pe->name && !pe->metric_group && !pe->metric_name) -break ;if (!pe->metric_expr)continue ; g = pe->metric_group;
@@ -745,17 +753,6 @@ static int __add_metric(struct list_head *metric_list,return 0 ; } -#define map_for_each_event (__pe, __idx, __map) \ - for (__idx = 0, __pe = &__map->table[__idx]; \ - __pe->name || __pe->metric_group || __pe->metric_name; \ - __pe = &__map->table[++__idx]) - -#define map_for_each_metric (__pe, __idx, __map, __metric) \ - map_for_each_event(__pe, __idx, __map) \ - if (__pe->metric_expr && \ - (match_metric(__pe->metric_group, __metric) || \ - match_metric(__pe->metric_name, __metric))) -static struct pmu_event *find_metric (const char *metric,struct pmu_events_map *map) {struct pmu_event *pe;
@@ -1092,11 +1089,7 @@ bool metricgroup__has_metric(const char *metric)if (!map)return false; -for (i =0 ; ; i++) { - pe = &map->table[i]; - -if (!pe->name && !pe->metric_group && !pe->metric_name) -break ; +map_for_each_event (pe, i, map) {if (!pe->metric_expr)continue ;if (match_metric (pe->metric_name, metric))
Signature · 1 line
2.17.1
Quoted 5 lines · Wei Li
Since we have introduced
map_for_each_event()to walk the 'pmu_events_map', clean upmetricgroup__print()andmetricgroup__has_metric()with it.Signed-off-by Wei Li <[email protected]>Acked-by Namhyung Kim <[email protected]>
Acked-by Jiri Olsa <[email protected]>
thanks,
jirka
Quoted 78 lines
---
v1 -> v2:
- Movemap_for_each_metric()aftermatch_metric()to avoid potential use-before-declare.--- tools/perf/util/metricgroup.c | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-)tools/perf/util/metricgroup.c +13
-20@@ -374,6 +374,17 @@ static bool match_metric(const char *n, const char *list)return false; } +#define map_for_each_event (__pe, __idx, __map) \ + for (__idx = 0, __pe = &__map->table[__idx]; \ + __pe->name || __pe->metric_group || __pe->metric_name; \ + __pe = &__map->table[++__idx]) + +#define map_for_each_metric (__pe, __idx, __map, __metric) \ + map_for_each_event(__pe, __idx, __map) \ + if (__pe->metric_expr && \ + (match_metric(__pe->metric_group, __metric) || \ + match_metric(__pe->metric_name, __metric))) +struct mep {struct rb_node nd;const char *name;@@ -475,12 +486,9 @@ void metricgroup__print(bool metrics, bool metricgroups, char *filter, groups.node_new = mep_new; groups.node_cmp = mep_cmp; groups.node_delete = mep_delete; -for (i =0 ; ; i++) { +map_for_each_event (pe, i, map) {const char *g; - pe = &map->table[i]; -if (!pe->name && !pe->metric_group && !pe->metric_name) -break ;if (!pe->metric_expr)continue ; g = pe->metric_group;@@ -745,17 +753,6 @@ static int __add_metric(struct list_head *metric_list,return 0 ; } -#define map_for_each_event (__pe, __idx, __map) \ - for (__idx = 0, __pe = &__map->table[__idx]; \ - __pe->name || __pe->metric_group || __pe->metric_name; \ - __pe = &__map->table[++__idx]) - -#define map_for_each_metric (__pe, __idx, __map, __metric) \ - map_for_each_event(__pe, __idx, __map) \ - if (__pe->metric_expr && \ - (match_metric(__pe->metric_group, __metric) || \ - match_metric(__pe->metric_name, __metric))) -static struct pmu_event *find_metric (const char *metric,struct pmu_events_map *map) {struct pmu_event *pe;@@ -1092,11 +1089,7 @@ bool metricgroup__has_metric(const char *metric)if (!map)return false; -for (i =0 ; ; i++) { - pe = &map->table[i]; - -if (!pe->name && !pe->metric_group && !pe->metric_name) -break ; +map_for_each_event (pe, i, map) {if (!pe->metric_expr)continue ;if (match_metric (pe->metric_name, metric))Signature · 1 line
2.17.1