collect.awk 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. # 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. # records are of the following forms:
  24. # 1:op 2:<op> 3:count 4:<count> 6:time_us 7:<time_us>
  25. # 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>
  26. # 11:bytes_sent 12:<bytes_sent> 13:bytes_received 14:<bytes_received>
  27. function abs(v) {
  28. return v < 0 ? -v : v
  29. }
  30. {
  31. if ($1 == "op") {
  32. n = $4;
  33. t = $6;
  34. op[$2]["count"] += n;
  35. op[$2]["time_us"] += t;
  36. if (n > 0) {
  37. op[$2]["time_us_sq"] += n * (t/n) * (t/n);
  38. }
  39. total_ops += t;
  40. } else if ($1 == "url") {
  41. n = $6;
  42. t = $8;
  43. sent = $12
  44. recv = $14
  45. url[$2][$4]["count"] += n;
  46. url[$2][$4]["time_us"] += t;
  47. if (n > 0) {
  48. url[$2][$4]["time_us_sq"] += n * (t/n) * (t/n);
  49. }
  50. url[$2][$4]["bytes_sent"] += sent;
  51. url[$2][$4]["bytes_received"] += recv;
  52. max = url[$2][$4]["time_us_max"];
  53. url[$2][$4]["time_us_max"] = (t/n > max ? t/n : max)
  54. } else if ($1 == "op_baseline") {
  55. # take average time for operations from baseline values with format:
  56. # op_baseline <opname> time_avg_us <t>
  57. op_baseline[$2] = $4;
  58. have_baseline = 1;
  59. }
  60. }
  61. function avg(sum, n) {
  62. if (n == 0) {
  63. return 0;
  64. } else {
  65. return sum / n;
  66. }
  67. }
  68. function stdev(sum, sum_sq, n) {
  69. if (n == 0) {
  70. return 0;
  71. } else {
  72. return sqrt(abs((sum_sq / n) - ((sum / n) * (sum / n))));
  73. }
  74. }
  75. END {
  76. for (x in op) {
  77. print "op", x, "count", op[x]["count"], "time_us", op[x]["time_us"], \
  78. "time_avg_us", avg(op[x]["time_us"], op[x]["count"]), \
  79. "stdev", stdev(op[x]["time_us"], op[x]["time_us_sq"], op[x]["count"]);
  80. }
  81. for (x in url) {
  82. for (y in url[x]) {
  83. print "url", x, "status", y, \
  84. "count", url[x][y]["count"], "time_us", url[x][y]["time_us"], \
  85. "time_avg_us", avg(url[x][y]["time_us"], url[x][y]["count"]), \
  86. "stdev", stdev(url[x][y]["time_us"], url[x][y]["time_us_sq"], url[x][y]["count"]), \
  87. "time_us_max", url[x][y]["time_us_max"], \
  88. "bytes_sent_avg", avg(url[x][y]["bytes_sent"], url[x][y]["count"]), \
  89. "bytes_received_avg", avg(url[x][y]["bytes_received"], url[x][y]["count"]);
  90. }
  91. }
  92. if (total_ops) {
  93. print "total_ops_ms", total_ops;
  94. }
  95. # Invoke awk with -V baseline_out=<filename> to extract baseline average
  96. if (baseline_out) {
  97. for (x in op) {
  98. print "op_baseline", x, "time_avg_us", avg(op[x]["time_us"], op[x]["count"]) > baseline_out
  99. }
  100. }
  101. if (have_baseline) {
  102. for (x in op) {
  103. total_ops_adjusted += op_baseline[x] * op[x]["count"];
  104. }
  105. print "total_ops_adjusted_ms", int(total_ops_adjusted);
  106. }
  107. }