Commit 140aeadc authored by Andi Kleen's avatar Andi Kleen Committed by Arnaldo Carvalho de Melo

perf stat: Abstract stat metrics printing

Abstract the printing of shadow metrics. Instead of every metric calling
fprintf directly and taking care of indentation, use two call backs: one
to print metrics and another to start a new line.

This will allow adding metrics to CSV mode and also using them for other
purposes.

The computation of padding is now done in the central callback, instead
of every metric doing it manually.  This makes it easier to add new
metrics.

v2: Refactor functions, printout now does more. Move
shadow printing. Improve fallback callbacks. Don't
use void * callback data.
v3: Remove unnecessary hunk. Add typedef for new_line
v4: Remove unnecessary hunk. Don't print metrics for CSV/interval
mode yet.  Move printout change to separate patch.
v5: Fix bisect bugs. Avoid bogus frontend cycles printing.
Fix indentation in different aggregation modes.
v6: Delay newline handling
Signed-off-by: default avatarAndi Kleen <ak@linux.intel.com>
Acked-by: default avatarJiri Olsa <jolsa@redhat.com>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1454173616-17710-2-git-send-email-andi@firstfloor.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 720e98b5
...@@ -735,6 +735,58 @@ static void aggr_printout(struct perf_evsel *evsel, int id, int nr) ...@@ -735,6 +735,58 @@ static void aggr_printout(struct perf_evsel *evsel, int id, int nr)
} }
} }
struct outstate {
FILE *fh;
bool newline;
};
#define METRIC_LEN 35
static void new_line_std(void *ctx)
{
struct outstate *os = ctx;
os->newline = true;
}
static void do_new_line_std(struct outstate *os)
{
fputc('\n', os->fh);
if (stat_config.aggr_mode == AGGR_NONE)
fprintf(os->fh, " ");
if (stat_config.aggr_mode == AGGR_CORE)
fprintf(os->fh, " ");
if (stat_config.aggr_mode == AGGR_SOCKET)
fprintf(os->fh, " ");
fprintf(os->fh, " ");
}
static void print_metric_std(void *ctx, const char *color, const char *fmt,
const char *unit, double val)
{
struct outstate *os = ctx;
FILE *out = os->fh;
int n;
bool newline = os->newline;
os->newline = false;
if (unit == NULL || fmt == NULL) {
fprintf(out, "%-*s", METRIC_LEN, "");
return;
}
if (newline)
do_new_line_std(os);
n = fprintf(out, " # ");
if (color)
n += color_fprintf(out, color, fmt, val);
else
n += fprintf(out, fmt, val);
fprintf(out, " %-*s", METRIC_LEN - n - 1, unit);
}
static void nsec_printout(int id, int nr, struct perf_evsel *evsel, double avg) static void nsec_printout(int id, int nr, struct perf_evsel *evsel, double avg)
{ {
FILE *output = stat_config.output; FILE *output = stat_config.output;
...@@ -795,20 +847,27 @@ static void abs_printout(int id, int nr, struct perf_evsel *evsel, double avg) ...@@ -795,20 +847,27 @@ static void abs_printout(int id, int nr, struct perf_evsel *evsel, double avg)
static void printout(int id, int nr, struct perf_evsel *counter, double uval) static void printout(int id, int nr, struct perf_evsel *counter, double uval)
{ {
int cpu = cpu_map__id_to_cpu(id); struct outstate os = { .fh = stat_config.output };
struct perf_stat_output_ctx out;
print_metric_t pm = print_metric_std;
void (*nl)(void *);
if (stat_config.aggr_mode == AGGR_GLOBAL) nl = new_line_std;
cpu = 0;
if (nsec_counter(counter)) if (nsec_counter(counter))
nsec_printout(id, nr, counter, uval); nsec_printout(id, nr, counter, uval);
else else
abs_printout(id, nr, counter, uval); abs_printout(id, nr, counter, uval);
out.print_metric = pm;
out.new_line = nl;
out.ctx = &os;
if (!csv_output && !stat_config.interval) if (!csv_output && !stat_config.interval)
perf_stat__print_shadow_stats(stat_config.output, counter, perf_stat__print_shadow_stats(counter, uval,
uval, cpu, stat_config.aggr_mode == AGGR_GLOBAL ? 0 :
stat_config.aggr_mode); cpu_map__id_to_cpu(id),
&out);
} }
static void print_aggr(char *prefix) static void print_aggr(char *prefix)
......
This diff is collapsed.
...@@ -68,11 +68,22 @@ void perf_stat_evsel_id_init(struct perf_evsel *evsel); ...@@ -68,11 +68,22 @@ void perf_stat_evsel_id_init(struct perf_evsel *evsel);
extern struct stats walltime_nsecs_stats; extern struct stats walltime_nsecs_stats;
typedef void (*print_metric_t)(void *ctx, const char *color, const char *unit,
const char *fmt, double val);
typedef void (*new_line_t )(void *ctx);
void perf_stat__reset_shadow_stats(void); void perf_stat__reset_shadow_stats(void);
void perf_stat__update_shadow_stats(struct perf_evsel *counter, u64 *count, void perf_stat__update_shadow_stats(struct perf_evsel *counter, u64 *count,
int cpu); int cpu);
void perf_stat__print_shadow_stats(FILE *out, struct perf_evsel *evsel, struct perf_stat_output_ctx {
double avg, int cpu, enum aggr_mode aggr); void *ctx;
print_metric_t print_metric;
new_line_t new_line;
};
void perf_stat__print_shadow_stats(struct perf_evsel *evsel,
double avg, int cpu,
struct perf_stat_output_ctx *out);
int perf_evlist__alloc_stats(struct perf_evlist *evlist, bool alloc_raw); int perf_evlist__alloc_stats(struct perf_evlist *evlist, bool alloc_raw);
void perf_evlist__free_stats(struct perf_evlist *evlist); void perf_evlist__free_stats(struct perf_evlist *evlist);
......
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