Commit c2019f84 authored by Namhyung Kim's avatar Namhyung Kim Committed by Arnaldo Carvalho de Melo
Browse files

perf stat: Factor out print_counter_value() function



And split it for each output mode like others.  I believe it makes the
code simpler and more intuitive.  Now abs_printout() becomes just to
call sub-functions.

Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Athira Jajeev <atrajeev@linux.vnet.ibm.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: https://lore.kernel.org/r/20221114230227.1255976-7-namhyung@kernel.org


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 33b2e2c2
Loading
Loading
Loading
Loading
+53 −28
Original line number Original line Diff line number Diff line
@@ -517,46 +517,71 @@ static void print_metric_header(struct perf_stat_config *config,
		fprintf(os->fh, "%*s ", config->metric_only_len, unit);
		fprintf(os->fh, "%*s ", config->metric_only_len, unit);
}
}


static void abs_printout(struct perf_stat_config *config,
static void print_counter_value_std(struct perf_stat_config *config,
			 struct aggr_cpu_id id, int nr, struct evsel *evsel, double avg)
				    struct evsel *evsel, double avg)
{
{
	FILE *output = config->output;
	FILE *output = config->output;
	double sc =  evsel->scale;
	double sc =  evsel->scale;
	const char *fmt;
	const char *fmt;


	if (config->csv_output) {
		fmt = floor(sc) != sc ?  "%.2f%s" : "%.0f%s";
	} else {
	if (config->big_num)
	if (config->big_num)
			fmt = floor(sc) != sc ? "%'18.2f%s" : "%'18.0f%s";
		fmt = floor(sc) != sc ? "%'18.2f " : "%'18.0f ";
	else
	else
			fmt = floor(sc) != sc ? "%18.2f%s" : "%18.0f%s";
		fmt = floor(sc) != sc ? "%18.2f " : "%18.0f ";

	fprintf(output, fmt, avg);

	if (evsel->unit)
		fprintf(output, "%-*s ", config->unit_width, evsel->unit);

	fprintf(output, "%-*s", 32, evsel__name(evsel));
}
}


	aggr_printout(config, evsel, id, nr);
static void print_counter_value_csv(struct perf_stat_config *config,
				    struct evsel *evsel, double avg)
{
	FILE *output = config->output;
	double sc =  evsel->scale;
	const char *sep = config->csv_sep;
	const char *fmt = floor(sc) != sc ? "%.2f%s" : "%.0f%s";


	if (config->json_output)
	fprintf(output, fmt, avg, sep);
		fprintf(output, "\"counter-value\" : \"%f\", ", avg);
	else
		fprintf(output, fmt, avg, config->csv_sep);


	if (config->json_output) {
	if (evsel->unit)
		if (evsel->unit) {
		fprintf(output, "%s%s", evsel->unit, sep);
			fprintf(output, "\"unit\" : \"%s\", ",

				evsel->unit);
	fprintf(output, "%s", evsel__name(evsel));
}
}
	} else {

static void print_counter_value_json(struct perf_stat_config *config,
				     struct evsel *evsel, double avg)
{
	FILE *output = config->output;

	fprintf(output, "\"counter-value\" : \"%f\", ", avg);

	if (evsel->unit)
	if (evsel->unit)
			fprintf(output, "%-*s%s",
		fprintf(output, "\"unit\" : \"%s\", ", evsel->unit);
				config->csv_output ? 0 : config->unit_width,

				evsel->unit, config->csv_sep);
	fprintf(output, "\"event\" : \"%s\", ", evsel__name(evsel));
}
}


static void print_counter_value(struct perf_stat_config *config,
				struct evsel *evsel, double avg)
{
	if (config->json_output)
	if (config->json_output)
		fprintf(output, "\"event\" : \"%s\", ", evsel__name(evsel));
		print_counter_value_json(config, evsel, avg);
	else if (config->csv_output)
		print_counter_value_csv(config, evsel, avg);
	else
	else
		fprintf(output, "%-*s", config->csv_output ? 0 : 32, evsel__name(evsel));
		print_counter_value_std(config, evsel, avg);
}


static void abs_printout(struct perf_stat_config *config,
			 struct aggr_cpu_id id, int nr, struct evsel *evsel, double avg)
{
	aggr_printout(config, evsel, id, nr);
	print_counter_value(config, evsel, avg);
	print_cgroup(config, evsel);
	print_cgroup(config, evsel);
}
}