Commit 4c86b664 authored by Namhyung Kim's avatar Namhyung Kim Committed by Arnaldo Carvalho de Melo

perf stat: Rework header display

There are print_header() and print_interval() to print header lines before
actual counter values.  Also print_metric_headers() needs to be called for
the metric-only case.

Let's move all these logics to a single place including num_print_iv to
refresh the headers for interval mode.
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-15-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 6108712c
...@@ -1034,19 +1034,14 @@ static void prepare_interval(struct perf_stat_config *config, ...@@ -1034,19 +1034,14 @@ static void prepare_interval(struct perf_stat_config *config,
ts->tv_sec, ts->tv_nsec); ts->tv_sec, ts->tv_nsec);
} }
static void print_interval(struct perf_stat_config *config, static void print_header_interval_std(struct perf_stat_config *config,
struct evlist *evlist) struct target *_target __maybe_unused,
struct evlist *evlist,
int argc __maybe_unused,
const char **argv __maybe_unused)
{ {
bool metric_only = config->metric_only;
unsigned int unit_width = config->unit_width;
FILE *output = config->output; FILE *output = config->output;
static int num_print_interval;
if (config->interval_clear && isatty(fileno(output)))
puts(CONSOLE_CLEAR);
if ((num_print_interval == 0 || config->interval_clear) &&
!config->csv_output && !config->json_output) {
switch (config->aggr_mode) { switch (config->aggr_mode) {
case AGGR_NODE: case AGGR_NODE:
case AGGR_SOCKET: case AGGR_SOCKET:
...@@ -1078,28 +1073,20 @@ static void print_interval(struct perf_stat_config *config, ...@@ -1078,28 +1073,20 @@ static void print_interval(struct perf_stat_config *config,
break; break;
} }
if (!metric_only) { if (config->metric_only)
fprintf(output, " %*s %*s events\n",
COUNTS_LEN, "counts", unit_width, "unit");
}
}
if ((num_print_interval == 0 || config->interval_clear) && metric_only)
print_metric_headers(config, evlist, " ", true); print_metric_headers(config, evlist, " ", true);
if (++num_print_interval == 25) else
num_print_interval = 0; fprintf(output, " %*s %*s events\n",
COUNTS_LEN, "counts", config->unit_width, "unit");
} }
static void print_header(struct perf_stat_config *config, static void print_header_std(struct perf_stat_config *config,
struct target *_target, struct target *_target, struct evlist *evlist,
int argc, const char **argv) int argc, const char **argv)
{ {
FILE *output = config->output; FILE *output = config->output;
int i; int i;
fflush(stdout);
if (!config->csv_output && !config->json_output) {
fprintf(output, "\n"); fprintf(output, "\n");
fprintf(output, " Performance counter stats for "); fprintf(output, " Performance counter stats for ");
if (_target->bpf_str) if (_target->bpf_str)
...@@ -1121,7 +1108,55 @@ static void print_header(struct perf_stat_config *config, ...@@ -1121,7 +1108,55 @@ static void print_header(struct perf_stat_config *config,
if (config->run_count > 1) if (config->run_count > 1)
fprintf(output, " (%d runs)", config->run_count); fprintf(output, " (%d runs)", config->run_count);
fprintf(output, ":\n\n"); fprintf(output, ":\n\n");
if (config->metric_only)
print_metric_headers(config, evlist, " ", false);
}
static void print_header_csv(struct perf_stat_config *config,
struct target *_target __maybe_unused,
struct evlist *evlist,
int argc __maybe_unused,
const char **argv __maybe_unused)
{
if (config->metric_only)
print_metric_headers(config, evlist, " ", true);
}
static void print_header_json(struct perf_stat_config *config,
struct target *_target __maybe_unused,
struct evlist *evlist,
int argc __maybe_unused,
const char **argv __maybe_unused)
{
if (config->metric_only)
print_metric_headers(config, evlist, " ", true);
}
static void print_header(struct perf_stat_config *config,
struct target *_target,
struct evlist *evlist,
int argc, const char **argv)
{
static int num_print_iv;
fflush(stdout);
if (config->interval_clear)
puts(CONSOLE_CLEAR);
if (num_print_iv == 0 || config->interval_clear) {
if (config->json_output)
print_header_json(config, _target, evlist, argc, argv);
else if (config->csv_output)
print_header_csv(config, _target, evlist, argc, argv);
else if (config->interval)
print_header_interval_std(config, _target, evlist, argc, argv);
else
print_header_std(config, _target, evlist, argc, argv);
} }
if (num_print_iv++ == 25)
num_print_iv = 0;
} }
static int get_precision(double num) static int get_precision(double num)
...@@ -1278,18 +1313,10 @@ void evlist__print_counters(struct evlist *evlist, struct perf_stat_config *conf ...@@ -1278,18 +1313,10 @@ void evlist__print_counters(struct evlist *evlist, struct perf_stat_config *conf
if (interval) { if (interval) {
prefix = buf; prefix = buf;
prepare_interval(config, prefix, ts); prepare_interval(config, prefix, ts);
print_interval(config, evlist);
} else {
print_header(config, _target, argc, argv);
} }
print_header(config, _target, evlist, argc, argv);
if (metric_only) { if (metric_only) {
static int num_print_iv;
if (num_print_iv == 0 && !interval)
print_metric_headers(config, evlist, prefix, false);
if (num_print_iv++ == 25)
num_print_iv = 0;
if (config->aggr_mode == AGGR_GLOBAL && prefix && !config->iostat_run) if (config->aggr_mode == AGGR_GLOBAL && prefix && !config->iostat_run)
fprintf(config->output, "%s", prefix); fprintf(config->output, "%s", prefix);
} }
......
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