-remove debug message
[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 # SPDX-License-Identfier: AGPL3.0-or-later
18
19 # Aggregate benchmarking data from multiple threads/processes
20 # generated by util/benchmark.c.
21 #
22 # Can be used as
23 # awk -f collect.awk gnunet-benchmark-{ops,urls}-*.txt
24
25
26 # records are of the following forms:
27 # 1:op 2:<op> 3:count 4:<count> 6:time_us 7:<time_us>
28 # 1:url 2:<url> 3:status 4:<status> 5:count 6:<count> 7:time_us 8:<time_us> 9:time_us_max 10:<time_us_max>
29 #   11:bytes_sent 12:<bytes_sent> 13:bytes_received 14:<bytes_received>
30
31
32 function abs(v) {
33   return v < 0 ? -v : v
34 }
35
36 {
37   if ($1 == "op") {
38     n = $4;
39     t = $6;
40     op[$2]["count"] += n;
41     op[$2]["time_us"] += t;
42     if (n > 0) {
43       op[$2]["time_us_sq"] += n * (t/n) * (t/n);
44     }
45     total_ops += t;
46   } else if ($1 == "url") {
47     n = $6;
48     t = $8;
49     sent = $12
50     recv = $14
51     url[$2][$4]["count"] += n;
52     url[$2][$4]["time_us"] += t;
53     if (n > 0) {
54       url[$2][$4]["time_us_sq"] += n * (t/n) * (t/n);
55     }
56     url[$2][$4]["bytes_sent"] += sent;
57     url[$2][$4]["bytes_received"] += recv;
58     max = url[$2][$4]["time_us_max"];
59     url[$2][$4]["time_us_max"] = (t/n > max ? t/n : max)
60   } else if ($1 == "op_baseline") {
61     # take average time for operations from baseline values with format:
62     # op_baseline <opname> time_avg_us <t>
63     op_baseline[$2] = $4;
64     have_baseline = 1;
65   }
66 }
67
68 function avg(sum, n) {
69   if (n == 0) {
70     return 0;
71   } else {
72     return sum / n;
73   }
74 }
75
76 function stdev(sum, sum_sq, n) {
77   if (n == 0) {
78     return 0;
79   } else {
80     return sqrt(abs((sum_sq / n) - ((sum / n) * (sum / n))));
81   }
82 }
83
84 END {
85   for (x in op) {
86     print "op", x, "count", op[x]["count"], "time_us", op[x]["time_us"], \
87           "time_avg_us", avg(op[x]["time_us"], op[x]["count"]), \
88           "stdev", stdev(op[x]["time_us"], op[x]["time_us_sq"], op[x]["count"]);
89   }
90   for (x in url) {
91     for (y in url[x]) {
92       print "url", x, "status", y, \
93             "count", url[x][y]["count"], "time_us", url[x][y]["time_us"], \
94             "time_avg_us", avg(url[x][y]["time_us"], url[x][y]["count"]), \
95             "stdev", stdev(url[x][y]["time_us"], url[x][y]["time_us_sq"], url[x][y]["count"]), \
96             "time_us_max", url[x][y]["time_us_max"], \
97             "bytes_sent_avg", avg(url[x][y]["bytes_sent"], url[x][y]["count"]), \
98             "bytes_received_avg", avg(url[x][y]["bytes_received"], url[x][y]["count"]);
99     }
100   }
101   if (total_ops) {
102     print "total_ops_ms", total_ops;
103   }
104
105   # Invoke awk with -V baseline_out=<filename> to extract baseline average
106   if (baseline_out) {
107     for (x in op) {
108       print "op_baseline", x, "time_avg_us", avg(op[x]["time_us"], op[x]["count"]) > baseline_out
109     }
110   }
111
112   if (have_baseline) {
113     for (x in op) {
114       total_ops_adjusted += op_baseline[x] * op[x]["count"];
115     }
116     print "total_ops_adjusted_ms", int(total_ops_adjusted);
117   }
118 }