Commit 31bf6aea authored by Namhyung Kim's avatar Namhyung Kim Committed by Arnaldo Carvalho de Melo

perf stat: Split print_running() function

To make the code more obvious and hopefully simpler, factor out the
code for each output mode - stdio, CSV, JSON.
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-3-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent f5bc4428
...@@ -25,24 +25,41 @@ ...@@ -25,24 +25,41 @@
#define CNTR_NOT_SUPPORTED "<not supported>" #define CNTR_NOT_SUPPORTED "<not supported>"
#define CNTR_NOT_COUNTED "<not counted>" #define CNTR_NOT_COUNTED "<not counted>"
static void print_running(struct perf_stat_config *config, static void print_running_std(struct perf_stat_config *config, u64 run, u64 ena)
u64 run, u64 ena) {
if (run != ena)
fprintf(config->output, " (%.2f%%)", 100.0 * run / ena);
}
static void print_running_csv(struct perf_stat_config *config, u64 run, u64 ena)
{ {
double enabled_percent = 100;
if (run != ena)
enabled_percent = 100 * run / ena;
fprintf(config->output, "%s%" PRIu64 "%s%.2f",
config->csv_sep, run, config->csv_sep, enabled_percent);
}
static void print_running_json(struct perf_stat_config *config, u64 run, u64 ena)
{
double enabled_percent = 100; double enabled_percent = 100;
if (run != ena) if (run != ena)
enabled_percent = 100 * run / ena; enabled_percent = 100 * run / ena;
fprintf(config->output, "\"event-runtime\" : %" PRIu64 ", \"pcnt-running\" : %.2f, ",
run, enabled_percent);
}
static void print_running(struct perf_stat_config *config,
u64 run, u64 ena)
{
if (config->json_output) if (config->json_output)
fprintf(config->output, print_running_json(config, run, ena);
"\"event-runtime\" : %" PRIu64 ", \"pcnt-running\" : %.2f, ",
run, enabled_percent);
else if (config->csv_output) else if (config->csv_output)
fprintf(config->output, print_running_csv(config, run, ena);
"%s%" PRIu64 "%s%.2f", config->csv_sep, else
run, config->csv_sep, enabled_percent); print_running_std(config, run, ena);
else if (run != ena)
fprintf(config->output, " (%.2f%%)", 100.0 * run / ena);
} }
static void print_noise_pct(struct perf_stat_config *config, static void print_noise_pct(struct perf_stat_config *config,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment