crunch-results.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //
  2. // Pipe the output of server.js into this to convert raw test results into bracketed statistics
  3. // suitable for graphing.
  4. //
  5. // Time duration per statistical bracket
  6. var BRACKET_SIZE = 10000;
  7. // Number of bytes expected from each test
  8. var EXPECTED_BYTES = 5000;
  9. var readline = require('readline');
  10. var rl = readline.createInterface({
  11. input: process.stdin,
  12. output: process.stdout,
  13. terminal: false
  14. });
  15. var count = 0.0;
  16. var overallCount = 0.0;
  17. var totalFailures = 0.0;
  18. var totalOverallFailures = 0.0;
  19. var totalMs = 0;
  20. var totalData = 0;
  21. var devices = {};
  22. var lastBracketTs = 0;
  23. rl.on('line',function(line) {
  24. line = line.trim();
  25. var ls = line.split(',');
  26. if (ls.length == 7) {
  27. var ts = parseInt(ls[0]);
  28. var fromId = ls[1];
  29. var toId = ls[2];
  30. var ms = parseFloat(ls[3]);
  31. var bytes = parseInt(ls[4]);
  32. var timedOut = (ls[5] == 'true') ? true : false;
  33. var errMsg = ls[6];
  34. count += 1.0;
  35. overallCount += 1.0;
  36. if ((bytes !== EXPECTED_BYTES)||(timedOut)) {
  37. totalFailures += 1.0;
  38. totalOverallFailures += 1.0;
  39. }
  40. totalMs += ms;
  41. totalData += bytes;
  42. devices[fromId] = true;
  43. devices[toId] = true;
  44. if (lastBracketTs === 0)
  45. lastBracketTs = ts;
  46. if (((ts - lastBracketTs) >= BRACKET_SIZE)&&(count > 0.0)) {
  47. console.log(count.toString()+','+overallCount.toString()+','+(totalMs / count)+','+(totalFailures / count)+','+(totalOverallFailures / overallCount)+','+totalData+','+Object.keys(devices).length);
  48. count = 0.0;
  49. totalFailures = 0.0;
  50. totalMs = 0;
  51. totalData = 0;
  52. lastBracketTs = ts;
  53. }
  54. } // else ignore junk
  55. });