Skip to content

Commit

Permalink
perf tools: Add test_generic_metric function
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
olsajiri authored and acmel committed Jun 22, 2020
1 parent 9afe565 commit 6d432c4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tools/perf/util/stat-shadow.c
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,20 @@ static void generic_metric(struct perf_stat_config *config,
expr__ctx_clear(&pctx);
}

double test_generic_metric(struct metric_expr *mexp, int cpu, struct runtime_stat *st)
{
struct expr_parse_ctx pctx;
double ratio;

if (prepare_metric(mexp->metric_events, &pctx, cpu, st) < 0)
return 0.;

if (expr__parse(&ratio, &pctx, mexp->metric_expr, 1))
return 0.;

return ratio;
}

void perf_stat__print_shadow_stats(struct perf_stat_config *config,
struct evsel *evsel,
double avg, int cpu,
Expand Down
3 changes: 3 additions & 0 deletions tools/perf/util/stat.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,7 @@ perf_evlist__print_counters(struct evlist *evlist,
struct target *_target,
struct timespec *ts,
int argc, const char **argv);

struct metric_expr;
double test_generic_metric(struct metric_expr *mexp, int cpu, struct runtime_stat *st);
#endif

0 comments on commit 6d432c4

Please sign in to comment.