display_perf_results.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. const headers = ["Test", "Line", "Units", "Fuchsia Avg", "Fuchsia Dev",
  5. "Fuchsia CV", "Linux Avg", "Linux Dev", "Linux CV",
  6. "F-L Avgs"];
  7. function generateHeader() {
  8. // Generates the header for a table of statistics.
  9. let header_row = document.createElement("tr");
  10. for (let i = 0; i < headers.length; i++){
  11. let header = document.createElement("th");
  12. header.appendChild(document.createTextNode(headers[i]));
  13. header_row.appendChild(header);
  14. }
  15. return header_row;
  16. }
  17. function generateTableHtmlFromOutputRows(output_rows) {
  18. // Takes a list of rows of data, and collects them together into a single
  19. // table.
  20. let table = document.createElement("table");
  21. table.appendChild(generateHeader());
  22. output_rows.forEach(function(row){
  23. let doc_row = document.createElement("tr");
  24. row.forEach(function(datum){
  25. let item = document.createElement("td");
  26. item.appendChild(document.createTextNode(datum));
  27. doc_row.appendChild(item);
  28. });
  29. table.appendChild(doc_row);
  30. });
  31. return table;
  32. }
  33. function extractStats(line) {
  34. // Deconstructs the JSON file given into a list of the relevant values.
  35. return [line.fuchsia_avg,
  36. line.fuchsia_dev,
  37. line.fuchsia_cv,
  38. line.linux_avg,
  39. line.linux_dev,
  40. line.linux_cv,
  41. line.fuchsia_avg - line.linux_avg];
  42. }
  43. function renderTable(obj_dict) {
  44. // Returns an HTML table object by taking the TargetResults JSON and using it
  45. // to populate a table of statistics.
  46. let rows = []
  47. const name = obj_dict['name']
  48. const tests = obj_dict['tests'];
  49. Object.keys(tests).forEach(function(test_name) {
  50. const test = tests[test_name];
  51. const test_stats = extractStats(test)
  52. let test_row = [test_name, "Test Totals", test['unit']].concat(test_stats);
  53. rows.push(test_row)
  54. const lines = test['lines']
  55. Object.keys(lines).forEach(function(line_key) {
  56. const line = lines[line_key];
  57. const line_stats = extractStats(line);
  58. let line_row = [test_name, line_key, line['unit']].concat(line_stats);
  59. rows.push(line_row);
  60. });
  61. rows.push([]);
  62. });
  63. return generateTableHtmlFromOutputRows(rows);
  64. }
  65. function loadTable() {
  66. // Reads the result files, and adds the tables generated to the table_div HTML
  67. // object as they finish loading.
  68. let files = document.getElementById('files').files;
  69. let table_div = document.getElementById('stats_div');
  70. // Clear the table div of all prior stats tables
  71. while (table_div.firstChild)
  72. table_div.removeChild(table_div.firstChild);
  73. for (let i = 0; i < files.length; i++){
  74. let file = files[0];
  75. let reader = new FileReader();
  76. reader.addEventListener('loadend', function(contents) {
  77. let json_parsed = JSON.parse(reader.result)
  78. let table = renderTable(json_parsed);
  79. table_div.appendChild(table);
  80. });
  81. reader.readAsBinaryString(file);
  82. }
  83. }