From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751581AbbG3Nr6 (ORCPT ); Thu, 30 Jul 2015 09:47:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33798 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750950AbbG3Nr5 (ORCPT ); Thu, 30 Jul 2015 09:47:57 -0400 Date: Thu, 30 Jul 2015 15:47:55 +0200 From: Jiri Olsa To: Andi Kleen Cc: acme@kernel.org, jolsa@kernel.org, eranian@google.com, linux-kernel@vger.kernel.org, Andi Kleen Subject: Re: [PATCH 2/4] perf, tools, stat: Abstract stat metrics printing Message-ID: <20150730134755.GP9606@krava.brq.redhat.com> References: <1438215700-5530-1-git-send-email-andi@firstfloor.org> <1438215700-5530-3-git-send-email-andi@firstfloor.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1438215700-5530-3-git-send-email-andi@firstfloor.org> User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 29, 2015 at 05:21:38PM -0700, Andi Kleen wrote: > From: Andi Kleen > > 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 > --- > 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