@@ -730,25 +730,16 @@ static void print_smi_cost(struct perf_stat_config *config,
730
730
out -> print_metric (config , out -> ctx , NULL , "%4.0f" , "SMI#" , smi_num );
731
731
}
732
732
733
- static void generic_metric (struct perf_stat_config * config ,
734
- const char * metric_expr ,
735
- struct evsel * * metric_events ,
736
- char * name ,
737
- const char * metric_name ,
738
- const char * metric_unit ,
739
- int runtime ,
740
- int cpu ,
741
- struct perf_stat_output_ctx * out ,
742
- struct runtime_stat * st )
733
+ static int prepare_metric (struct evsel * * metric_events ,
734
+ struct expr_parse_ctx * pctx ,
735
+ int cpu ,
736
+ struct runtime_stat * st )
743
737
{
744
- print_metric_t print_metric = out -> print_metric ;
745
- struct expr_parse_ctx pctx ;
746
- double ratio , scale ;
747
- int i ;
748
- void * ctxp = out -> ctx ;
738
+ double scale ;
749
739
char * n , * pn ;
740
+ int i ;
750
741
751
- expr__ctx_init (& pctx );
742
+ expr__ctx_init (pctx );
752
743
for (i = 0 ; metric_events [i ]; i ++ ) {
753
744
struct saved_value * v ;
754
745
struct stats * stats ;
@@ -771,7 +762,7 @@ static void generic_metric(struct perf_stat_config *config,
771
762
772
763
n = strdup (metric_events [i ]-> name );
773
764
if (!n )
774
- return ;
765
+ return - ENOMEM ;
775
766
/*
776
767
* This display code with --no-merge adds [cpu] postfixes.
777
768
* These are not supported by the parser. Remove everything
@@ -782,11 +773,35 @@ static void generic_metric(struct perf_stat_config *config,
782
773
* pn = 0 ;
783
774
784
775
if (metric_total )
785
- expr__add_id (& pctx , n , metric_total );
776
+ expr__add_id (pctx , n , metric_total );
786
777
else
787
- expr__add_id (& pctx , n , avg_stats (stats )* scale );
778
+ expr__add_id (pctx , n , avg_stats (stats )* scale );
788
779
}
789
780
781
+ return i ;
782
+ }
783
+
784
+ static void generic_metric (struct perf_stat_config * config ,
785
+ const char * metric_expr ,
786
+ struct evsel * * metric_events ,
787
+ char * name ,
788
+ const char * metric_name ,
789
+ const char * metric_unit ,
790
+ int runtime ,
791
+ int cpu ,
792
+ struct perf_stat_output_ctx * out ,
793
+ struct runtime_stat * st )
794
+ {
795
+ print_metric_t print_metric = out -> print_metric ;
796
+ struct expr_parse_ctx pctx ;
797
+ double ratio , scale ;
798
+ int i ;
799
+ void * ctxp = out -> ctx ;
800
+
801
+ i = prepare_metric (metric_events , & pctx , cpu , st );
802
+ if (i < 0 )
803
+ return ;
804
+
790
805
if (!metric_events [i ]) {
791
806
if (expr__parse (& ratio , & pctx , metric_expr , runtime ) == 0 ) {
792
807
char * unit ;
0 commit comments