Merge tag 'block-5.9-2020-08-14' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / tools / perf / util / spark.c
blob70272a8b81a65d23238ebf8d830221ab5d2eb50b
1 #include <stdio.h>
2 #include <limits.h>
3 #include <string.h>
4 #include <stdlib.h>
5 #include "spark.h"
6 #include "stat.h"
8 #define SPARK_SHIFT 8
10 /* Print spark lines on outf for numval values in val. */
11 int print_spark(char *bf, int size, unsigned long *val, int numval)
13 static const char *ticks[NUM_SPARKS] = {
14 "▁", "▂", "▃", "▄", "▅", "▆", "▇", "█"
16 int i, printed = 0;
17 unsigned long min = ULONG_MAX, max = 0, f;
19 for (i = 0; i < numval; i++) {
20 if (val[i] < min)
21 min = val[i];
22 if (val[i] > max)
23 max = val[i];
25 f = ((max - min) << SPARK_SHIFT) / (NUM_SPARKS - 1);
26 if (f < 1)
27 f = 1;
28 for (i = 0; i < numval; i++) {
29 printed += scnprintf(bf + printed, size - printed, "%s",
30 ticks[((val[i] - min) << SPARK_SHIFT) / f]);
33 return printed;