Skip to content

Commit 2cfaa85

Browse files
olsajiriacmel
authored andcommitted
perf tools: Factor out prepare_metric function
Factoring out prepare_metric function so it can be used in test interface coming in following changes. 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 f78ac00 commit 2cfaa85

File tree

1 file changed

+34
-19
lines changed

1 file changed

+34
-19
lines changed

tools/perf/util/stat-shadow.c

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -730,25 +730,16 @@ static void print_smi_cost(struct perf_stat_config *config,
730730
out->print_metric(config, out->ctx, NULL, "%4.0f", "SMI#", smi_num);
731731
}
732732

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)
743737
{
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;
749739
char *n, *pn;
740+
int i;
750741

751-
expr__ctx_init(&pctx);
742+
expr__ctx_init(pctx);
752743
for (i = 0; metric_events[i]; i++) {
753744
struct saved_value *v;
754745
struct stats *stats;
@@ -771,7 +762,7 @@ static void generic_metric(struct perf_stat_config *config,
771762

772763
n = strdup(metric_events[i]->name);
773764
if (!n)
774-
return;
765+
return -ENOMEM;
775766
/*
776767
* This display code with --no-merge adds [cpu] postfixes.
777768
* These are not supported by the parser. Remove everything
@@ -782,11 +773,35 @@ static void generic_metric(struct perf_stat_config *config,
782773
*pn = 0;
783774

784775
if (metric_total)
785-
expr__add_id(&pctx, n, metric_total);
776+
expr__add_id(pctx, n, metric_total);
786777
else
787-
expr__add_id(&pctx, n, avg_stats(stats)*scale);
778+
expr__add_id(pctx, n, avg_stats(stats)*scale);
788779
}
789780

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+
790805
if (!metric_events[i]) {
791806
if (expr__parse(&ratio, &pctx, metric_expr, runtime) == 0) {
792807
char *unit;

0 commit comments

Comments
 (0)