]> git.llucax.com Git - software/dgc/dgcbench.git/blob - hist.awk
Move Makefile to the top-level directory
[software/dgc/dgcbench.git] / hist.awk
1 #!/usr/bin/env awk -F, -f
2
3 BEGIN {
4         MAX_SAMPLES = 50
5         # output CSV header
6         print "Size,Scan,No Scan";
7 }
8
9 NR == 2 {
10         min = max = int($3)
11 }
12
13 NR > 1 { # skip the input CVS header
14         n = int($3)
15         if (int($6) > 0) { # cell has the NO_SCAN bit
16                 no_scan[n]++
17                 if (!(n in scan))
18                         scan[n] = 0
19         } else { # cell doesn't have the NO_SCAN bit
20                 scan[n]++
21                 if (!(n in no_scan))
22                         no_scan[n] = 0
23         }
24         if (n < min)
25                 min = n
26         else if (n > max)
27                 max = n
28 }
29
30 function h(val) {
31         if (val >= 1048576) # 1 M
32                 r = sprintf("%uM", val / 1048576)
33         else if (val >= 1024) # 1 K
34                 r = sprintf("%uK", val / 1024)
35         else
36                 r = sprintf("%u", val)
37         return r
38 }
39
40 function p(s, ns, o, n) {
41         for (i = 1; i <= n; i++)
42                 print o[i] "," s[o[i]] "," ns[o[i]]
43 }
44
45 END {
46         # reduce the number of elements in the histogram if there are too many
47         if (length(scan) > MAX_SAMPLES) {
48                 step = int((max - min) / MAX_SAMPLES) + 1
49                 for (i in scan) {
50                         i = int(i)
51                         for (from = min; from < max; from += step) {
52                                 to = from + step
53                                 if ((from <= i) && (i < to)) {
54                                         j = sprintf("%s-%s", h(from), h(to))
55                                         scan2[j] += scan[i]
56                                         no_scan2[j] += no_scan[i]
57                                         break
58                                 }
59                         }
60                 }
61                 n = 1
62                 for (from = min; from < max; from += step) {
63                         v = sprintf("%s-%s", h(from), h(from + step))
64                         if (v in scan2)
65                                 order[n++] = v
66                 }
67         }
68         # print output data
69         if (length(scan2)) {
70                 p(scan2, no_scan2, order, n)
71         } else {
72                 for (i in scan)
73                         order[i++] = int(i)
74                 n = asort(order)
75                 p(scan, no_scan, order, n)
76         }
77 }
78