linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf, tools, stat: Print warning when no metric with --metric-only
@ 2016-03-10 14:27 Andi Kleen
  2016-03-11  8:06 ` Jiri Olsa
  0 siblings, 1 reply; 3+ messages in thread
From: Andi Kleen @ 2016-03-10 14:27 UTC (permalink / raw)
  To: acme; +Cc: jolsa, linux-kernel, Andi Kleen

From: Andi Kleen <ak@linux.intel.com>

Print a warning when --metric-only is specified, but the events
define no metric. Requested by Jiri.

% perf stat -e cycles --metric-only true

 Performance counter stats for 'true':

No metrics defined by configured events

       0.001612070 seconds time elapsed

Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
 tools/perf/builtin-stat.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 1f19f2f..70efb58 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -743,6 +743,7 @@ struct outstate {
 	int  nfields;
 	int  id, nr;
 	struct perf_evsel *evsel;
+	int nheaders;
 };
 
 #define METRIC_LEN  35
@@ -919,6 +920,7 @@ static void print_metric_header(void *ctx, const char *color __maybe_unused,
 		fprintf(os->fh, "%s%s", unit, csv_sep);
 	else
 		fprintf(os->fh, "%-*s ", METRIC_ONLY_LEN, unit);
+	os->nheaders++;
 }
 
 static void nsec_printout(int id, int nr, struct perf_evsel *evsel, double avg)
@@ -1315,6 +1317,8 @@ static void print_metric_headers(char *prefix)
 					      &out);
 	}
 	fputc('\n', stat_config.output);
+	if (os.nheaders == 0)
+		pr_warning("No metrics defined by configured events\n");
 }
 
 static void print_interval(char *prefix, struct timespec *ts)
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] perf, tools, stat: Print warning when no metric with --metric-only
  2016-03-10 14:27 [PATCH] perf, tools, stat: Print warning when no metric with --metric-only Andi Kleen
@ 2016-03-11  8:06 ` Jiri Olsa
  2016-03-11 23:04   ` Andi Kleen
  0 siblings, 1 reply; 3+ messages in thread
From: Jiri Olsa @ 2016-03-11  8:06 UTC (permalink / raw)
  To: Andi Kleen; +Cc: acme, jolsa, linux-kernel, Andi Kleen

On Thu, Mar 10, 2016 at 06:27:17AM -0800, Andi Kleen wrote:
> From: Andi Kleen <ak@linux.intel.com>
> 
> Print a warning when --metric-only is specified, but the events
> define no metric. Requested by Jiri.
> 
> % perf stat -e cycles --metric-only true
> 
>  Performance counter stats for 'true':
> 
> No metrics defined by configured events
> 
>        0.001612070 seconds time elapsed
> 

how about printing the 'time' column and keeping the warning on the header line?


[jolsa@krava perf]$ sudo ./perf stat -a -I 1000 --metric-only 
            time insn per cycle       branch-misses of all branches 
     1.000370422    0.30                6.77%                      
     2.000749536    0.40                5.75%                      
     3.001007542    0.28                5.38%                      
     4.001324779    0.57                5.83%                      
^C     4.011558899    0.01                0.12%                      

[jolsa@krava perf]$ sudo ./perf stat -a -I 1000 --metric-only -e cycles
            time No metrics defined by configured events
     1.000211156 
     2.000432519 


thanks,
jirka


---
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 91188047be6a..9ce4138a8065 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -1302,7 +1302,7 @@ static void print_metric_headers(char *prefix)
 	};
 
 	if (prefix)
-		fprintf(stat_config.output, "%s", prefix);
+		fprintf(stat_config.output, "%16s ", "time");
 
 	if (!csv_output)
 		fprintf(stat_config.output, "%*s",
@@ -1319,9 +1319,9 @@ static void print_metric_headers(char *prefix)
 					      0,
 					      &out);
 	}
-	fputc('\n', stat_config.output);
 	if (os.nheaders == 0)
-		pr_warning("No metrics defined by configured events\n");
+		pr_warning("No metrics defined by configured events");
+	fputc('\n', stat_config.output);
 }
 
 static void print_interval(char *prefix, struct timespec *ts)

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] perf, tools, stat: Print warning when no metric with --metric-only
  2016-03-11  8:06 ` Jiri Olsa
@ 2016-03-11 23:04   ` Andi Kleen
  0 siblings, 0 replies; 3+ messages in thread
From: Andi Kleen @ 2016-03-11 23:04 UTC (permalink / raw)
  To: Jiri Olsa; +Cc: Andi Kleen, acme, jolsa, linux-kernel, Andi Kleen

> [jolsa@krava perf]$ sudo ./perf stat -a -I 1000 --metric-only 
>             time insn per cycle       branch-misses of all branches 
>      1.000370422    0.30                6.77%                      
>      2.000749536    0.40                5.75%                      
>      3.001007542    0.28                5.38%                      
>      4.001324779    0.57                5.83%                      
> ^C     4.011558899    0.01                0.12%                      
> 
> [jolsa@krava perf]$ sudo ./perf stat -a -I 1000 --metric-only -e cycles
>             time No metrics defined by configured events
>      1.000211156 
>      2.000432519 

Looks good to me. Please submit it.

-Andi

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-03-11 23:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-10 14:27 [PATCH] perf, tools, stat: Print warning when no metric with --metric-only Andi Kleen
2016-03-11  8:06 ` Jiri Olsa
2016-03-11 23:04   ` Andi Kleen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).