Skip to content

Commit 6d432c4

Browse files
olsajiriacmel
authored andcommittedJun 22, 2020
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 <jolsa@kernel.org> Acked-by: Ian Rogers <irogers@google.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Michael Petlan <mpetlan@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lore.kernel.org/lkml/20200602214741.1218986-12-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
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)
Please sign in to comment.