Commit 33c4ed47 authored by Namhyung Kim's avatar Namhyung Kim Committed by Arnaldo Carvalho de Melo

perf stat: Cleanup interval print alignment

Instead of using magic values, define symbolic constants and use them.
Also add aggr_header_std[] array to simplify aggr_mode handling.
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-13-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 208cbcd2
...@@ -25,6 +25,45 @@ ...@@ -25,6 +25,45 @@
#define CNTR_NOT_SUPPORTED "<not supported>" #define CNTR_NOT_SUPPORTED "<not supported>"
#define CNTR_NOT_COUNTED "<not counted>" #define CNTR_NOT_COUNTED "<not counted>"
#define METRIC_LEN 38
#define EVNAME_LEN 32
#define COUNTS_LEN 18
#define INTERVAL_LEN 16
#define CGROUP_LEN 16
#define COMM_LEN 16
#define PID_LEN 7
#define CPUS_LEN 4
static int aggr_header_lens[] = {
[AGGR_CORE] = 18,
[AGGR_DIE] = 12,
[AGGR_SOCKET] = 6,
[AGGR_NODE] = 6,
[AGGR_NONE] = 6,
[AGGR_THREAD] = 16,
[AGGR_GLOBAL] = 0,
};
static const char *aggr_header_csv[] = {
[AGGR_CORE] = "core,cpus,",
[AGGR_DIE] = "die,cpus,",
[AGGR_SOCKET] = "socket,cpus,",
[AGGR_NONE] = "cpu,",
[AGGR_THREAD] = "comm-pid,",
[AGGR_NODE] = "node,",
[AGGR_GLOBAL] = ""
};
static const char *aggr_header_std[] = {
[AGGR_CORE] = "core",
[AGGR_DIE] = "die",
[AGGR_SOCKET] = "socket",
[AGGR_NONE] = "cpu",
[AGGR_THREAD] = "comm-pid",
[AGGR_NODE] = "node",
[AGGR_GLOBAL] = ""
};
static void print_running_std(struct perf_stat_config *config, u64 run, u64 ena) static void print_running_std(struct perf_stat_config *config, u64 run, u64 ena)
{ {
if (run != ena) if (run != ena)
...@@ -116,7 +155,7 @@ static void print_noise(struct perf_stat_config *config, ...@@ -116,7 +155,7 @@ static void print_noise(struct perf_stat_config *config,
static void print_cgroup_std(struct perf_stat_config *config, const char *cgrp_name) static void print_cgroup_std(struct perf_stat_config *config, const char *cgrp_name)
{ {
fprintf(config->output, " %-16s", cgrp_name); fprintf(config->output, " %-*s", CGROUP_LEN, cgrp_name);
} }
static void print_cgroup_csv(struct perf_stat_config *config, const char *cgrp_name) static void print_cgroup_csv(struct perf_stat_config *config, const char *cgrp_name)
...@@ -147,44 +186,46 @@ static void print_aggr_id_std(struct perf_stat_config *config, ...@@ -147,44 +186,46 @@ static void print_aggr_id_std(struct perf_stat_config *config,
struct evsel *evsel, struct aggr_cpu_id id, int nr) struct evsel *evsel, struct aggr_cpu_id id, int nr)
{ {
FILE *output = config->output; FILE *output = config->output;
int idx = config->aggr_mode;
char buf[128];
switch (config->aggr_mode) { switch (config->aggr_mode) {
case AGGR_CORE: case AGGR_CORE:
fprintf(output, "S%d-D%d-C%*d %*d ", snprintf(buf, sizeof(buf), "S%d-D%d-C%d", id.socket, id.die, id.core);
id.socket, id.die, -8, id.core, 4, nr);
break; break;
case AGGR_DIE: case AGGR_DIE:
fprintf(output, "S%d-D%*d %*d ", snprintf(buf, sizeof(buf), "S%d-D%d", id.socket, id.die);
id.socket, -8, id.die, 4, nr);
break; break;
case AGGR_SOCKET: case AGGR_SOCKET:
fprintf(output, "S%*d %*d ", snprintf(buf, sizeof(buf), "S%d", id.socket);
-5, id.socket, 4, nr);
break; break;
case AGGR_NODE: case AGGR_NODE:
fprintf(output, "N%*d %*d ", snprintf(buf, sizeof(buf), "N%d", id.node);
-5, id.node, 4, nr);
break; break;
case AGGR_NONE: case AGGR_NONE:
if (evsel->percore && !config->percore_show_thread) { if (evsel->percore && !config->percore_show_thread) {
fprintf(output, "S%d-D%d-C%*d ", snprintf(buf, sizeof(buf), "S%d-D%d-C%d ",
id.socket, id.die, -3, id.core); id.socket, id.die, id.core);
fprintf(output, "%-*s ",
aggr_header_lens[AGGR_CORE], buf);
} else if (id.cpu.cpu > -1) { } else if (id.cpu.cpu > -1) {
fprintf(output, "CPU%*d ", fprintf(output, "CPU%-*d ",
-7, id.cpu.cpu); aggr_header_lens[AGGR_NONE] - 3, id.cpu.cpu);
} }
break; return;
case AGGR_THREAD: case AGGR_THREAD:
fprintf(output, "%*s-%*d ", fprintf(output, "%*s-%-*d ",
16, perf_thread_map__comm(evsel->core.threads, id.thread_idx), COMM_LEN, perf_thread_map__comm(evsel->core.threads, id.thread_idx),
-8, perf_thread_map__pid(evsel->core.threads, id.thread_idx)); PID_LEN, perf_thread_map__pid(evsel->core.threads, id.thread_idx));
break; return;
case AGGR_GLOBAL: case AGGR_GLOBAL:
case AGGR_UNSET: case AGGR_UNSET:
case AGGR_MAX: case AGGR_MAX:
default: default:
break; return;
} }
fprintf(output, "%-*s %*d ", aggr_header_lens[idx], buf, 4, nr);
} }
static void print_aggr_id_csv(struct perf_stat_config *config, static void print_aggr_id_csv(struct perf_stat_config *config,
...@@ -301,8 +342,6 @@ struct outstate { ...@@ -301,8 +342,6 @@ struct outstate {
struct evsel *evsel; struct evsel *evsel;
}; };
#define METRIC_LEN 38
static void new_line_std(struct perf_stat_config *config __maybe_unused, static void new_line_std(struct perf_stat_config *config __maybe_unused,
void *ctx) void *ctx)
{ {
...@@ -534,19 +573,19 @@ static void print_counter_value_std(struct perf_stat_config *config, ...@@ -534,19 +573,19 @@ static void print_counter_value_std(struct perf_stat_config *config,
const char *bad_count = evsel->supported ? CNTR_NOT_COUNTED : CNTR_NOT_SUPPORTED; const char *bad_count = evsel->supported ? CNTR_NOT_COUNTED : CNTR_NOT_SUPPORTED;
if (config->big_num) if (config->big_num)
fmt = floor(sc) != sc ? "%'18.2f " : "%'18.0f "; fmt = floor(sc) != sc ? "%'*.2f " : "%'*.0f ";
else else
fmt = floor(sc) != sc ? "%18.2f " : "%18.0f "; fmt = floor(sc) != sc ? "%*.2f " : "%*.0f ";
if (ok) if (ok)
fprintf(output, fmt, avg); fprintf(output, fmt, COUNTS_LEN, avg);
else else
fprintf(output, "%18s ", bad_count); fprintf(output, "%*s ", COUNTS_LEN, bad_count);
if (evsel->unit) if (evsel->unit)
fprintf(output, "%-*s ", config->unit_width, evsel->unit); fprintf(output, "%-*s ", config->unit_width, evsel->unit);
fprintf(output, "%-*s", 32, evsel__name(evsel)); fprintf(output, "%-*s", EVNAME_LEN, evsel__name(evsel));
} }
static void print_counter_value_csv(struct perf_stat_config *config, static void print_counter_value_csv(struct perf_stat_config *config,
...@@ -904,34 +943,19 @@ static void print_no_aggr_metric(struct perf_stat_config *config, ...@@ -904,34 +943,19 @@ static void print_no_aggr_metric(struct perf_stat_config *config,
} }
} }
static int aggr_header_lens[] = {
[AGGR_CORE] = 24,
[AGGR_DIE] = 18,
[AGGR_SOCKET] = 12,
[AGGR_NONE] = 6,
[AGGR_THREAD] = 24,
[AGGR_NODE] = 6,
[AGGR_GLOBAL] = 0,
};
static const char *aggr_header_csv[] = {
[AGGR_CORE] = "core,cpus,",
[AGGR_DIE] = "die,cpus,",
[AGGR_SOCKET] = "socket,cpus,",
[AGGR_NONE] = "cpu,",
[AGGR_THREAD] = "comm-pid,",
[AGGR_NODE] = "node,",
[AGGR_GLOBAL] = ""
};
static void print_metric_headers_std(struct perf_stat_config *config, static void print_metric_headers_std(struct perf_stat_config *config,
const char *prefix, bool no_indent) const char *prefix, bool no_indent)
{ {
if (prefix) if (prefix)
fprintf(config->output, "%s", prefix); fprintf(config->output, "%s", prefix);
if (!no_indent) { if (!no_indent) {
fprintf(config->output, "%*s", int len = aggr_header_lens[config->aggr_mode];
aggr_header_lens[config->aggr_mode], "");
if (nr_cgroups)
len += CGROUP_LEN + 1;
fprintf(config->output, "%*s", len, "");
} }
} }
...@@ -1025,46 +1049,39 @@ static void print_interval(struct perf_stat_config *config, ...@@ -1025,46 +1049,39 @@ static void print_interval(struct perf_stat_config *config,
!config->csv_output && !config->json_output) { !config->csv_output && !config->json_output) {
switch (config->aggr_mode) { switch (config->aggr_mode) {
case AGGR_NODE: case AGGR_NODE:
fprintf(output, "# time node cpus");
if (!metric_only)
fprintf(output, " counts %*s events\n", unit_width, "unit");
break;
case AGGR_SOCKET: case AGGR_SOCKET:
fprintf(output, "# time socket cpus");
if (!metric_only)
fprintf(output, " counts %*s events\n", unit_width, "unit");
break;
case AGGR_DIE: case AGGR_DIE:
fprintf(output, "# time die cpus");
if (!metric_only)
fprintf(output, " counts %*s events\n", unit_width, "unit");
break;
case AGGR_CORE: case AGGR_CORE:
fprintf(output, "# time core cpus"); fprintf(output, "#%*s %-*s cpus",
if (!metric_only) INTERVAL_LEN - 1, "time",
fprintf(output, " counts %*s events\n", unit_width, "unit"); aggr_header_lens[config->aggr_mode],
aggr_header_std[config->aggr_mode]);
break; break;
case AGGR_NONE: case AGGR_NONE:
fprintf(output, "# time CPU "); fprintf(output, "#%*s %-*s",
if (!metric_only) INTERVAL_LEN - 1, "time",
fprintf(output, " counts %*s events\n", unit_width, "unit"); aggr_header_lens[config->aggr_mode],
aggr_header_std[config->aggr_mode]);
break; break;
case AGGR_THREAD: case AGGR_THREAD:
fprintf(output, "# time comm-pid"); fprintf(output, "#%*s %*s-%-*s",
if (!metric_only) INTERVAL_LEN - 1, "time",
fprintf(output, " counts %*s events\n", unit_width, "unit"); COMM_LEN, "comm", PID_LEN, "pid");
break; break;
case AGGR_GLOBAL: case AGGR_GLOBAL:
default: default:
if (!config->iostat_run) { if (!config->iostat_run)
fprintf(output, "# time"); fprintf(output, "#%*s",
if (!metric_only) INTERVAL_LEN - 1, "time");
fprintf(output, " counts %*s events\n", unit_width, "unit");
}
case AGGR_UNSET: case AGGR_UNSET:
case AGGR_MAX: case AGGR_MAX:
break; break;
} }
if (!metric_only) {
fprintf(output, " %*s %*s events\n",
COUNTS_LEN, "counts", unit_width, "unit");
}
} }
if ((num_print_interval == 0 || config->interval_clear) && metric_only) if ((num_print_interval == 0 || config->interval_clear) && metric_only)
......
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