Commit 208cbcd2 authored by Namhyung Kim's avatar Namhyung Kim Committed by Arnaldo Carvalho de Melo

perf stat: Factor out prepare_interval()

This logic does not print the time directly, but it just puts the
timestamp in the buffer as a prefix.  To reduce the confusion, factor
out the code into a separate function.
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-12-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent b2d9832e
...@@ -993,9 +993,25 @@ static void print_metric_headers(struct perf_stat_config *config, ...@@ -993,9 +993,25 @@ static void print_metric_headers(struct perf_stat_config *config,
fputc('\n', config->output); fputc('\n', config->output);
} }
static void prepare_interval(struct perf_stat_config *config,
char *prefix, struct timespec *ts)
{
if (config->iostat_run)
return;
if (!config->json_output)
sprintf(prefix, "%6lu.%09lu%s", (unsigned long) ts->tv_sec,
ts->tv_nsec, config->csv_sep);
else if (!config->metric_only)
sprintf(prefix, "{\"interval\" : %lu.%09lu, ", (unsigned long)
ts->tv_sec, ts->tv_nsec);
else
sprintf(prefix, "{\"interval\" : %lu.%09lu}", (unsigned long)
ts->tv_sec, ts->tv_nsec);
}
static void print_interval(struct perf_stat_config *config, static void print_interval(struct perf_stat_config *config,
struct evlist *evlist, struct evlist *evlist)
char *prefix, struct timespec *ts)
{ {
bool metric_only = config->metric_only; bool metric_only = config->metric_only;
unsigned int unit_width = config->unit_width; unsigned int unit_width = config->unit_width;
...@@ -1005,16 +1021,6 @@ static void print_interval(struct perf_stat_config *config, ...@@ -1005,16 +1021,6 @@ static void print_interval(struct perf_stat_config *config,
if (config->interval_clear && isatty(fileno(output))) if (config->interval_clear && isatty(fileno(output)))
puts(CONSOLE_CLEAR); puts(CONSOLE_CLEAR);
if (!config->iostat_run && !config->json_output)
sprintf(prefix, "%6lu.%09lu%s", (unsigned long) ts->tv_sec,
ts->tv_nsec, config->csv_sep);
if (!config->iostat_run && config->json_output && !config->metric_only)
sprintf(prefix, "{\"interval\" : %lu.%09lu, ", (unsigned long)
ts->tv_sec, ts->tv_nsec);
if (!config->iostat_run && config->json_output && config->metric_only)
sprintf(prefix, "{\"interval\" : %lu.%09lu}", (unsigned long)
ts->tv_sec, ts->tv_nsec);
if ((num_print_interval == 0 || config->interval_clear) && if ((num_print_interval == 0 || config->interval_clear) &&
!config->csv_output && !config->json_output) { !config->csv_output && !config->json_output) {
switch (config->aggr_mode) { switch (config->aggr_mode) {
...@@ -1252,10 +1258,13 @@ void evlist__print_counters(struct evlist *evlist, struct perf_stat_config *conf ...@@ -1252,10 +1258,13 @@ void evlist__print_counters(struct evlist *evlist, struct perf_stat_config *conf
if (config->iostat_run) if (config->iostat_run)
evlist->selected = evlist__first(evlist); evlist->selected = evlist__first(evlist);
if (interval) if (interval) {
print_interval(config, evlist, prefix = buf, ts); prefix = buf;
else prepare_interval(config, prefix, ts);
print_interval(config, evlist);
} else {
print_header(config, _target, argc, argv); print_header(config, _target, argc, argv);
}
if (metric_only) { if (metric_only) {
static int num_print_iv; static int num_print_iv;
......
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