static bool smi_reset = false;
static bool big_num = true;
static int big_num_opt = -1;
-static const char *csv_sep = NULL;
-static bool csv_output = false;
static bool group = false;
static const char *pre_cmd = NULL;
static const char *post_cmd = NULL;
static void print_running(struct perf_stat_config *config,
u64 run, u64 ena)
{
- if (csv_output) {
+ if (config->csv_output) {
fprintf(config->output, "%s%" PRIu64 "%s%.2f",
- csv_sep,
+ config->csv_sep,
run,
- csv_sep,
+ config->csv_sep,
ena ? 100.0 * run / ena : 100.0);
} else if (run != ena) {
fprintf(config->output, " (%.2f%%)", 100.0 * run / ena);
{
double pct = rel_stddev_stats(total, avg);
- if (csv_output)
- fprintf(config->output, "%s%.2f%%", csv_sep, pct);
+ if (config->csv_output)
+ fprintf(config->output, "%s%.2f%%", config->csv_sep, pct);
else if (pct)
fprintf(config->output, " ( +-%6.2f%% )", pct);
}
case AGGR_CORE:
fprintf(config->output, "S%d-C%*d%s%*d%s",
cpu_map__id_to_socket(id),
- csv_output ? 0 : -8,
+ config->csv_output ? 0 : -8,
cpu_map__id_to_cpu(id),
- csv_sep,
- csv_output ? 0 : 4,
+ config->csv_sep,
+ config->csv_output ? 0 : 4,
nr,
- csv_sep);
+ config->csv_sep);
break;
case AGGR_SOCKET:
fprintf(config->output, "S%*d%s%*d%s",
- csv_output ? 0 : -5,
+ config->csv_output ? 0 : -5,
id,
- csv_sep,
- csv_output ? 0 : 4,
+ config->csv_sep,
+ config->csv_output ? 0 : 4,
nr,
- csv_sep);
+ config->csv_sep);
break;
case AGGR_NONE:
fprintf(config->output, "CPU%*d%s",
- csv_output ? 0 : -4,
- perf_evsel__cpus(evsel)->map[id], csv_sep);
+ config->csv_output ? 0 : -4,
+ perf_evsel__cpus(evsel)->map[id], config->csv_sep);
break;
case AGGR_THREAD:
fprintf(config->output, "%*s-%*d%s",
- csv_output ? 0 : 16,
+ config->csv_output ? 0 : 16,
thread_map__comm(evsel->threads, id),
- csv_output ? 0 : -8,
+ config->csv_output ? 0 : -8,
thread_map__pid(evsel->threads, id),
- csv_sep);
+ config->csv_sep);
break;
case AGGR_GLOBAL:
case AGGR_UNSET:
fputc('\n', os->fh);
if (os->prefix)
- fprintf(os->fh, "%s%s", os->prefix, csv_sep);
+ fprintf(os->fh, "%s%s", os->prefix, config->csv_sep);
aggr_printout(config, os->evsel, os->id, os->nr);
for (i = 0; i < os->nfields; i++)
- fputs(csv_sep, os->fh);
+ fputs(config->csv_sep, os->fh);
}
static void print_metric_csv(struct perf_stat_config *config __maybe_unused,
char buf[64], *vals, *ends;
if (unit == NULL || fmt == NULL) {
- fprintf(out, "%s%s", csv_sep, csv_sep);
+ fprintf(out, "%s%s", config->csv_sep, config->csv_sep);
return;
}
snprintf(buf, sizeof(buf), fmt, val);
*ends = 0;
while (isspace(*unit))
unit++;
- fprintf(out, "%s%s%s%s", csv_sep, vals, csv_sep, unit);
+ fprintf(out, "%s%s%s%s", config->csv_sep, vals, config->csv_sep, unit);
}
/* Filter out some columns that don't work well in metrics only mode */
while (isdigit(*ends) || *ends == '.')
ends++;
*ends = 0;
- fprintf(out, "%s%s", vals, csv_sep);
+ fprintf(out, "%s%s", vals, config->csv_sep);
}
static void new_line_metric(struct perf_stat_config *config __maybe_unused,
if (!valid_only_metric(unit))
return;
unit = fixunit(tbuf, os->evsel, unit);
- if (csv_output)
- fprintf(os->fh, "%s%s", unit, csv_sep);
+ if (config->csv_output)
+ fprintf(os->fh, "%s%s", unit, config->csv_sep);
else
fprintf(os->fh, "%*s ", metric_only_len, unit);
}
double sc = evsel->scale;
const char *fmt;
- if (csv_output) {
+ if (config->csv_output) {
fmt = floor(sc) != sc ? "%.2f%s" : "%.0f%s";
} else {
if (big_num)
aggr_printout(config, evsel, id, nr);
- fprintf(output, fmt, avg, csv_sep);
+ fprintf(output, fmt, avg, config->csv_sep);
if (evsel->unit)
fprintf(output, "%-*s%s",
- csv_output ? 0 : unit_width,
- evsel->unit, csv_sep);
+ config->csv_output ? 0 : unit_width,
+ evsel->unit, config->csv_sep);
- fprintf(output, "%-*s", csv_output ? 0 : 25, perf_evsel__name(evsel));
+ fprintf(output, "%-*s", config->csv_output ? 0 : 25, perf_evsel__name(evsel));
if (evsel->cgrp)
- fprintf(output, "%s%s", csv_sep, evsel->cgrp->name);
+ fprintf(output, "%s%s", config->csv_sep, evsel->cgrp->name);
}
static bool is_mixed_hw_group(struct perf_evsel *counter)
if (metric_only) {
nl = new_line_metric;
- if (csv_output)
+ if (config->csv_output)
pm = print_metric_only_csv;
else
pm = print_metric_only;
} else
nl = new_line_std;
- if (csv_output && !metric_only) {
+ if (config->csv_output && !metric_only) {
static int aggr_fields[] = {
[AGGR_GLOBAL] = 0,
[AGGR_THREAD] = 1,
aggr_printout(config, counter, id, nr);
fprintf(config->output, "%*s%s",
- csv_output ? 0 : 18,
+ config->csv_output ? 0 : 18,
counter->supported ? CNTR_NOT_COUNTED : CNTR_NOT_SUPPORTED,
- csv_sep);
+ config->csv_sep);
if (counter->supported) {
print_free_counters_hint = 1;
}
fprintf(config->output, "%-*s%s",
- csv_output ? 0 : unit_width,
- counter->unit, csv_sep);
+ config->csv_output ? 0 : unit_width,
+ counter->unit, config->csv_sep);
fprintf(config->output, "%*s",
- csv_output ? 0 : -25,
+ config->csv_output ? 0 : -25,
perf_evsel__name(counter));
if (counter->cgrp)
fprintf(config->output, "%s%s",
- csv_sep, counter->cgrp->name);
+ config->csv_sep, counter->cgrp->name);
- if (!csv_output)
+ if (!config->csv_output)
pm(config, &os, NULL, NULL, "", 0);
print_noise(config, counter, noise);
print_running(config, run, ena);
- if (csv_output)
+ if (config->csv_output)
pm(config, &os, NULL, NULL, "", 0);
return;
}
out.ctx = &os;
out.force_header = false;
- if (csv_output && !metric_only) {
+ if (config->csv_output && !metric_only) {
print_noise(config, counter, noise);
print_running(config, run, ena);
}
perf_stat__print_shadow_stats(config, counter, uval,
first_shadow_cpu(counter, id),
&out, &metric_events, st);
- if (!csv_output && !metric_only) {
+ if (!config->csv_output && !metric_only) {
print_noise(config, counter, noise);
print_running(config, run, ena);
}
if (prefix)
fprintf(config->output, "%s", prefix);
- if (!csv_output && !no_indent)
+ if (!config->csv_output && !no_indent)
fprintf(config->output, "%*s",
aggr_header_lens[config->aggr_mode], "");
- if (csv_output) {
+ if (config->csv_output) {
if (config->interval)
fputs("time,", config->output);
fputs(aggr_header_csv[config->aggr_mode], config->output);
if (interval_clear)
puts(CONSOLE_CLEAR);
- sprintf(prefix, "%6lu.%09lu%s", ts->tv_sec, ts->tv_nsec, csv_sep);
+ sprintf(prefix, "%6lu.%09lu%s", ts->tv_sec, ts->tv_nsec, config->csv_sep);
- if ((num_print_interval == 0 && !csv_output) || interval_clear) {
+ if ((num_print_interval == 0 && !config->csv_output) || interval_clear) {
switch (config->aggr_mode) {
case AGGR_SOCKET:
fprintf(output, "# time socket cpus");
fflush(stdout);
- if (!csv_output) {
+ if (!config->csv_output) {
fprintf(output, "\n");
fprintf(output, " Performance counter stats for ");
if (target.system_wide)
break;
}
- if (!interval && !csv_output)
+ if (!interval && !config->csv_output)
print_footer(config);
fflush(config->output);
OPT_SET_UINT('A', "no-aggr", &stat_config.aggr_mode,
"disable CPU count aggregation", AGGR_NONE),
OPT_BOOLEAN(0, "no-merge", &no_merge, "Do not merge identical named events"),
- OPT_STRING('x', "field-separator", &csv_sep, "separator",
+ OPT_STRING('x', "field-separator", &stat_config.csv_sep, "separator",
"print counts with custom separator"),
OPT_CALLBACK('G', "cgroup", &evsel_list, "name",
"monitor event in cgroup name only", parse_cgroups),
perf_stat__collect_metric_expr(evsel_list);
perf_stat__init_shadow_stats();
- if (csv_sep) {
- csv_output = true;
- if (!strcmp(csv_sep, "\\t"))
- csv_sep = "\t";
+ if (stat_config.csv_sep) {
+ stat_config.csv_output = true;
+ if (!strcmp(stat_config.csv_sep, "\\t"))
+ stat_config.csv_sep = "\t";
} else
- csv_sep = DEFAULT_SEPARATOR;
+ stat_config.csv_sep = DEFAULT_SEPARATOR;
if (argc && !strncmp(argv[0], "rec", 3)) {
argc = __cmd_record(argc, argv);
/*
* let the spreadsheet do the pretty-printing
*/
- if (csv_output) {
+ if (stat_config.csv_output) {
/* User explicitly passed -B? */
if (big_num_opt == 1) {
fprintf(stderr, "-B option not supported with -x\n");