@@ -415,6 +415,12 @@ static bool match_metric(const char *n, const char *list)
415
415
return false;
416
416
}
417
417
418
+ static bool match_pe_metric (struct pmu_event * pe , const char * metric )
419
+ {
420
+ return match_metric (pe -> metric_group , metric ) ||
421
+ match_metric (pe -> metric_name , metric );
422
+ }
423
+
418
424
struct mep {
419
425
struct rb_node nd ;
420
426
const char * name ;
@@ -757,6 +763,16 @@ int __weak arch_get_runtimeparam(struct pmu_event *pe __maybe_unused)
757
763
return 1 ;
758
764
}
759
765
766
+ struct metricgroup_add_iter_data {
767
+ struct list_head * metric_list ;
768
+ const char * metric ;
769
+ struct metric * * m ;
770
+ struct expr_ids * ids ;
771
+ int * ret ;
772
+ bool * has_match ;
773
+ bool metric_no_group ;
774
+ };
775
+
760
776
static int __add_metric (struct list_head * metric_list ,
761
777
struct pmu_event * pe ,
762
778
bool metric_no_group ,
@@ -866,10 +882,11 @@ static int __add_metric(struct list_head *metric_list,
866
882
return 0 ;
867
883
}
868
884
869
- #define map_for_each_event (__pe , __idx , __map ) \
870
- for (__idx = 0, __pe = &__map->table[__idx]; \
871
- __pe->name || __pe->metric_group || __pe->metric_name; \
872
- __pe = &__map->table[++__idx])
885
+ #define map_for_each_event (__pe , __idx , __map ) \
886
+ if (__map) \
887
+ for (__idx = 0, __pe = &__map->table[__idx]; \
888
+ __pe->name || __pe->metric_group || __pe->metric_name; \
889
+ __pe = &__map->table[++__idx])
873
890
874
891
#define map_for_each_metric (__pe , __idx , __map , __metric ) \
875
892
map_for_each_event(__pe, __idx, __map) \
@@ -1037,6 +1054,29 @@ static int add_metric(struct list_head *metric_list,
1037
1054
return ret ;
1038
1055
}
1039
1056
1057
+ static int metricgroup__add_metric_sys_event_iter (struct pmu_event * pe ,
1058
+ void * data )
1059
+ {
1060
+ struct metricgroup_add_iter_data * d = data ;
1061
+ int ret ;
1062
+
1063
+ if (!match_pe_metric (pe , d -> metric ))
1064
+ return 0 ;
1065
+
1066
+ ret = add_metric (d -> metric_list , pe , d -> metric_no_group , d -> m , NULL , d -> ids );
1067
+ if (ret )
1068
+ return ret ;
1069
+
1070
+ ret = resolve_metric (d -> metric_no_group ,
1071
+ d -> metric_list , NULL , d -> ids );
1072
+ if (ret )
1073
+ return ret ;
1074
+
1075
+ * (d -> has_match ) = true;
1076
+
1077
+ return * d -> ret ;
1078
+ }
1079
+
1040
1080
static int metricgroup__add_metric (const char * metric , bool metric_no_group ,
1041
1081
struct strbuf * events ,
1042
1082
struct list_head * metric_list ,
@@ -1067,6 +1107,22 @@ static int metricgroup__add_metric(const char *metric, bool metric_no_group,
1067
1107
goto out ;
1068
1108
}
1069
1109
1110
+ {
1111
+ struct metricgroup_iter_data data = {
1112
+ .fn = metricgroup__add_metric_sys_event_iter ,
1113
+ .data = (void * ) & (struct metricgroup_add_iter_data ) {
1114
+ .metric_list = & list ,
1115
+ .metric = metric ,
1116
+ .metric_no_group = metric_no_group ,
1117
+ .m = & m ,
1118
+ .ids = & ids ,
1119
+ .has_match = & has_match ,
1120
+ .ret = & ret ,
1121
+ },
1122
+ };
1123
+
1124
+ pmu_for_each_sys_event (metricgroup__sys_event_iter , & data );
1125
+ }
1070
1126
/* End of pmu events. */
1071
1127
if (!has_match ) {
1072
1128
ret = - EINVAL ;
@@ -1193,8 +1249,6 @@ int metricgroup__parse_groups(const struct option *opt,
1193
1249
struct evlist * perf_evlist = * (struct evlist * * )opt -> value ;
1194
1250
struct pmu_events_map * map = perf_pmu__find_map (NULL );
1195
1251
1196
- if (!map )
1197
- return 0 ;
1198
1252
1199
1253
return parse_groups (perf_evlist , str , metric_no_group ,
1200
1254
metric_no_merge , NULL , metric_events , map );
0 commit comments