All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jim Cromie <jim.cromie@gmail.com>
To: mingo@elte.hu
Cc: acme@ghostprotocols.net, linux-kernel@vger.kernel.org,
	Jim Cromie <jim.cromie@gmail.com>
Subject: [PATCH 3/3] perf-stat: clean up <no count> handling, CPUx prefixing
Date: Thu, 26 May 2011 13:50:06 -0600	[thread overview]
Message-ID: <1306439406-18037-4-git-send-email-jim.cromie@gmail.com> (raw)
In-Reply-To: <1306439406-18037-1-git-send-email-jim.cromie@gmail.com>

push <no-count> printing into print-ops to hide some cruft, and fold
away dynamic formats.  Refactor cpustr string prep into cpustr(int
cpu), use it everywhere, and change fn-sigs accordingly.

Also includes 1-line fixup for overlooked hack in earlier patch:
  -       if (scaled == -1 && !csv_output) {
  +       if (scaled == -1) {

Signed-off-by: Jim Cromie <jim.cromie@gmail.com>
---
 tools/perf/builtin-stat.c |  101 +++++++++++++++++++++++++++-----------------
 1 files changed, 62 insertions(+), 39 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index c59d199..9c03e99 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -383,12 +383,14 @@ static int run_perf_stat(int argc __used, const char **argv)
 
 struct print_ops {
 	int (*noise)  (double numer, double denom);
-	int (*nsec)   (const char *evt_name, double msecs, char *cpustr);
-	int (*abs)    (const char*, double avg, char *cpustr);
+	int (*nsec)   (const char *evt_name, double msecs, int cpu);
+	int (*abs)    (const char*, double avg, int cpu);
 	int (*unit)   (const char*, double, double);
 	int (*scaled) (double);
 	int (*cgrp)   (const char *name);
 	int (*time)   (const char *label, double mtime);
+	int (*ctr)    (const char *label, int val);
+	int (*noct)   (const char *label, int cpu);
 };
 static struct print_ops *prt;
 
@@ -406,24 +408,48 @@ static int csv_pr_noise(double numer, double denom)
 		ratio = numer / denom;
 	return fprintf(logfp, "%s%.3f%%", csv_sep, ratio);
 }
-static int user_pr_nsec(const char *evt_name, double msecs, char *cpustr)
+
+static char _cpustr[16];
+static char * cpustr(int cpu)
+{
+	_cpustr[0] = '\0';
+	if (cpu > -1) {
+		sprintf(_cpustr, "CPU%*d%s",
+			csv_output ? 0 : -4,
+			cpu, csv_sep);
+	}
+	return _cpustr;
+}
+static int user_pr_nsec(const char *evt_name, double msecs, int cpu)
 {
 	return fprintf(logfp, "%s%18.6f%s%-24s",
-			cpustr, msecs, csv_sep, evt_name);
+			cpustr(cpu), msecs, csv_sep, evt_name);
 }
-static int csv_pr_nsec(const char *evt_name, double msecs, char *cpustr)
+static int csv_pr_nsec(const char *evt_name, double msecs, int cpu)
 {
-	return fprintf(logfp, "%s%s%s%.6f", cpustr, evt_name, csv_sep, msecs);
+	return fprintf(logfp, "%s%s%s%.6f", cpustr(cpu), evt_name,
+			csv_sep, msecs);
 }
 
-static int user_pr_abs(const char *evt_name, double avg, char *cpustr)
+static int user_pr_abs(const char *evt_name, double avg, int cpu)
 {
 	const char *fmt = (big_num) ? "%s%'18.0f%s%-24s" : "%s%18.0f%s%-24s";
-	return fprintf(logfp, fmt, cpustr, avg, csv_sep, evt_name);
+	return fprintf(logfp, fmt, cpustr(cpu), avg, csv_sep, evt_name);
+}
+static int csv_pr_abs(const char *evt_name, double avg, int cpu)
+{
+	return fprintf(logfp, "%s%s%s%.0f", cpustr(cpu), evt_name, csv_sep, avg);
+}
+
+static int user_pr_nc(const char *evt_name, int cpu)
+{
+	return fprintf(logfp, "%s%18s%s%-24s", cpustr(cpu), "<not counted>",
+			csv_sep, evt_name);
 }
-static int csv_pr_abs(const char *evt_name, double avg, char *cpustr)
+static int csv_pr_nc(const char *evt_name, int cpu)
 {
-	return fprintf(logfp, "%s%s%s%.0f", cpustr, evt_name, csv_sep, avg);
+	return fprintf(logfp, "%s%s%s%s", cpustr(cpu), evt_name,
+			csv_sep, "<not-counted>");
 }
 
 static int user_pr_unit(const char *unit, double numer, double denom)
@@ -468,6 +494,20 @@ static int csv_pr_time(const char *label, double mtime)
 	return fprintf(logfp, "%s%s%.9f", label, csv_sep, mtime);
 }
 
+static int _pr_ctr(const char *label, int val)
+{
+	if (csv_output)
+		return fprintf(logfp, "CPU%0d%s%s%s%s",
+				val, csv_sep,
+				"<not counted>", csv_sep,
+				label);
+	else
+		return fprintf(logfp, "CPU%-4d%s%18s%s%-24s",
+				val, csv_sep,
+				"<not counted>", csv_sep,
+				label);
+}
+
 struct print_ops user_print_ops = {
 	.noise	= user_pr_noise,
 	.nsec	= user_pr_nsec,
@@ -476,6 +516,8 @@ struct print_ops user_print_ops = {
 	.cgrp	= user_pr_cgrp,
 	.unit	= user_pr_unit,
 	.time	= user_pr_time,
+	.ctr	= _pr_ctr,
+	.noct	= user_pr_nc,
 };
 
 struct print_ops csv_print_ops = {
@@ -486,6 +528,8 @@ struct print_ops csv_print_ops = {
 	.cgrp	= csv_pr_cgrp,
 	.unit	= csv_pr_unit,
 	.time	= csv_pr_time,
+	.ctr	= _pr_ctr,
+	.noct	= csv_pr_nc,
 };
 
 static void print_noise(struct perf_evsel *evsel, double avg)
@@ -502,14 +546,8 @@ static void print_noise(struct perf_evsel *evsel, double avg)
 static void nsec_printout(int cpu, struct perf_evsel *evsel, double avg)
 {
 	double msecs = avg / 1e6;
-	char cpustr[16] = { '\0', };
-
-	if (no_aggr)
-		sprintf(cpustr, "CPU%*d%s",
-			csv_output ? 0 : -4,
-			evsel_list->cpus->map[cpu], csv_sep);
 
-	prt->nsec(event_name(evsel), msecs, cpustr);
+	prt->nsec(event_name(evsel), msecs, cpu);
 
 	if (evsel->cgrp)
 		prt->cgrp(evsel->cgrp->name);
@@ -524,17 +562,11 @@ static void nsec_printout(int cpu, struct perf_evsel *evsel, double avg)
 
 static void abs_printout(int cpu, struct perf_evsel *evsel, double avg)
 {
-	char cpustr[16] = { '\0', };
+	prt->abs(event_name(evsel), avg, cpu);
 
-	if (no_aggr)
-		sprintf(cpustr, "CPU%*d%s",
-			csv_output ? 0 : -4,
-			evsel_list->cpus->map[cpu], csv_sep);
-	else
+	if (!no_aggr)
 		cpu = 0;
 
-	prt->abs(event_name(evsel), avg, cpustr);
-
 	if (evsel->cgrp)
 		prt->cgrp(evsel->cgrp->name);
 
@@ -569,14 +601,9 @@ static void print_counter_aggr(struct perf_evsel *counter)
 	double avg = avg_stats(&ps->res_stats[0]);
 	int scaled = counter->counts->scaled;
 
-	if (scaled == -1 && !csv_output) {
+	if (scaled == -1) {
 
-		fprintf(logfp, "%*s%s%*s",
-			csv_output ? 0 : 18,
-			"<not counted>",
-			csv_sep,
-			csv_output ? 0 : -24,
-			event_name(counter));
+		prt->noct(event_name(counter), -1);
 
 		if (counter->cgrp)
 			prt->cgrp(counter->cgrp->name);
@@ -618,13 +645,9 @@ static void print_counter(struct perf_evsel *counter)
 		run = counter->counts->cpu[cpu].run;
 
 		if (run == 0 || ena == 0) {
-			fprintf(logfp, "CPU%*d%s%*s%s%*s",
-				csv_output ? 0 : -4,
-				evsel_list->cpus->map[cpu], csv_sep,
-				csv_output ? 0 : 18,
-				"<not counted>", csv_sep,
-				csv_output ? 0 : -24,
-				event_name(counter));
+
+			prt->ctr(event_name(counter),
+				evsel_list->cpus->map[cpu]);
 
 			if (counter->cgrp)
 				prt->cgrp(counter->cgrp->name);
-- 
1.7.4.4


      parent reply	other threads:[~2011-05-26 19:50 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-21  8:56 [PATCH 0/2] perf stat: add -l <N> option to redirect stderr elsewhere Jim Cromie
2011-05-21  8:56 ` [PATCH 1/2] " Jim Cromie
2011-05-21 10:34   ` Ingo Molnar
2011-05-21 20:41     ` Arnaldo Carvalho de Melo
2011-09-01 21:58       ` Jim Cromie
2011-09-02 14:35         ` Arnaldo Carvalho de Melo
2011-09-02 18:02           ` Arnaldo Carvalho de Melo
2011-09-02 18:04           ` Jim Cromie
2011-09-02 18:58             ` Arnaldo Carvalho de Melo
2011-09-07 23:13               ` [patch 0/5] perf stat --log-fd=N Jim Cromie
2011-09-07 23:14                 ` [PATCH 1/5] perf stat: add --log-fd <N> option to redirect stderr elsewhere Jim Cromie
2011-09-07 23:14                 ` [PATCH 2/5] perf-stat: fix +- nan% in --no-aggr runs Jim Cromie
2011-09-07 23:14                 ` [PATCH 3/5] perf stat: suppress printing std-dev when its 0 Jim Cromie
2011-09-07 23:14                 ` [PATCH 4/5] perf stat: allow tab as cvs delimiter Jim Cromie
2011-09-07 23:14                 ` [PATCH 5/5] perf stat: fix spelling in comment Jim Cromie
2011-05-21  8:56 ` [PATCH 2/2] dont commify big numbers by default, let -B do it Jim Cromie
2011-05-21 10:33   ` Ingo Molnar
2011-05-24 22:05     ` Jim Cromie
2011-05-24 22:11       ` [PATCH] add --simple output mode to perf-stat, based upon csv-output Jim Cromie
2011-05-25 12:44       ` [PATCH 2/2] dont commify big numbers by default, let -B do it Ingo Molnar
2011-05-26 19:41         ` Jim Cromie
2011-05-26 19:50           ` [PATCH 0/3] perf-stat: refactor print/formatting into print-ops Jim Cromie
2011-05-26 19:50             ` [PATCH 1/3] perf-stat: refactor print/formatting into print-ops for pretty, csv Jim Cromie
2011-05-26 19:50             ` [PATCH 2/3] perf-stat: fix +- nan% in -Aa runs Jim Cromie
2011-05-26 19:50             ` Jim Cromie [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1306439406-18037-4-git-send-email-jim.cromie@gmail.com \
    --to=jim.cromie@gmail.com \
    --cc=acme@ghostprotocols.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.