Re: [PATCH 2/2] perf, tools: Support spark lines in perf stat

2014-04-14 Thread Andi Kleen
> fput could go into print_stat_spark

I wanted to keep the function generic, so that it can be easily
used in other places. Adding the space is somewhat specific
to stat.

Also the rest of the stat code has the white space printing 
centralized in the caller too. I suppose makes it easier to change.

> > +   len = n;
> > +   if (len > NUM_SPARK_VALS)
> > +   len = NUM_SPARK_VALS;
> > +   if (all_the_same(stat->svals, len))
> > +   return;
> > +   print_spark(f, stat->svals, len);
> > +   if (stat->n > NUM_SPARK_VALS)
> > +   fputs("..", f);
> > +}
> 
> whats the reason for 'n' in here?  looks like you could do only with 'len'

len is capped to NUM_SPARK_VALS, but the test needs to be on the
uncapped value. Otherwise exactly NUM_SPARK_VALS entries would
get a .. incorrectly.

-Andi
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/2] perf, tools: Support spark lines in perf stat

2014-04-14 Thread Jiri Olsa
On Tue, Mar 25, 2014 at 10:31:39AM -0700, Andi Kleen wrote:
> From: Andi Kleen 
> 

SNIP

> @@ -1176,6 +1176,9 @@ static void print_aggr(char *prefix)
>   if (run != ena)
>   fprintf(output, "  (%.2f%%)",
>   100.0 * run / ena);
> +
> + fputc(' ', output);
> + print_stat_spark(output, counter->priv);
>   }
>   fputc('\n', output);
>   }
> @@ -1224,6 +1227,9 @@ static void print_counter_aggr(struct perf_evsel 
> *counter, char *prefix)
>  
>   print_noise(counter, avg);
>  
> + fputc(' ', output);
> + print_stat_spark(output, counter->priv);
> +
>   if (csv_output) {
>   fputc('\n', output);
>   return;
> @@ -1295,6 +1301,9 @@ static void print_counter(struct perf_evsel *counter, 
> char *prefix)
>   if (run != ena)
>   fprintf(output, "  (%.2f%%)",
>   100.0 * run / ena);
> +
> + fputc(' ', output);
> + print_stat_spark(output, counter->priv);
>   }
>   fputc('\n', output);
>   }
> @@ -1355,6 +1364,9 @@ static void print_stat(int argc, const char **argv)
>   fprintf(output, "   
>  ");
>   print_noise_pct(stddev_stats(_nsecs_stats),
>   avg_stats(_nsecs_stats));
> +
> + fputc(' ', output);
> + print_stat_spark(output, _nsecs_stats);

Do we want to be that explicit about printing ' ' here?
I dont see it elsewhere..

fput could go into print_stat_spark


SNIP

> +void print_stat_spark(FILE *f, struct stats *stat)
> +{
> + int n = stat->n, len;
> +
> + if (n <= 1)
> + return;
> + len = n;
> + if (len > NUM_SPARK_VALS)
> + len = NUM_SPARK_VALS;
> + if (all_the_same(stat->svals, len))
> + return;
> + print_spark(f, stat->svals, len);
> + if (stat->n > NUM_SPARK_VALS)
> + fputs("..", f);
> +}

whats the reason for 'n' in here?  looks like you could do only with 'len'

thanks,
jirka
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/2] perf, tools: Support spark lines in perf stat

2014-04-14 Thread Jiri Olsa
On Tue, Mar 25, 2014 at 10:31:39AM -0700, Andi Kleen wrote:
 From: Andi Kleen a...@linux.intel.com
 

SNIP

 @@ -1176,6 +1176,9 @@ static void print_aggr(char *prefix)
   if (run != ena)
   fprintf(output,   (%.2f%%),
   100.0 * run / ena);
 +
 + fputc(' ', output);
 + print_stat_spark(output, counter-priv);
   }
   fputc('\n', output);
   }
 @@ -1224,6 +1227,9 @@ static void print_counter_aggr(struct perf_evsel 
 *counter, char *prefix)
  
   print_noise(counter, avg);
  
 + fputc(' ', output);
 + print_stat_spark(output, counter-priv);
 +
   if (csv_output) {
   fputc('\n', output);
   return;
 @@ -1295,6 +1301,9 @@ static void print_counter(struct perf_evsel *counter, 
 char *prefix)
   if (run != ena)
   fprintf(output,   (%.2f%%),
   100.0 * run / ena);
 +
 + fputc(' ', output);
 + print_stat_spark(output, counter-priv);
   }
   fputc('\n', output);
   }
 @@ -1355,6 +1364,9 @@ static void print_stat(int argc, const char **argv)
   fprintf(output,
  );
   print_noise_pct(stddev_stats(walltime_nsecs_stats),
   avg_stats(walltime_nsecs_stats));
 +
 + fputc(' ', output);
 + print_stat_spark(output, walltime_nsecs_stats);

Do we want to be that explicit about printing ' ' here?
I dont see it elsewhere..

fput could go into print_stat_spark


SNIP

 +void print_stat_spark(FILE *f, struct stats *stat)
 +{
 + int n = stat-n, len;
 +
 + if (n = 1)
 + return;
 + len = n;
 + if (len  NUM_SPARK_VALS)
 + len = NUM_SPARK_VALS;
 + if (all_the_same(stat-svals, len))
 + return;
 + print_spark(f, stat-svals, len);
 + if (stat-n  NUM_SPARK_VALS)
 + fputs(.., f);
 +}

whats the reason for 'n' in here?  looks like you could do only with 'len'

thanks,
jirka
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/2] perf, tools: Support spark lines in perf stat

2014-04-14 Thread Andi Kleen
 fput could go into print_stat_spark

I wanted to keep the function generic, so that it can be easily
used in other places. Adding the space is somewhat specific
to stat.

Also the rest of the stat code has the white space printing 
centralized in the caller too. I suppose makes it easier to change.

  +   len = n;
  +   if (len  NUM_SPARK_VALS)
  +   len = NUM_SPARK_VALS;
  +   if (all_the_same(stat-svals, len))
  +   return;
  +   print_spark(f, stat-svals, len);
  +   if (stat-n  NUM_SPARK_VALS)
  +   fputs(.., f);
  +}
 
 whats the reason for 'n' in here?  looks like you could do only with 'len'

len is capped to NUM_SPARK_VALS, but the test needs to be on the
uncapped value. Otherwise exactly NUM_SPARK_VALS entries would
get a .. incorrectly.

-Andi
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/2] perf, tools: Support spark lines in perf stat

2014-04-13 Thread Jiri Olsa
On Tue, Mar 25, 2014 at 10:31:39AM -0700, Andi Kleen wrote:
> From: Andi Kleen 
> 

SNIP

> index 65a151e..6bf7b6c 100644
> --- a/tools/perf/builtin-stat.c
> +++ b/tools/perf/builtin-stat.c
> @@ -1176,6 +1176,9 @@ static void print_aggr(char *prefix)
>   if (run != ena)
>   fprintf(output, "  (%.2f%%)",
>   100.0 * run / ena);
> +
> + fputc(' ', output);
> + print_stat_spark(output, counter->priv);

I dont think we want it in csv output

[jolsa@krava perf]$ ./perf stat -r 20 -x , true
0.285896,,task-clock,2.39% █▃▃▂▂▁▁▁..
0,,context-switches,0.00% 
0,,cpu-migrations,100.00% 
91,,page-faults,0.08% █▁██..
165335,,cycles,30.69% █▇▇▁▇▁▁▁..


jirka
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 2/2] perf, tools: Support spark lines in perf stat

2014-04-13 Thread Jiri Olsa
On Tue, Mar 25, 2014 at 10:31:39AM -0700, Andi Kleen wrote:
 From: Andi Kleen a...@linux.intel.com
 

SNIP

 index 65a151e..6bf7b6c 100644
 --- a/tools/perf/builtin-stat.c
 +++ b/tools/perf/builtin-stat.c
 @@ -1176,6 +1176,9 @@ static void print_aggr(char *prefix)
   if (run != ena)
   fprintf(output,   (%.2f%%),
   100.0 * run / ena);
 +
 + fputc(' ', output);
 + print_stat_spark(output, counter-priv);

I dont think we want it in csv output

[jolsa@krava perf]$ ./perf stat -r 20 -x , true
0.285896,,task-clock,2.39% █▃▃▂▂▁▁▁..
0,,context-switches,0.00% 
0,,cpu-migrations,100.00% 
91,,page-faults,0.08% █▁██..
165335,,cycles,30.69% █▇▇▁▇▁▁▁..


jirka
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 2/2] perf, tools: Support spark lines in perf stat

2014-03-25 Thread Andi Kleen
From: Andi Kleen 

perf stat -rX prints the stddev for multiple measurements.
Just looking at the stddev for judging the quality of the data
is a bit dangerous The simplest sanity check is to just look
at a simple plot. This patchs add a sparkline to the end
of the measurements to make it simple to judge the data.

The sparkline only uses UTF-8, so should be readable
in all modern tools and terminals.

The sparkline is between the minimum and maximum of the data,
so it's mainly a indicator of variance. To keep the code
simple and make the output not too wide only the first
8 values are printed. If more values are there it adds '..'

The code is inspired by Zach Holman's spark shell script.

Example output (view in non-proportial font):

 Performance counter stats for 'true' (10 runs):

  0.175672  task-clock (msec) #0.555 CPUs utilized  
  ( +-  1.77% ) █▄▁▁..
 0  context-switches  #0.000 K/sec
 0  cpu-migrations#0.000 K/sec
   114  page-faults   #0.647 M/sec  
  ( +-  0.14% ) ▁█▁▁..
   520,798  cycles#2.965 GHz
  ( +-  1.75% ) █▄▁▁..
   433,525  instructions  #0.83  insns per cycle
  ( +-  0.28% ) ▅▇▅▄▇█▁▆..
83,012  branches  #  472.537 M/sec  
  ( +-  0.31% ) ▅▇▆▄▇█▁▆..
 3,157  branch-misses #3.80% of all branches
  ( +-  2.55% ) ▇█▃▅▁▃▁▂..

   0.000316660 seconds time elapsed 
 ( +-  1.78% ) █▅▁▁..

As you can see even in the most simple run there are quite interesting
patterns. The time sparkline suggests it would be also useful to have an option
to throw the first measurement away.

Known issues:
- Makes the perf stat output wider. Could be adjust by shrinking
some white space. Not done so far.
- No output for -A/--per-socket/--per-core with -rX. This code
is missing the basic noise detection code. Once it's added there
sparklines could be shown too.

Signed-off-by: Andi Kleen 
---
 tools/perf/Makefile.perf  |  1 +
 tools/perf/builtin-stat.c | 12 
 tools/perf/util/spark.c   | 45 +
 tools/perf/util/spark.h   |  3 +++
 tools/perf/util/stat.c| 33 +
 tools/perf/util/stat.h| 10 ++
 6 files changed, 104 insertions(+)
 create mode 100644 tools/perf/util/spark.c
 create mode 100644 tools/perf/util/spark.h

diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 7257e7e..432d099 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -359,6 +359,7 @@ LIB_OBJS += $(OUTPUT)util/trace-event-scripting.o
 LIB_OBJS += $(OUTPUT)util/trace-event.o
 LIB_OBJS += $(OUTPUT)util/svghelper.o
 LIB_OBJS += $(OUTPUT)util/sort.o
+LIB_OBJS += $(OUTPUT)util/spark.o
 LIB_OBJS += $(OUTPUT)util/hist.o
 LIB_OBJS += $(OUTPUT)util/probe-event.o
 LIB_OBJS += $(OUTPUT)util/util.o
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 65a151e..6bf7b6c 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -1176,6 +1176,9 @@ static void print_aggr(char *prefix)
if (run != ena)
fprintf(output, "  (%.2f%%)",
100.0 * run / ena);
+
+   fputc(' ', output);
+   print_stat_spark(output, counter->priv);
}
fputc('\n', output);
}
@@ -1224,6 +1227,9 @@ static void print_counter_aggr(struct perf_evsel 
*counter, char *prefix)
 
print_noise(counter, avg);
 
+   fputc(' ', output);
+   print_stat_spark(output, counter->priv);
+
if (csv_output) {
fputc('\n', output);
return;
@@ -1295,6 +1301,9 @@ static void print_counter(struct perf_evsel *counter, 
char *prefix)
if (run != ena)
fprintf(output, "  (%.2f%%)",
100.0 * run / ena);
+
+   fputc(' ', output);
+   print_stat_spark(output, counter->priv);
}
fputc('\n', output);
}
@@ -1355,6 +1364,9 @@ static void print_stat(int argc, const char **argv)
fprintf(output, "   
 ");
print_noise_pct(stddev_stats(_nsecs_stats),
avg_stats(_nsecs_stats));
+
+   fputc(' ', output);
+   print_stat_spark(output, _nsecs_stats);
}
fprintf(output, "\n\n");
}
diff --git a/tools/perf/util/spark.c 

[PATCH 2/2] perf, tools: Support spark lines in perf stat

2014-03-25 Thread Andi Kleen
From: Andi Kleen a...@linux.intel.com

perf stat -rX prints the stddev for multiple measurements.
Just looking at the stddev for judging the quality of the data
is a bit dangerous The simplest sanity check is to just look
at a simple plot. This patchs add a sparkline to the end
of the measurements to make it simple to judge the data.

The sparkline only uses UTF-8, so should be readable
in all modern tools and terminals.

The sparkline is between the minimum and maximum of the data,
so it's mainly a indicator of variance. To keep the code
simple and make the output not too wide only the first
8 values are printed. If more values are there it adds '..'

The code is inspired by Zach Holman's spark shell script.

Example output (view in non-proportial font):

 Performance counter stats for 'true' (10 runs):

  0.175672  task-clock (msec) #0.555 CPUs utilized  
  ( +-  1.77% ) █▄▁▁..
 0  context-switches  #0.000 K/sec
 0  cpu-migrations#0.000 K/sec
   114  page-faults   #0.647 M/sec  
  ( +-  0.14% ) ▁█▁▁..
   520,798  cycles#2.965 GHz
  ( +-  1.75% ) █▄▁▁..
   433,525  instructions  #0.83  insns per cycle
  ( +-  0.28% ) ▅▇▅▄▇█▁▆..
83,012  branches  #  472.537 M/sec  
  ( +-  0.31% ) ▅▇▆▄▇█▁▆..
 3,157  branch-misses #3.80% of all branches
  ( +-  2.55% ) ▇█▃▅▁▃▁▂..

   0.000316660 seconds time elapsed 
 ( +-  1.78% ) █▅▁▁..

As you can see even in the most simple run there are quite interesting
patterns. The time sparkline suggests it would be also useful to have an option
to throw the first measurement away.

Known issues:
- Makes the perf stat output wider. Could be adjust by shrinking
some white space. Not done so far.
- No output for -A/--per-socket/--per-core with -rX. This code
is missing the basic noise detection code. Once it's added there
sparklines could be shown too.

Signed-off-by: Andi Kleen a...@linux.intel.com
---
 tools/perf/Makefile.perf  |  1 +
 tools/perf/builtin-stat.c | 12 
 tools/perf/util/spark.c   | 45 +
 tools/perf/util/spark.h   |  3 +++
 tools/perf/util/stat.c| 33 +
 tools/perf/util/stat.h| 10 ++
 6 files changed, 104 insertions(+)
 create mode 100644 tools/perf/util/spark.c
 create mode 100644 tools/perf/util/spark.h

diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 7257e7e..432d099 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -359,6 +359,7 @@ LIB_OBJS += $(OUTPUT)util/trace-event-scripting.o
 LIB_OBJS += $(OUTPUT)util/trace-event.o
 LIB_OBJS += $(OUTPUT)util/svghelper.o
 LIB_OBJS += $(OUTPUT)util/sort.o
+LIB_OBJS += $(OUTPUT)util/spark.o
 LIB_OBJS += $(OUTPUT)util/hist.o
 LIB_OBJS += $(OUTPUT)util/probe-event.o
 LIB_OBJS += $(OUTPUT)util/util.o
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 65a151e..6bf7b6c 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -1176,6 +1176,9 @@ static void print_aggr(char *prefix)
if (run != ena)
fprintf(output,   (%.2f%%),
100.0 * run / ena);
+
+   fputc(' ', output);
+   print_stat_spark(output, counter-priv);
}
fputc('\n', output);
}
@@ -1224,6 +1227,9 @@ static void print_counter_aggr(struct perf_evsel 
*counter, char *prefix)
 
print_noise(counter, avg);
 
+   fputc(' ', output);
+   print_stat_spark(output, counter-priv);
+
if (csv_output) {
fputc('\n', output);
return;
@@ -1295,6 +1301,9 @@ static void print_counter(struct perf_evsel *counter, 
char *prefix)
if (run != ena)
fprintf(output,   (%.2f%%),
100.0 * run / ena);
+
+   fputc(' ', output);
+   print_stat_spark(output, counter-priv);
}
fputc('\n', output);
}
@@ -1355,6 +1364,9 @@ static void print_stat(int argc, const char **argv)
fprintf(output,
 );
print_noise_pct(stddev_stats(walltime_nsecs_stats),
avg_stats(walltime_nsecs_stats));
+
+   fputc(' ', output);
+   print_stat_spark(output, walltime_nsecs_stats);
}
fprintf(output, \n\n);
}