benchmark: output baseline
[oweals/gnunet.git] / contrib / benchmark / collect.awk
1 # This file is part of GNUnet
2 # Copyright (C) 2018 GNUnet e.V.
3 #
4 # GNUnet is free software: you can redistribute it and/or modify it
5 # under the terms of the GNU Affero General Public License as published
6 # by the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # GNUnet is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Affero General Public License for more details.
13 #
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17
18 # Aggregate benchmarking data from multiple threads/processes
19 # generated by util/benchmark.c.
20 #
21 # Can be used as
22 # awk -f collect.awk gnunet-benchmark-{ops,urls}-*.txt
23
24
25 # records are of the following forms:
26 # op <op> count <count> time_us <time_us>
27 # url <url> status <status> count <count> time_us <time_us> time_us_max <time_us_max>
28
29
30 function abs(v) {
31   return v < 0 ? -v : v
32 }
33
34 {
35   if ($1 == "op") {
36     n = $4;
37     t = $6;
38     op[$2]["count"] += n;
39     op[$2]["time_us"] += t;
40     if (n > 0) {
41       op[$2]["time_us_sq"] += n * (t/n) * (t/n);
42     }
43     total_ops += t;
44   } else if ($1 == "url") {
45     n = $6;
46     t = $8;
47     url[$2][$4]["count"] += n;
48     url[$2][$4]["time_us"] += t;
49     if (n > 0) {
50       url[$2][$4]["time_us_sq"] += n * (t/n) * (t/n);
51     }
52     max = url[$2][$4]["time_us_max"];
53     url[$2][$4]["time_us_max"] = (t/n > max ? t/n : max)
54   }
55 }
56
57 function avg(sum, n) {
58   if (n == 0) {
59     return 0;
60   } else {
61     return sum / n;
62   }
63 }
64
65 function stdev(sum, sum_sq, n) {
66   if (n == 0) {
67     return 0;
68   } else {
69     return sqrt(abs((sum_sq / n) - ((sum / n) * (sum / n))));
70   }
71 }
72
73 END {
74   for (x in op) {
75     print "op", x, "count", op[x]["count"], "time_us", op[x]["time_us"], \
76           "time_avg_us", avg(op[x]["time_us"], op[x]["count"]), \
77           "stdev", stdev(op[x]["time_us"], op[x]["time_us_sq"], op[x]["count"]);
78   }
79   for (x in url) {
80     for (y in url[x]) {
81       print "url", x, "status", y, \
82             "count", url[x][y]["count"], "time_us", url[x][y]["time_us"], \
83             "time_avg_us", avg(url[x][y]["time_us"], url[x][y]["count"]), \
84             "stdev", stdev(url[x][y]["time_us"], url[x][y]["time_us_sq"], url[x][y]["count"]), \
85             "time_us_max", url[x][y]["time_us_max"];
86     }
87   }
88   if (total_ops) {
89     print "total_ops_ms", total_ops;
90   }
91
92   # Invoke awk with -V baseline_out=<filename> to extract baseline average
93   if (baseline_out) {
94     for (x in op) {
95       print "op_baseline", x, "time_avg_us", avg(op[x]["time_us"], op[x]["count"]) > baseline_out
96     }
97   }
98 }