Re: [PATCH 2/4] perf, tools, stat: Abstract stat metrics printing
From: Jiri Olsa
Date: Thu Jul 30 2015 - 09:48:01 EST
On Wed, Jul 29, 2015 at 05:21:38PM -0700, Andi Kleen wrote:
> From: Andi Kleen <ak@xxxxxxxxxxxxxxx>
>
> 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.
>
> Right now there is no (intentional) behavior change, just refactoring.
>
> Signed-off-by: Andi Kleen <ak@xxxxxxxxxxxxxxx>
> ---
> tools/perf/builtin-stat.c | 98 +++++++++++++++++++--------
> tools/perf/util/stat-shadow.c | 154 ++++++++++++++++++++++--------------------
> tools/perf/util/stat.h | 10 ++-
> 3 files changed, 160 insertions(+), 102 deletions(-)
>
> diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
> index d99d850..e6386f1 100644
> --- a/tools/perf/builtin-stat.c
> +++ b/tools/perf/builtin-stat.c
> @@ -617,7 +617,49 @@ static void aggr_printout(struct perf_evsel *evsel, int id, int nr)
> }
> }
>
> -static void nsec_printout(int id, int nr, struct perf_evsel *evsel, double avg)
> +struct outstate {
> + FILE *fh;
> +};
because we already need to make the print_metric callback global,
would it be better to make this struct global, having all the
needed callbacks defined within? something like:
typedef void (*perf_stat_output_metric_t)(void *ctx, const char *color, const char *unit,
const char *fmt, double val);
typedef void (*perf_stat_output_newln_t)(void *ctx);
struct perf_stat_output_ctx {
FILE *output
perf_stat_output_metric_t metric;
perf_stat_output_newln_t nl;
};
not sure about the naming, but IMO should have some perf_sta_.. global form
it'd also ease the new arguments count from 3 to 1
jirka
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/