Skip to content

Commit 6d432c4

Browse files
olsajiriacmel
authored andcommitted
perf tools: Add test_generic_metric function
Adding test_generic_metric that prepares and runs given metric over the data from struct runtime_stat object. Signed-off-by: Jiri Olsa <[email protected]> Acked-by: Ian Rogers <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andi Kleen <[email protected]> Cc: Michael Petlan <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephane Eranian <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 9afe565 commit 6d432c4

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

tools/perf/util/stat-shadow.c

+14
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,20 @@ static void generic_metric(struct perf_stat_config *config,
842842
expr__ctx_clear(&pctx);
843843
}
844844

845+
double test_generic_metric(struct metric_expr *mexp, int cpu, struct runtime_stat *st)
846+
{
847+
struct expr_parse_ctx pctx;
848+
double ratio;
849+
850+
if (prepare_metric(mexp->metric_events, &pctx, cpu, st) < 0)
851+
return 0.;
852+
853+
if (expr__parse(&ratio, &pctx, mexp->metric_expr, 1))
854+
return 0.;
855+
856+
return ratio;
857+
}
858+
845859
void perf_stat__print_shadow_stats(struct perf_stat_config *config,
846860
struct evsel *evsel,
847861
double avg, int cpu,

tools/perf/util/stat.h

+3
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,7 @@ perf_evlist__print_counters(struct evlist *evlist,
230230
struct target *_target,
231231
struct timespec *ts,
232232
int argc, const char **argv);
233+
234+
struct metric_expr;
235+
double test_generic_metric(struct metric_expr *mexp, int cpu, struct runtime_stat *st);
233236
#endif

0 commit comments

Comments
 (0)