callstats.html 71.9 KB
Newer Older
1
<!DOCTYPE html>
2 3 4 5 6 7 8
<html>
<!--
Copyright 2016 the V8 project authors. All rights reserved.  Use of this source
code is governed by a BSD-style license that can be found in the LICENSE file.
-->

<head>
9 10
  <meta charset="utf-8">
  <title>V8 Runtime Stats Komparator</title>
11 12 13 14
  <style>
    body {
      font-family: arial;
    }
15

16 17 18 19
    table {
      display: table;
      border-spacing: 0px;
    }
20

21 22 23 24
    tr {
      border-spacing: 0px;
      padding: 10px;
    }
25

26 27 28 29
    td,
    th {
      padding: 3px 10px 3px 5px;
    }
30

31 32 33 34
    .inline {
      display: inline-block;
      vertical-align: top;
    }
35

36 37 38 39
    h2,
    h3 {
      margin-bottom: 0px;
    }
40

41 42 43
    .hidden {
      display: none;
    }
44

45 46 47
    .view {
      display: table;
    }
48

49 50 51 52 53
    .column {
      display: table-cell;
      border-right: 1px black dotted;
      min-width: 200px;
    }
54

55 56 57
    .column .header {
      padding: 0 10px 0 10px
    }
58

59 60 61
    #column {
      display: none;
    }
62

63 64 65
    .list {
      width: 100%;
    }
66

67 68 69
    select {
      width: 100%
    }
70

71 72 73
    .list tbody {
      cursor: pointer;
    }
74

75 76 77
    .list tr:nth-child(even) {
      background-color: #EFEFEF;
    }
78

79 80 81
    .list tr:nth-child(even).selected {
      background-color: #DDD;
    }
82

83 84 85
    .list tr.child {
      display: none;
    }
86

87 88 89
    .list tr.child.visible {
      display: table-row;
    }
90

91 92 93
    .list .child .name {
      padding-left: 20px;
    }
94

95 96 97
    .list .parent td {
      border-top: 1px solid #AAA;
    }
98

99 100 101
    .list .total {
      font-weight: bold
    }
102

103 104 105
    .list tr.parent {
      background-color: #FFF;
    }
106

107 108 109
    .list tr.parent.selected {
      background-color: #DDD;
    }
110

111 112 113
    tr.selected {
      background-color: #DDD;
    }
114

115 116 117 118 119 120 121 122
    .codeSearch {
      display: block-inline;
      float: right;
      border-radius: 5px;
      background-color: #EEE;
      width: 1em;
      text-align: center;
    }
123

124 125 126 127
    .list .position {
      text-align: right;
      display: none;
    }
128

129 130 131
    .list div.toggle {
      cursor: pointer;
    }
132

133 134 135
    #column_0 .position {
      display: table-cell;
    }
136

137 138 139
    #column_0 .name {
      display: table-cell;
    }
140

141 142 143 144
    .list .name {
      display: none;
      white-space: nowrap;
    }
145

146 147 148
    .value {
      text-align: right;
    }
149

150 151 152
    .selectedVersion {
      font-weight: bold;
    }
153

154 155 156
    #baseline {
      width: auto;
    }
157

158 159 160
    .compareSelector {
      padding-bottom: 20px;
    }
161

162 163 164
    .pageDetailTable tbody {
      cursor: pointer
    }
165

166 167 168
    .pageDetailTable tfoot td {
      border-top: 1px grey solid;
    }
169

170 171 172 173 174 175 176 177 178 179
    #popover {
      position: absolute;
      transform: translateY(-50%) translateX(40px);
      box-shadow: -2px 10px 44px -10px #000;
      border-radius: 5px;
      z-index: 1;
      background-color: #FFF;
      display: none;
      white-space: nowrap;
    }
180

181 182 183 184 185 186 187 188 189 190
    #popover table {
      position: relative;
      z-index: 1;
      text-align: right;
      margin: 10px;
    }
    #popover td {
      padding: 3px 0px 3px 5px;
      white-space: nowrap;
    }
191

192 193 194 195 196 197 198 199 200 201
    .popoverArrow {
      background-color: #FFF;
      position: absolute;
      width: 30px;
      height: 30px;
      transform: translateY(-50%)rotate(45deg);
      top: 50%;
      left: -10px;
      z-index: 0;
    }
202

203 204 205 206 207
    #popover .name {
      padding: 5px;
      font-weight: bold;
      text-align: center;
    }
208

209 210 211
    #popover table .compare {
      display: none
    }
212

213 214 215
    #popover table.compare .compare {
      display: table-cell;
    }
216 217 218 219 220

    #popover .compare .time,
    #popover .compare .version {
      padding-left: 10px;
    }
221 222 223 224 225 226 227 228 229 230 231
    .graph,
    .graph .content {
      width: 100%;
    }

    .diff .hideDiff {
      display: none;
    }
    .noDiff .hideNoDiff {
      display: none;
    }
232
  </style>
233 234
  <script src="https://www.gstatic.com/charts/loader.js"></script>
  <script>
235
    "use strict"
236
    google.charts.load('current', {packages: ['corechart']});
237 238 239 240

    // Did anybody say monkeypatching?
    if (!NodeList.prototype.forEach) {
      NodeList.prototype.forEach = function(func) {
241
        for (let i = 0; i < this.length; i++) {
242 243 244 245 246
          func(this[i]);
        }
      }
    }

247 248 249 250 251
    let versions;
    let pages;
    let selectedPage;
    let baselineVersion;
    let selectedEntry;
252

253
    // Marker to programatically replace the defaultData.
254
    let defaultData = /*default-data-start*/undefined/*default-data-end*/;
255 256

    function initialize() {
257
      // Initialize the stats table and toggle lists.
258 259
      let original = $("column");
      let view = document.createElement('div');
260
      view.id = 'view';
261
      let i = 0;
262 263
      versions.forEach((version) =>  {
        if (!version.enabled) return;
264
        // add column
265
        let column = original.cloneNode(true);
266 267
        column.id = "column_" + i;
        // Fill in all versions
268
        let select = column.querySelector(".version");
269 270 271
        select.id = "selectVersion_" + i;
        // add all select options
        versions.forEach((version) => {
272
          if (!version.enabled) return;
273
          let option = document.createElement("option");
274 275 276 277 278 279 280
          option.textContent = version.name;
          option.version = version;
          select.appendChild(option);
        });
        // Fill in all page versions
        select = column.querySelector(".pageVersion");
        select.id = "select_" + i;
281
        // add all pages
282
        versions.forEach((version) => {
283
          if (!version.enabled) return;
284
          let optgroup = document.createElement("optgroup");
285 286
          optgroup.label = version.name;
          optgroup.version = version;
287
          version.forEachPage((page) => {
288
            let option = document.createElement("option");
289 290 291 292 293 294
            option.textContent = page.name;
            option.page = page;
            optgroup.appendChild(option);
          });
          select.appendChild(optgroup);
        });
295 296 297
        view.appendChild(column);
        i++;
      });
298
      let oldView = $('view');
299
      oldView.parentNode.replaceChild(view, oldView);
300

301
      let select = $('baseline');
302 303 304
      removeAllChildren(select);
      select.appendChild(document.createElement('option'));
      versions.forEach((version) => {
305
        let option = document.createElement("option");
306 307 308 309
        option.textContent = version.name;
        option.version = version;
        select.appendChild(option);
      });
310 311
      initializeToggleList(versions.versions, $('versionSelector'));
      initializeToggleList(pages.values(), $('pageSelector'));
312
      initializeToggleList(Group.groups.values(), $('groupSelector'));
313 314
      initializeToggleContentVisibility();
    }
315

316
    function initializeToggleList(items, node) {
317
      let list = node.querySelector('ul');
318 319 320 321
      removeAllChildren(list);
      items = Array.from(items);
      items.sort(NameComparator);
      items.forEach((item) => {
322 323
        let li = document.createElement('li');
        let checkbox = document.createElement('input');
324
        checkbox.type = 'checkbox';
325 326
        checkbox.checked = item.enabled;
        checkbox.item = item;
327
        checkbox.addEventListener('click', handleToggleVersionOrPageEnable);
328
        li.appendChild(checkbox);
329 330
        li.appendChild(document.createTextNode(item.name));
        list.appendChild(li);
331
      });
332 333
      $('results').querySelectorAll('#results > .hidden').forEach((node) => {
        toggleCssClass(node, 'hidden', false);
334 335 336 337
      })
    }

    function initializeToggleContentVisibility() {
338
      let nodes = document.querySelectorAll('.toggleContentVisibility');
339
      nodes.forEach((node) => {
340 341
        let content = node.querySelector('.content');
        let header = node.querySelector('h1,h2,h3');
342 343
        if (content === undefined || header === undefined) return;
        if (header.querySelector('input') != undefined) return;
344
        let checkbox = document.createElement('input');
345 346 347 348 349
        checkbox.type = 'checkbox';
        checkbox.checked = content.className.indexOf('hidden') == -1;
        checkbox.contentNode = content;
        checkbox.addEventListener('click', handleToggleContentVisibility);
        header.insertBefore(checkbox, header.childNodes[0]);
350 351 352
      });
    }

353 354 355 356 357 358 359
    window.addEventListener('popstate', (event) => {
      popHistoryState(event.state);
    });

    function popHistoryState(state) {
      if (!state.version) return false;
      if (!versions) return false;
360
      let version = versions.getByName(state.version);
361
      if (!version) return false;
362
      let page = version.get(state.page);
363 364
      if (!page) return false;
      if (!state.entry) {
365
        showEntry(page.total);
366
      } else {
367
        let entry = page.get(state.entry);
368
        if (!entry) {
369
          showEntry(page.total);
370 371 372 373 374 375 376 377
        } else {
          showEntry(entry);
        }
      }
      return true;
    }

    function pushHistoryState() {
378
      let selection = selectedEntry ? selectedEntry : selectedPage;
379
      if (!selection) return;
380
      let state = selection.urlParams();
381 382
      // Don't push a history state if it didn't change.
      if (JSON.stringify(window.history.state) === JSON.stringify(state)) return;
383 384
      let params = "?";
      for (let pairs of Object.entries(state)) {
385 386 387 388 389 390
        params += encodeURIComponent(pairs[0]) + "="
            + encodeURIComponent(pairs[1]) + "&";
      }
      window.history.pushState(state, selection.toString(), params);
    }

391 392
    function showSelectedEntryInPage(page) {
      if (!selectedEntry) return showPage(page);
393
      let entry = page.get(selectedEntry.name);
394 395 396 397
      if (!entry) return showPage(page);
      selectEntry(entry);
    }

398
    function showPage(firstPage) {
399
      let changeSelectedEntry = selectedEntry !== undefined
400
          && selectedEntry.page === selectedPage;
401 402 403 404
      selectedPage = firstPage;
      selectedPage.sort();
      showPageInColumn(firstPage, 0);
      // Show the other versions of this page in the following columns.
405 406
      let pageVersions = versions.getPageVersions(firstPage);
      let index = 1;
407 408 409 410 411 412
      pageVersions.forEach((page) => {
        if (page !== firstPage) {
          showPageInColumn(page, index);
          index++;
        }
      });
413 414 415
      if (changeSelectedEntry) {
        showEntryDetail(selectedPage.getEntry(selectedEntry));
      }
416
      showImpactList(selectedPage);
417
      pushHistoryState();
418 419 420 421
    }

    function showPageInColumn(page, columnIndex) {
      page.sort();
422
      let showDiff = (baselineVersion === undefined && columnIndex !== 0) ||
423
        (baselineVersion !== undefined && page.version !== baselineVersion);
424
      let diffStatus = (td, a, b) => {};
425 426 427 428 429 430 431 432 433
      if (showDiff) {
        if (baselineVersion !== undefined) {
          diffStatus = (td, a, b) => {
            if (a == 0) return;
            td.style.color = a < 0 ? '#FF0000' : '#00BB00';
          };
        } else {
          diffStatus = (td, a, b) => {
            if (a == b) return;
434 435
            let color;
            let ratio = a / b;
436 437 438 439 440 441 442 443 444 445 446 447
            if (ratio > 1) {
              ratio = Math.min(Math.round((ratio - 1) * 255 * 10), 200);
              color = '#' + ratio.toString(16) + "0000";
            } else {
              ratio = Math.min(Math.round((1 - ratio) * 255 * 10), 200);
              color = '#00' + ratio.toString(16) + "00";
            }
            td.style.color = color;
          }
        }
      }

448 449
      let column = $('column_' + columnIndex);
      let select = $('select_' + columnIndex);
450 451 452 453
      // Find the matching option
      selectOption(select, (i, option) => {
        return option.page == page
      });
454 455 456 457
      let table = column.querySelector("table");
      let oldTbody = table.querySelector('tbody');
      let tbody = document.createElement('tbody');
      let referencePage = selectedPage;
458
      page.forEachSorted(selectedPage, (parentEntry, entry, referenceEntry) => {
459
        let tr = document.createElement('tr');
460 461 462
        tbody.appendChild(tr);
        tr.entry = entry;
        tr.parentEntry = parentEntry;
463
        tr.className = parentEntry === undefined ? 'parent' : 'child';
464 465 466 467 468
        // Don't show entries that do not exist on the current page or if we
        // compare against the current page
        if (entry !== undefined && page.version !== baselineVersion) {
          // If we show a diff, use the baselineVersion as the referenceEntry
          if (baselineVersion !== undefined) {
469
            let baselineEntry = baselineVersion.getEntry(entry);
470 471 472
            if (baselineEntry !== undefined) referenceEntry = baselineEntry
          }
          if (!parentEntry) {
473
            let node = td(tr, '<div class="toggle">►</div>', 'position');
474 475 476 477
            node.firstChild.addEventListener('click', handleToggleGroup);
          } else {
            td(tr, entry.position == 0 ? '' : entry.position, 'position');
          }
478 479
          addCodeSearchButton(entry,
              td(tr, entry.name, 'name ' + entry.cssClass()));
480

481 482 483 484 485 486 487 488 489
          diffStatus(
            td(tr, ms(entry.time), 'value time'),
            entry.time, referenceEntry.time);
          diffStatus(
            td(tr, percent(entry.timePercent), 'value time'),
            entry.time, referenceEntry.time);
          diffStatus(
            td(tr, count(entry.count), 'value count'),
            entry.count, referenceEntry.count);
490
        } else if (baselineVersion !== undefined && referenceEntry
491 492
            && page.version !== baselineVersion) {
          // Show comparison of entry that does not exist on the current page.
493 494
          tr.entry = new Entry(0, referenceEntry.name);
          tr.entry.page = page;
495 496 497
          td(tr, '-', 'position');
          td(tr, referenceEntry.name, 'name');
          diffStatus(
498 499
            td(tr, ms(referenceEntry.time), 'value time'),
            referenceEntry.time, 0);
500
          diffStatus(
501 502
            td(tr, percent(referenceEntry.timePercent), 'value time'),
            referenceEntry.timePercent, 0);
503
          diffStatus(
504 505
            td(tr, count(referenceEntry.count), 'value count'),
            referenceEntry.count, 0);
506 507
        } else {
          // Display empty entry / baseline entry
508
          let showBaselineEntry = entry !== undefined;
509
          if (showBaselineEntry) {
510
            if (!parentEntry) {
511
              let node = td(tr, '<div class="toggle">►</div>', 'position');
512 513 514 515 516
              node.firstChild.addEventListener('click', handleToggleGroup);
            } else {
              td(tr, entry.position == 0 ? '' : entry.position, 'position');
            }
            td(tr, entry.name, 'name');
517 518 519
            td(tr, ms(entry.time, false), 'value time');
            td(tr, percent(entry.timePercent, false), 'value time');
            td(tr, count(entry.count, false), 'value count');
520 521
          } else {
            td(tr, '-', 'position');
522
            td(tr, referenceEntry.name, 'name');
523 524 525
            td(tr, '-', 'value time');
            td(tr, '-', 'value time');
            td(tr, '-', 'value count');
526 527 528 529
          }
        }
      });
      table.replaceChild(tbody, oldTbody);
530
      let versionSelect = column.querySelector('select.version');
531 532 533 534 535
      selectOption(versionSelect, (index, option) => {
        return option.version == page.version
      });
    }

536 537 538 539
    function showEntry(entry) {
      selectEntry(entry, true);
    }

540
    function selectEntry(entry, updateSelectedPage) {
541
      let needsPageSwitch = true;
542
      if (updateSelectedPage && selectedPage) {
543
        entry = selectedPage.version.getEntry(entry);
544
        needsPageSwitch = updateSelectedPage && entry.page != selectedPage;
545
      }
546
      let rowIndex = 0;
547 548
      // If clicked in the detail row change the first column to that page.
      if (needsPageSwitch) showPage(entry.page);
549 550
      let childNodes = $('column_0').querySelector('.list tbody').childNodes;
      for (let i = 0; i < childNodes.length; i++) {
551 552
        if (childNodes[i].entry !== undefined &&
            childNodes[i].entry.name == entry.name) {
553 554 555 556
          rowIndex = i;
          break;
        }
      }
557
      let firstEntry = childNodes[rowIndex].entry;
558 559 560 561 562 563 564 565 566
      if (rowIndex) {
        if (firstEntry.parent) showGroup(firstEntry.parent);
      }
      // Deselect all
      $('view').querySelectorAll('.list tbody tr').forEach((tr) => {
        toggleCssClass(tr, 'selected', false);
      });
      // Select the entry row
      $('view').querySelectorAll("tbody").forEach((body) => {
567
        let row = body.childNodes[rowIndex];
568
        if (!row) return;
569 570
        toggleCssClass(row, 'selected', row.entry && row.entry.name ==
          firstEntry.name);
571
      });
572
      if (updateSelectedPage && selectedEntry) {
573 574
        entry = selectedEntry.page.version.getEntry(entry);
      }
575 576 577 578
      if (entry !== selectedEntry) {
        selectedEntry = entry;
        showEntryDetail(entry);
      }
579 580 581
    }

    function showEntryDetail(entry) {
582 583 584 585
      showVersionDetails(entry);
      showPageDetails(entry);
      showImpactList(entry.page);
      showGraphs(entry.page);
586
      pushHistoryState();
587
    }
588

589
    function showVersionDetails(entry) {
590
      let table, tbody, entries;
591 592 593
      table = $('detailView').querySelector('.versionDetailTable');
      tbody = document.createElement('tbody');
      if (entry !== undefined) {
594
        $('detailView').querySelector('.versionDetail h3 span').textContent =
595 596
          entry.name + ' in ' + entry.page.name;
        entries = versions.getPageVersions(entry.page).map(
597 598 599 600 601 602 603 604
          (page) => {
            return page.get(entry.name)
          });
        entries.sort((a, b) => {
          return a.time - b.time
        });
        entries.forEach((pageEntry) => {
          if (pageEntry === undefined) return;
605
          let tr = document.createElement('tr');
606 607
          if (pageEntry == entry) tr.className += 'selected';
          tr.entry = pageEntry;
608
          let isBaselineEntry = pageEntry.page.version == baselineVersion;
609
          td(tr, pageEntry.page.version.name, 'version');
610 611 612
          td(tr, ms(pageEntry.time, !isBaselineEntry), 'value time');
          td(tr, percent(pageEntry.timePercent, !isBaselineEntry), 'value time');
          td(tr, count(pageEntry.count, !isBaselineEntry), 'value count');
613 614 615 616
          tbody.appendChild(tr);
        });
      }
      table.replaceChild(tbody, table.querySelector('tbody'));
617
    }
618

619
    function showPageDetails(entry) {
620
      let table, tbody, entries;
621 622
      table = $('detailView').querySelector('.pageDetailTable');
      tbody = document.createElement('tbody');
623 624 625
      if (entry === undefined) {
        table.replaceChild(tbody, table.querySelector('tbody'));
        return;
626
      }
627 628
      let version = entry.page.version;
      let showDiff = version !== baselineVersion;
629
      $('detailView').querySelector('.pageDetail h3 span').textContent =
630 631 632 633 634 635
        version.name;
      entries = version.pages.map((page) => {
          if (!page.enabled) return;
          return page.get(entry.name)
        });
      entries.sort((a, b) => {
636
        let cmp = b.timePercent - a.timePercent;
637 638 639 640 641
        if (cmp.toFixed(1) == 0) return b.time - a.time;
        return cmp
      });
      entries.forEach((pageEntry) => {
        if (pageEntry === undefined) return;
642
        let tr = document.createElement('tr');
643 644 645 646 647 648 649 650 651 652 653
        if (pageEntry === entry) tr.className += 'selected';
        tr.entry = pageEntry;
        td(tr, pageEntry.page.name, 'name');
        td(tr, ms(pageEntry.time, showDiff), 'value time');
        td(tr, percent(pageEntry.timePercent, showDiff), 'value time');
        td(tr, percent(pageEntry.timePercentPerEntry, showDiff),
            'value time hideNoDiff');
        td(tr, count(pageEntry.count, showDiff), 'value count');
        tbody.appendChild(tr);
      });
      // show the total for all pages
654
      let tds = table.querySelectorAll('tfoot td');
655
      tds[1].textContent = ms(entry.getTimeImpact(), showDiff);
656
      // Only show the percentage total if we are in diff mode:
657 658 659
      tds[2].textContent = percent(entry.getTimePercentImpact(), showDiff);
      tds[3].textContent = '';
      tds[4].textContent = count(entry.getCountImpact(), showDiff);
660 661 662 663
      table.replaceChild(tbody, table.querySelector('tbody'));
    }

    function showImpactList(page) {
664
      let impactView = $('detailView').querySelector('.impactView');
665
      impactView.querySelector('h3 span').textContent = page.version.name;
666

667 668 669 670
      let table = impactView.querySelector('table');
      let tbody = document.createElement('tbody');
      let version = page.version;
      let entries = version.allEntries();
671
      if (selectedEntry !== undefined && selectedEntry.isGroup) {
672
        impactView.querySelector('h3 span').textContent += " " + selectedEntry.name;
673 674 675 676 677
        entries = entries.filter((entry) => {
          return entry.name == selectedEntry.name ||
            (entry.parent && entry.parent.name == selectedEntry.name)
        });
      }
678
      let isCompareView = baselineVersion !== undefined;
679 680
      entries = entries.filter((entry) => {
        if (isCompareView) {
681
          let impact = entry.getTimeImpact();
682 683
          return impact < -1 || 1 < impact
        }
684
        return entry.getTimePercentImpact() > 0.01;
685
      });
686
      entries = entries.slice(0, 50);
687
      entries.sort((a, b) => {
688
        let cmp = b.getTimePercentImpact() - a.getTimePercentImpact();
689 690 691 692
        if (isCompareView || cmp.toFixed(1) == 0) {
          return b.getTimeImpact() - a.getTimeImpact();
        }
        return cmp
693 694
      });
      entries.forEach((entry) => {
695
        let tr = document.createElement('tr');
696 697 698
        tr.entry = entry;
        td(tr, entry.name, 'name');
        td(tr, ms(entry.getTimeImpact()), 'value time');
699
        let percentImpact = entry.getTimePercentImpact();
700
        td(tr, percentImpact > 1000 ? '-' : percent(percentImpact), 'value time');
701
        let topPages = entry.getPagesByPercentImpact().slice(0, 3)
702
          .map((each) => {
703 704
            return each.name + ' (' + percent(each.getEntry(entry).timePercent) +
              ')'
705 706 707 708 709 710
          });
        td(tr, topPages.join(', '), 'name');
        tbody.appendChild(tr);
      });
      table.replaceChild(tbody, table.querySelector('tbody'));
    }
711

712
    function showGraphs(page) {
713
      let groups = page.groups.filter(each => each.enabled);
714 715 716 717
      // Sort groups by the biggest impact
      groups.sort((a, b) => {
        return b.getTimeImpact() - a.getTimeImpact();
      });
718 719 720
      if (selectedGroup == undefined) {
        selectedGroup = groups[0];
      } else {
721
        groups = groups.filter(each => each.name != selectedGroup.name);
722 723
        groups.unshift(selectedGroup);
      }
724 725 726 727
      showPageGraph(groups, page);
      showVersionGraph(groups, page);
      showPageVersionGraph(groups, page);
    }
728

729
    function getGraphDataTable(groups) {
730
      let dataTable = new google.visualization.DataTable();
731 732
      dataTable.addColumn('string', 'Name');
      groups.forEach(group => {
733
        let column = dataTable.addColumn('number', group.name.substring(6));
734 735
        dataTable.setColumnProperty(column, 'group', group);
      });
736 737 738
      return dataTable;
    }

739
    let selectedGroup;
740
    function showPageGraph(groups, page) {
741 742
      let isDiffView = baselineVersion !== undefined;
      let dataTable = getGraphDataTable(groups);
743
      // Calculate the average row
744
      let row = ['Average'];
745
      groups.forEach((group) => {
746 747 748 749 750
        if (isDiffView) {
          row.push(group.isTotal ? 0 : group.getAverageTimeImpact());
        } else {
          row.push(group.isTotal ? 0 : group.getTimeImpact());
        }
751 752 753
      });
      dataTable.addRow(row);
      // Sort the pages by the selected group.
754
      let pages = page.version.pages.filter(page => page.enabled);
755
      function sumDiff(page) {
756
        let sum = 0;
757
        groups.forEach(group => {
758
          let value = group.getTimePercentImpact() -
759 760 761 762 763 764 765 766
            page.getEntry(group).timePercent;
          sum += value * value;
        });
        return sum;
      }
      if (isDiffView) {
        pages.sort((a, b) => {
          return b.getEntry(selectedGroup).time-
767
            a.getEntry(selectedGroup).time;
768 769 770 771
        });
      } else {
        pages.sort((a, b) => {
          return b.getEntry(selectedGroup).timePercent -
772
            a.getEntry(selectedGroup).timePercent;
773 774 775 776
        });
      }
      // Sort by sum of squared distance to the average.
      // pages.sort((a, b) => {
777
      //   return a.distanceFromTotalPercent() - b.distanceFromTotalPercent();
778
      // });
779
      // Calculate the entries for the pages
780
      pages.forEach((page) => {
781 782
        row = [page.name];
        groups.forEach((group) => {
783
          row.push(group.isTotal ? 0 : page.getEntry(group).time);
784
        });
785
        let rowIndex = dataTable.addRow(row);
786
        dataTable.setRowProperty(rowIndex, 'page', page);
787
      });
788 789 790
      renderGraph('Pages for ' + page.version.name, groups, dataTable,
          'pageGraph', isDiffView ? true : 'percent');
    }
791

792
    function showVersionGraph(groups, page) {
793 794 795
      let dataTable = getGraphDataTable(groups);
      let row;
      let vs = versions.versions.filter(version => version.enabled);
796 797
      vs.sort((a, b) => {
        return b.getEntry(selectedGroup).getTimeImpact() -
798
          a.getEntry(selectedGroup).getTimeImpact();
799
      });
800 801
      // Calculate the entries for the versions
      vs.forEach((version) => {
802 803 804 805
        row = [version.name];
        groups.forEach((group) => {
          row.push(group.isTotal ? 0 : version.getEntry(group).getTimeImpact());
        });
806
        let rowIndex = dataTable.addRow(row);
807 808 809 810 811 812 813
        dataTable.setRowProperty(rowIndex, 'page', page);
      });
      renderGraph('Versions Total Time over all Pages', groups, dataTable,
          'versionGraph', true);
    }

    function showPageVersionGraph(groups, page) {
814 815 816
      let dataTable = getGraphDataTable(groups);
      let row;
      let vs = versions.getPageVersions(page);
817
      vs.sort((a, b) => {
818
        return b.getEntry(selectedGroup).time - a.getEntry(selectedGroup).time;
819
      });
820 821
      // Calculate the entries for the versions
      vs.forEach((page) => {
822 823 824 825
        row = [page.version.name];
        groups.forEach((group) => {
          row.push(group.isTotal ? 0 : page.getEntry(group).time);
        });
826
        let rowIndex = dataTable.addRow(row);
827 828 829 830 831 832 833
        dataTable.setRowProperty(rowIndex, 'page', page);
      });
      renderGraph('Versions for ' + page.name, groups, dataTable,
          'pageVersionGraph', true);
    }

    function renderGraph(title, groups, dataTable, id, isStacked) {
834 835
      let isDiffView = baselineVersion !== undefined;
      let formatter = new google.visualization.NumberFormat({
836 837
        suffix: (isDiffView ? 'msΔ' : 'ms'),
        negativeColor: 'red',
838 839
        groupingSymbol: "'"
      });
840
      for (let i = 1; i < dataTable.getNumberOfColumns(); i++) {
841 842
        formatter.format(dataTable, i);
      }
843 844
      let height = 85 + 28 * dataTable.getNumberOfRows();
      let options = {
845 846
        isStacked: isStacked,
        height: height,
847 848
        hAxis: {
          minValue: 0,
849
          textStyle: { fontSize: 14 }
850
        },
851
        animation:{
852
          duration: dataTable.getNumberOfRows() > 50 ? 0 : 500 ,
853 854
          easing: 'out',
        },
855
        vAxis: {
856
          textStyle: { fontSize: 14 }
857
        },
858
        tooltip: { textStyle: { fontSize: 14 }},
859 860 861 862
        explorer: {
          actions: ['dragToZoom', 'rightClickToReset'],
          maxZoomIn: 0.01
        },
863
        legend: {position:'top', maxLines: 1, textStyle: { fontSize: 14 }},
864 865
        chartArea: {left:200, top:50, width:'98%', height:'80%'},
        colors: groups.map(each => each.color)
866
      };
867
      let parentNode = $(id);
868
      parentNode.querySelector('h2>span, h3>span').textContent = title;
869
      let graphNode = parentNode.querySelector('.content');
870

871
      let chart = graphNode.chart;
872 873 874 875 876
      if (chart === undefined) {
        chart = graphNode.chart = new google.visualization.BarChart(graphNode);
      } else {
        google.visualization.events.removeAllListeners(chart);
      }
877
      google.visualization.events.addListener(chart, 'select', selectHandler);
878 879
      function getChartEntry(selection) {
        if (!selection) return undefined;
880
        let column = selection.column;
881
        if (column == undefined) return undefined;
882 883
        let selectedGroup = dataTable.getColumnProperty(column, 'group');
        let row = selection.row;
884
        if (row == null) return selectedGroup;
885
        let page = dataTable.getRowProperty(row, 'page');
886 887 888
        if (!page) return selectedGroup;
        return page.getEntry(selectedGroup);
      }
889
      function selectHandler() {
890 891 892
        selectedGroup = getChartEntry(chart.getSelection()[0])
        if (!selectedGroup) return;
        selectEntry(selectedGroup, true);
893
      }
894 895 896 897 898 899 900

      // Make our global tooltips work
      google.visualization.events.addListener(chart, 'onmouseover', mouseOverHandler);
      function mouseOverHandler(selection) {
        graphNode.entry = getChartEntry(selection);
      }
      chart.draw(dataTable, options);
901
    }
902 903 904 905 906 907 908

    function showGroup(entry) {
      toggleGroup(entry, true);
    }

    function toggleGroup(group, show) {
      $('view').querySelectorAll(".child").forEach((tr) => {
909
        let entry = tr.parentEntry;
910 911 912 913 914 915 916
        if (!entry) return;
        if (entry.name !== group.name) return;
        toggleCssClass(tr, 'visible', show);
      });
    }

    function showPopover(entry) {
917
      let popover = $('popover');
918 919
      popover.querySelector('td.name').textContent = entry.name;
      popover.querySelector('td.page').textContent = entry.page.name;
920 921 922 923 924 925 926 927 928 929
      setPopoverDetail(popover, entry, '');
      popover.querySelector('table').className = "";
      if (baselineVersion !== undefined) {
        entry = baselineVersion.getEntry(entry);
        setPopoverDetail(popover, entry, '.compare');
        popover.querySelector('table').className = "compare";
      }
    }

    function setPopoverDetail(popover, entry, prefix) {
930
      let node = (name) => popover.querySelector(prefix + name);
931
      if (entry == undefined) {
932 933 934 935 936 937 938 939 940 941
        node('.version').textContent = baselineVersion.name;
        node('.time').textContent = '-';
        node('.timeVariance').textContent = '-';
        node('.percent').textContent = '-';
        node('.percentPerEntry').textContent = '-';
        node('.percentVariance').textContent  = '-';
        node('.count').textContent =  '-';
        node('.countVariance').textContent = '-';
        node('.timeImpact').textContent = '-';
        node('.timePercentImpact').textContent = '-';
942
      } else {
943 944 945
        node('.version').textContent = entry.page.version.name;
        node('.time').textContent = ms(entry._time, false);
        node('.timeVariance').textContent
946
            = percent(entry.timeVariancePercent, false);
947 948
        node('.percent').textContent = percent(entry.timePercent, false);
        node('.percentPerEntry').textContent
949
            = percent(entry.timePercentPerEntry, false);
950
        node('.percentVariance').textContent
951
            = percent(entry.timePercentVariancePercent, false);
952 953
        node('.count').textContent = count(entry._count, false);
        node('.countVariance').textContent
954
            = percent(entry.timeVariancePercent, false);
955
        node('.timeImpact').textContent
956
            = ms(entry.getTimeImpact(false), false);
957
        node('.timePercentImpact').textContent
958 959
            = percent(entry.getTimeImpactVariancePercent(false), false);
      }
960
    }
961
  </script>
962
  <script>
963 964
  "use strict"
    // =========================================================================
965 966 967 968 969 970 971 972 973 974 975 976
    // Helpers
    function $(id) {
      return document.getElementById(id)
    }

    function removeAllChildren(node) {
      while (node.firstChild) {
        node.removeChild(node.firstChild);
      }
    }

    function selectOption(select, match) {
977 978
      let options = select.options;
      for (let i = 0; i < options.length; i++) {
979 980 981 982 983 984 985
        if (match(i, options[i])) {
          select.selectedIndex = i;
          return;
        }
      }
    }

986 987
    function addCodeSearchButton(entry, node) {
      if (entry.isGroup) return;
988
      let button = document.createElement("div");
989
      button.textContent = '?'
990 991 992 993 994 995
      button.className = "codeSearch"
      button.addEventListener('click', handleCodeSearch);
      node.appendChild(button);
      return node;
    }

996
    function td(tr, content, className) {
997
      let td = document.createElement("td");
998 999 1000 1001 1002
      if (content[0] == '<') {
        td.innerHTML = content;
      } else {
        td.textContent = content;
      }
1003 1004 1005 1006 1007 1008
      td.className = className
      tr.appendChild(td);
      return td
    }

    function nodeIndex(node) {
1009
      let children = node.parentNode.childNodes,
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019
        i = 0;
      for (; i < children.length; i++) {
        if (children[i] == node) {
          return i;
        }
      }
      return -1;
    }

    function toggleCssClass(node, cssClass, toggleState) {
1020 1021
      let index = -1;
      let classes;
1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035
      if (node.className != undefined) {
        classes = node.className.split(' ');
        index = classes.indexOf(cssClass);
      }
      if (index == -1) {
        if (toggleState === false) return;
        node.className += ' ' + cssClass;
        return;
      }
      if (toggleState === true) return;
      classes.splice(index, 1);
      node.className = classes.join(' ');
    }

1036 1037 1038 1039 1040 1041
    function NameComparator(a, b) {
      if (a.name > b.name) return 1;
      if (a.name < b.name) return -1;
      return 0
    }

1042 1043
    function diffSign(value, digits, unit, showDiff) {
      if (showDiff === false || baselineVersion == undefined) {
1044
        if (value === undefined) return '';
1045 1046 1047
        return value.toFixed(digits) + unit;
      }
      return (value >= 0 ? '+' : '') + value.toFixed(digits) + unit + 'Δ';
1048 1049
    }

1050 1051
    function ms(value, showDiff) {
      return diffSign(value, 1, 'ms', showDiff);
1052 1053
    }

1054 1055
    function count(value, showDiff) {
      return diffSign(value, 0, '#', showDiff);
1056 1057
    }

1058 1059
    function percent(value, showDiff) {
      return diffSign(value, 1, '%', showDiff);
1060
    }
1061

1062
  </script>
1063
  <script>
1064
  "use strict"
1065
    // =========================================================================
1066
    // EventHandlers
1067
    function handleBodyLoad() {
1068
      $('uploadInput').focus();
1069 1070 1071 1072 1073
      if (defaultData) {
        handleLoadJSON(defaultData);
      } else if (window.location.protocol !== 'file:') {
        tryLoadDefaultResults();
      }
1074 1075 1076
    }

    function tryLoadDefaultResults() {
1077
     // Try to load a results.json file adjacent to this day.
1078
     let xhr = new XMLHttpRequest();
1079 1080 1081
     // The markers on the following line can be used to replace the url easily
     // with scripts.
     xhr.open('GET', /*results-url-start*/'results.json'/*results-url-end*/, true);
1082
     xhr.onreadystatechange = function(e) {
1083
       if(this.readyState !== XMLHttpRequest.DONE || this.status !== 200) return;
1084 1085 1086
       handleLoadText(this.responseText);
     };
     xhr.send();
1087 1088
    }

1089
    function handleAppendFile() {
1090
      let files = document.getElementById("appendInput").files;
1091 1092 1093
      loadFiles(files, true);
    }

1094
    function handleLoadFile() {
1095
      let files = document.getElementById("uploadInput").files;
1096 1097
      loadFiles(files, false)
    }
1098

1099
    function loadFiles(files, append) {
1100 1101
      let file = files[0];
      let reader = new FileReader();
1102 1103

      reader.onload = function(evt) {
1104
        handleLoadText(this.result, append, file.name);
1105 1106 1107 1108
      }
      reader.readAsText(file);
    }

1109
    function handleLoadText(text, append, fileName) {
1110 1111 1112 1113 1114 1115 1116 1117 1118
      try {
        handleLoadJSON(JSON.parse(text), append, fileName);
      } catch(e) {
        if (!fileName.endsWith('.txt')) {
          alert(`Error parsing "${fileName}"`);
          console.error(e);
        }
        handleLoadTXT(text, append, fileName);
      }
1119 1120
    }

1121
    function getStateFromParams() {
1122 1123
      let query = window.location.search.substr(1);
      let result = {};
1124
      query.split("&").forEach((part) => {
1125 1126
        let item = part.split("=");
        let key = decodeURIComponent(item[0])
1127 1128 1129 1130 1131
        result[key] = decodeURIComponent(item[1]);
      });
      return result;
    }

1132
    function handleLoadJSON(json, append, fileName) {
1133 1134
      let isFirstLoad = pages === undefined;
      json = fixClusterTelemetryResults(json);
1135 1136
      json = fixTraceImportJSON(json);
      json = fixSingleVersionJSON(json, fileName);
1137 1138 1139 1140 1141 1142 1143 1144 1145
      if (append && !isFirstLoad) {
        json = createUniqueVersions(json)
      }
      if (!append || isFirstLoad) {
        pages = new Pages();
        versions = Versions.fromJSON(json);
      } else {
        Versions.fromJSON(json).forEach(e => versions.add(e))
      }
1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162
      displayResultsAfterLoading(isFirstLoad)
    }

    function handleLoadTXT(txt, append, fileName) {
      let isFirstLoad = pages === undefined;
      // Load raw RCS output which contains a single page
      if (!append || isFirstLoad) {
        pages = new Pages();
        versions = new Versions()
      }
      versions.add(Version.fromTXT(fileName, txt))
      displayResultsAfterLoading()

    }

    function displayResultsAfterLoading(isFirstLoad) {
      let state = getStateFromParams();
1163
      initialize()
1164
      if (isFirstLoad && !popHistoryState(state) && selectedPage) {
1165
        showEntry(selectedPage.total);
1166
        return;
1167
      }
1168 1169 1170
      selectedPage = versions.versions[0].pages[0]
      if (selectedPage == undefined) return;
      showPage(selectedPage);
1171 1172 1173 1174 1175
    }

    function fixClusterTelemetryResults(json) {
      // Convert CT results to callstats compatible JSON
      // Input:
1176
      // { VERSION_NAME: { PAGE: { METRIC: { "count": {XX}, "duration": {XX} }.. }}.. }
1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195
      let firstEntry;
      for (let key in json) {
        firstEntry = json[key];
        break;
      }
      // Return the original JSON if it is not a CT result.
      if (firstEntry.pairs === undefined) return json;
      // The results include already the group totals, remove them by filtering.
      let groupNames = new Set(Array.from(Group.groups.values()).map(e => e.name));
      let result = Object.create(null);
      for (let file_name in json) {
        let entries = [];
        let file_data = json[file_name].pairs;
        for (let name in file_data) {
          if(name != "Total" && groupNames.has(name)) continue;
          let entry = file_data[name];
          let count = entry.count;
          let time = entry.time;
          entries.push([name, time, 0, 0, count, 0, 0]);
1196
        } 
1197 1198 1199 1200 1201 1202
        let domain = file_name.split("/").slice(-1)[0];
        result[domain] = entries;
      }
      return {__proto__:null, ClusterTelemetry: result};
    }

1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246
    function fixTraceImportJSON(json) {
      // Fix json file that was created by converting a trace json output
      if (!('telemetry-results' in json)) return json;
      // { telemetry-results: { PAGE:[ { METRIC: [ COUNT TIME ], ... }, ... ]}}
      let version_data = {__proto__:null};
      json = json["telemetry-results"];
      for (let page_name in json) {
        if (page_name == "placeholder") continue;
        let page_data = {
              __proto__:null,
              Total: {
                duration: {average: 0, stddev: 0},
                count: {average:0, stddev: 0}
              }
            };
        let page = json[page_name];
        for (let slice of page ) {
          for (let metric_name in slice) {
            if (metric_name == "Blink_V8") continue;
            // sum up entries
            if (!(metric_name in page_data)) {
              page_data[metric_name] = {
                duration: {average: 0, stddev: 0},
                count: {average:0, stddev: 0}
              }
            }
            let [metric_count, metric_duration] = slice[metric_name]
            let metric = page_data[metric_name];
            const kMicroToMilli = 1/1000;
            metric.duration.average += metric_duration * kMicroToMilli;
            metric.count.average += metric_count;

            if (metric_name.startsWith('Blink_')) continue;
            let total = page_data['Total'];
            total.duration.average += metric_duration * kMicroToMilli;
            total.count.average += metric_count;
          } 
        }
        version_data[page_name] = page_data;
      }
      return version_data;
    }

    function fixSingleVersionJSON(json, name) {
1247 1248
      // Try to detect the single-version case, where we're missing the toplevel
      // version object. The incoming JSON is of the form:
1249
        //   { PAGE: ... , PAGE_2:  }
1250 1251 1252
      // Instead of the default multi-page JSON:
      //    {"Version 1": { "Page 1": ..., ...}, "Version 2": {...}, ...}
      // In this case insert a single "Default" version as top-level entry.
1253 1254
      let firstProperty = (object) => {
        for (let key in object) return object[key];
1255
      };
1256 1257 1258
      let maybePage = firstProperty(json);
      let maybeMetrics = firstProperty(maybePage);
      let tempName = name ? name : new Date().toISOString();
1259
      tempName = window.prompt('Enter a name for the loaded file:', tempName);
1260 1261 1262 1263 1264 1265 1266 1267 1268
      if ('count' in maybeMetrics && 'duration' in maybeMetrics) {
        return {[tempName]: json}
      }
      // Legacy fallback where the metrics are encoded as arrays:
      //  { PAGE: [[metric_name, ...], [...], ]}
      if (Array.isArray(maybeMetrics)) {
        return {[tempName]: json}
      }
      return json
1269 1270
    }

1271
    let appendIndex = 0;
1272
    function createUniqueVersions(json) {
1273
      // Make sure all toplevel entries are unique names and added properly
1274 1275 1276 1277
      appendIndex++;
      let result = {__proto__:null}
      for (let key in json) {
        result[key+"_"+appendIndex] = json[key];
1278
      }
1279
      return result
1280 1281
    }

1282
    function handleToggleGroup(event) {
1283
      let group = event.target.parentNode.parentNode.entry;
1284 1285 1286 1287
      toggleGroup(selectedPage.get(group.name));
    }

    function handleSelectPage(select, event) {
1288
      let option = select.options[select.selectedIndex];
1289
      if (select.id == "select_0") {
1290
        showSelectedEntryInPage(option.page);
1291
      } else {
1292
        let columnIndex = select.id.split('_')[1];
1293 1294 1295 1296 1297
        showPageInColumn(option.page, columnIndex);
      }
    }

    function handleSelectVersion(select, event) {
1298 1299
      let option = select.options[select.selectedIndex];
      let version = option.version;
1300
      if (select.id == "selectVersion_0") {
1301
        let page = version.get(selectedPage.name);
1302
        showSelectedEntryInPage(page);
1303
      } else {
1304 1305 1306
        let columnIndex = select.id.split('_')[1];
        let pageSelect = $('select_' + columnIndex);
        let page = pageSelect.options[pageSelect.selectedIndex].page;
1307 1308 1309 1310 1311 1312 1313
        page = version.get(page.name);
        showPageInColumn(page, columnIndex);
      }
    }

    function handleSelectDetailRow(table, event) {
      if (event.target.tagName != 'TD') return;
1314
      let tr = event.target.parentNode;
1315 1316 1317 1318 1319 1320 1321
      if (tr.tagName != 'TR') return;
      if (tr.entry === undefined) return;
      selectEntry(tr.entry, true);
    }

    function handleSelectRow(table, event, fromDetail) {
      if (event.target.tagName != 'TD') return;
1322
      let tr = event.target.parentNode;
1323 1324 1325 1326 1327 1328
      if (tr.tagName != 'TR') return;
      if (tr.entry === undefined) return;
      selectEntry(tr.entry, false);
    }

    function handleSelectBaseline(select, event) {
1329
      let option = select.options[select.selectedIndex];
1330
      baselineVersion = option.version;
1331 1332
      let showingDiff = baselineVersion !== undefined;
      let body = $('body');
1333 1334
      toggleCssClass(body, 'diff', showingDiff);
      toggleCssClass(body, 'noDiff', !showingDiff);
1335 1336 1337 1338 1339
      showPage(selectedPage);
      if (selectedEntry === undefined) return;
      selectEntry(selectedEntry, true);
    }

1340
    function findEntry(event) {
1341
      let target = event.target;
1342 1343 1344 1345 1346 1347 1348
      while (target.entry === undefined) {
        target = target.parentNode;
        if (!target) return undefined;
      }
      return target.entry;
    }

1349
    function handleUpdatePopover(event) {
1350
      let popover = $('popover');
1351 1352
      popover.style.left = event.pageX + 'px';
      popover.style.top = event.pageY + 'px';
1353
      popover.style.display = 'none';
1354
      popover.style.display = event.shiftKey ? 'block' : 'none';
1355
      let entry = findEntry(event);
1356 1357
      if (entry === undefined) return;
      showPopover(entry);
1358 1359
    }

1360
    function handleToggleVersionOrPageEnable(event) {
1361
      let item = this.item ;
1362 1363
      if (item  === undefined) return;
      item .enabled = this.checked;
1364
      initialize();
1365
      let page = selectedPage;
1366 1367 1368
      if (page === undefined || !page.version.enabled) {
        page = versions.getEnabledPage(page.name);
      }
1369 1370 1371
      if (!page.enabled) {
        page = page.getNextPage();
      }
1372 1373 1374
      showPage(page);
    }

1375
    function handleToggleContentVisibility(event) {
1376
      let content = event.target.contentNode;
1377 1378
      toggleCssClass(content, 'hidden');
    }
1379

1380
    function handleCodeSearch(event) {
1381
      let entry = findEntry(event);
1382
      if (entry === undefined) return;
1383
      let url = "https://cs.chromium.org/search/?sq=package:chromium&type=cs&q=";
1384 1385 1386 1387 1388 1389 1390 1391
      name = entry.name;
      if (name.startsWith("API_")) {
        name = name.substring(4);
      }
      url += encodeURIComponent(name) + "+file:src/v8/src";
      window.open(url,'_blank');
    }
  </script>
1392
  <script>
1393 1394
  "use strict"
    // =========================================================================
1395 1396 1397 1398 1399 1400 1401
    class Versions {
      constructor() {
        this.versions = [];
      }
      add(version) {
        this.versions.push(version)
      }
1402
      getPageVersions(page) {
1403
        let result = [];
1404
        this.versions.forEach((version) => {
1405
          if (!version.enabled) return;
1406
          let versionPage = version.get(page.name);
1407
          if (versionPage  !== undefined) result.push(versionPage);
1408 1409 1410 1411 1412 1413 1414 1415
        });
        return result;
      }
      get length() {
        return this.versions.length
      }
      get(index) {
        return this.versions[index]
1416 1417 1418 1419
      }
      getByName(name) {
        return this.versions.find((each) => each.name == name);
      }
1420 1421 1422 1423
      forEach(f) {
        this.versions.forEach(f);
      }
      sort() {
1424
        this.versions.sort(NameComparator);
1425
      }
1426
      getEnabledPage(name) {
1427 1428
        for (let i = 0; i < this.versions.length; i++) {
          let version = this.versions[i];
1429
          if (!version.enabled) continue;
1430
          let page = version.get(name);
1431
          if (page !== undefined) return page;
1432
        }
1433
      }
1434 1435

      static fromJSON(json) {
1436 1437
        let versions = new Versions();
        for (let version in json) {
1438 1439 1440 1441
          versions.add(Version.fromJSON(version, json[version]));
        }
        versions.sort();
        return versions;
1442 1443 1444 1445 1446 1447
      }
    }

    class Version {
      constructor(name) {
        this.name = name;
1448 1449
        this.enabled = true;
        this.pages = [];
1450 1451 1452 1453 1454
      }
      add(page) {
        this.pages.push(page);
      }
      indexOf(name) {
1455
        for (let i = 0; i < this.pages.length; i++) {
1456 1457 1458 1459
          if (this.pages[i].name == name) return i;
        }
        return -1;
      }
1460 1461 1462 1463
      getNextPage(page) {
        if (this.length == 0) return undefined;
        return this.pages[(this.indexOf(page.name) + 1) % this.length];
      }
1464
      get(name) {
1465
        let index = this.indexOf(name);
1466 1467 1468 1469
        if (0 <= index) return this.pages[index];
        return undefined
      }
      get length() {
1470
        return this.pages.length
1471 1472 1473
      }
      getEntry(entry) {
        if (entry === undefined) return undefined;
1474
        let page = this.get(entry.page.name);
1475 1476 1477 1478
        if (page === undefined) return undefined;
        return page.get(entry.name);
      }
      forEachEntry(fun) {
1479
        this.forEachPage((page) => {
1480 1481 1482
          page.forEach(fun);
        });
      }
1483 1484 1485 1486 1487 1488
      forEachPage(fun) {
        this.pages.forEach((page) => {
          if (!page.enabled) return;
          fun(page);
        })
      }
1489
      allEntries() {
1490
        let map = new Map();
1491 1492 1493 1494 1495 1496 1497
        this.forEachEntry((group, entry) => {
          if (!map.has(entry.name)) map.set(entry.name, entry);
        });
        return Array.from(map.values());
      }
      getTotalValue(name, property) {
        if (name === undefined) name = this.pages[0].total.name;
1498
        let sum = 0;
1499
        this.forEachPage((page) => {
1500
          let entry = page.get(name);
1501 1502 1503 1504 1505 1506 1507 1508
          if (entry !== undefined) sum += entry[property];
        });
        return sum;
      }
      getTotalTime(name, showDiff) {
        return this.getTotalValue(name, showDiff === false ? '_time' : 'time');
      }
      getTotalTimePercent(name, showDiff) {
1509
        if (baselineVersion === undefined || showDiff === false) {
1510 1511 1512
          // Return the overall average percent of the given entry name.
          return this.getTotalValue(name, 'time') /
            this.getTotalTime('Group-Total') * 100;
1513
        }
1514
        // Otherwise return the difference to the sum of the baseline version.
1515 1516
        let baselineValue = baselineVersion.getTotalTime(name, false);
        let total = this.getTotalValue(name, '_time');
1517
        return (total / baselineValue - 1)  * 100;
1518 1519 1520
      }
      getTotalTimeVariance(name, showDiff) {
        // Calculate the overall error for a given entry name
1521
        let sum = 0;
1522
        this.forEachPage((page) => {
1523
          let entry = page.get(name);
1524 1525 1526 1527 1528 1529
          if (entry === undefined) return;
          sum += entry.timeVariance * entry.timeVariance;
        });
        return Math.sqrt(sum);
      }
      getTotalTimeVariancePercent(name, showDiff) {
1530
        return this.getTotalTimeVariance(name, showDiff) /
1531 1532 1533
          this.getTotalTime(name, showDiff) * 100;
      }
      getTotalCount(name, showDiff) {
1534
        return this.getTotalValue(name, showDiff === false ? '_count' : 'count');
1535
      }
1536 1537 1538
      getAverageTimeImpact(name, showDiff) {
        return this.getTotalTime(name, showDiff) / this.pages.length;
      }
1539
      getPagesByPercentImpact(name) {
1540
        let sortedPages =
1541 1542 1543 1544 1545 1546 1547 1548
          this.pages.filter((each) => {
            return each.get(name) !== undefined
          });
        sortedPages.sort((a, b) => {
          return b.get(name).timePercent - a.get(name).timePercent;
        });
        return sortedPages;
      }
1549
      sort() {
1550
        this.pages.sort(NameComparator)
1551
      }
1552 1553

      static fromJSON(name, data) {
1554 1555
        let version = new Version(name);
        for (let pageName in data) {
1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566
          version.add(PageVersion.fromJSON(version, pageName, data[pageName]));
        }
        version.sort();
        return version;
      }

      static fromTXT(name, txt) {
        let version = new Version(name);
        let pageName = "RAW DATA";
        version.add(PageVersion.fromTXT(version, pageName, txt));
        return version;
1567 1568
      }
    }
1569

1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580
    class Pages extends Map {
      get(name) {
        if (name.indexOf('www.') == 0) {
          name = name.substring(4);
        }
        if (!this.has(name)) {
          this.set(name, new Page(name));
        }
        return super.get(name);
      }
    }
1581 1582

    class Page {
1583
      constructor(name) {
1584
        this.name = name;
1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596
        this.enabled = true;
        this.versions = [];
      }
      add(page) {
        this.versions.push(page);
      }
    }

    class PageVersion {
      constructor(version, page) {
        this.page = page;
        this.page.add(this);
1597
        this.total = Group.groups.get('total').entry();
1598
        this.total.isTotal = true;
1599
        this.unclassified = new UnclassifiedEntry(this)
1600 1601
        this.groups = [
          this.total,
1602
          Group.groups.get('ic').entry(),
1603
          Group.groups.get('optimize-background').entry(),
1604
          Group.groups.get('optimize').entry(),
1605
          Group.groups.get('compile-background').entry(),
1606
          Group.groups.get('compile').entry(),
1607
          Group.groups.get('parse-background').entry(),
1608
          Group.groups.get('parse').entry(),
1609
          Group.groups.get('blink').entry(),
1610 1611 1612 1613 1614
          Group.groups.get('callback').entry(),
          Group.groups.get('api').entry(),
          Group.groups.get('gc').entry(),
          Group.groups.get('javascript').entry(),
          Group.groups.get('runtime').entry(),
1615 1616 1617 1618 1619 1620 1621 1622 1623
          this.unclassified
        ];
        this.entryDict = new Map();
        this.groups.forEach((entry) => {
          entry.page = this;
          this.entryDict.set(entry.name, entry);
        });
        this.version = version;
      }
1624 1625 1626 1627 1628 1629
      toString() {
        return this.version.name + ": " + this.name;
      }
      urlParams() {
        return { version: this.version.name, page: this.name};
      }
1630
      add(entry) {
1631 1632
        // Ignore accidentally added Group entries.
        if (entry.name.startsWith(GroupedEntry.prefix)) return;
1633 1634
        entry.page = this;
        this.entryDict.set(entry.name, entry);
1635 1636 1637 1638
        for (let group of this.groups) { 
          if (group.add(entry)) return;
        }
        console.error("Sould not get here", entry);
1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649
      }
      get(name) {
        return this.entryDict.get(name)
      }
      getEntry(entry) {
        if (entry === undefined) return undefined;
        return this.get(entry.name);
      }
      get length() {
        return this.versions.length
      }
1650 1651
      get name() { return this.page.name }
      get enabled() { return this.page.enabled }
1652
      forEachSorted(referencePage, func) {
1653 1654
        // Iterate over all the entries in the order they appear on the
        // reference page.
1655
        referencePage.forEach((parent, referenceEntry) => {
1656
          let entry;
1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680
          if (parent) parent = this.entryDict.get(parent.name);
          if (referenceEntry) entry = this.entryDict.get(referenceEntry.name);
          func(parent, entry, referenceEntry);
        });
      }
      forEach(fun) {
        this.forEachGroup((group) => {
          fun(undefined, group);
          group.forEach((entry) => {
            fun(group, entry)
          });
        });
      }
      forEachGroup(fun) {
        this.groups.forEach(fun)
      }
      sort() {
        this.groups.sort((a, b) => {
          return b.time - a.time;
        });
        this.groups.forEach((group) => {
          group.sort()
        });
      }
1681
      distanceFromTotalPercent() {
1682
        let sum = 0;
1683 1684
        this.groups.forEach(group => {
          if (group == this.total) return;
1685
          let value = group.getTimePercentImpact() -
1686 1687 1688 1689
              this.getEntry(group).timePercent;
          sum += value * value;
        });
        return sum;
1690
      }
1691 1692 1693
      getNextPage() {
        return this.version.getNextPage(this);
      }
1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708

      static fromJSON(version, name, data) {
        let page = new PageVersion(version, pages.get(name));
        // Distinguish between the legacy format which just uses Arrays,
        // or the new object style.
        if (Array.isArray(data)) {
          for (let i = 0; i < data.length; i++) {
            page.add(Entry.fromLegacyJSON(i, data[data.length - i - 1]));
          }
        } else {
          let position = 0;
          for (let metric_name in data) {
            page.add(Entry.fromJSON(position, metric_name, data[metric_name]));
            position++;
          }
1709
        }
1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723
        page.sort();
        return page
      }

      static fromTXT(version, name, txt) {
        let pageVersion = new PageVersion(version, pages.get(name));
        let lines = txt.split('\n');
        let split = / +/g
        // Skip the first two lines (HEADER and SEPARATOR)
        for (let i = 2; i < lines.length; i++) {
          let line = lines[i].trim().split(split)
          if (line.length != 5) continue;
          let position = i-2;
          pageVersion.add(Entry.fromTXT(position, line));
1724
        }
1725
        return pageVersion;
1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743
      }
    }


    class Entry {
      constructor(position, name, time, timeVariance, timeVariancePercent,
        count,
        countVariance, countVariancePercent) {
        this.position = position;
        this.name = name;
        this._time = time;
        this._timeVariance = timeVariance;
        this._timeVariancePercent = timeVariancePercent;
        this._count = count;
        this.countVariance = countVariance;
        this.countVariancePercent = countVariancePercent;
        this.page = undefined;
        this.parent = undefined;
1744
        this.isTotal = false;
1745
      }
1746
      urlParams() {
1747
        let params = this.page.urlParams();
1748 1749 1750
        params.entry = this.name;
        return params;
      }
1751 1752
      getCompareWithBaseline(value, property) {
        if (baselineVersion == undefined) return value;
1753
        let baselineEntry = baselineVersion.getEntry(this);
1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767
        if (!baselineEntry) return value;
        if (baselineVersion === this.page.version) return value;
        return value - baselineEntry[property];
      }
      cssClass() {
        return ''
      }
      get time() {
        return this.getCompareWithBaseline(this._time, '_time');
      }
      get count() {
        return this.getCompareWithBaseline(this._count, '_count');
      }
      get timePercent() {
1768
        let value = this._time / this.page.total._time * 100;
1769
        if (baselineVersion == undefined) return value;
1770
        let baselineEntry = baselineVersion.getEntry(this);
1771
        if (!baselineEntry) return value;
1772 1773 1774
        if (baselineVersion === this.page.version) return value;
        return (this._time - baselineEntry._time) / this.page.total._time *
          100;
1775
      }
1776
      get timePercentPerEntry() {
1777
        let value = this._time / this.page.total._time * 100;
1778
        if (baselineVersion == undefined) return value;
1779
        let baselineEntry = baselineVersion.getEntry(this);
1780 1781 1782 1783
        if (!baselineEntry) return value;
        if (baselineVersion === this.page.version) return value;
        return (this._time / baselineEntry._time - 1) * 100;
      }
1784 1785 1786 1787 1788 1789 1790 1791
      get timePercentVariancePercent() {
        // Get the absolute values for the percentages
        return this.timeVariance / this.page.total._time * 100;
      }
      getTimeImpact(showDiff) {
        return this.page.version.getTotalTime(this.name, showDiff);
      }
      getTimeImpactVariancePercent(showDiff) {
1792
        return this.page.version.getTotalTimeVariancePercent(this.name, showDiff);
1793 1794 1795 1796 1797 1798 1799
      }
      getTimePercentImpact(showDiff) {
        return this.page.version.getTotalTimePercent(this.name, showDiff);
      }
      getCountImpact(showDiff) {
        return this.page.version.getTotalCount(this.name, showDiff);
      }
1800 1801 1802
      getAverageTimeImpact(showDiff) {
        return this.page.version.getAverageTimeImpact(this.name, showDiff);
      }
1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814
      getPagesByPercentImpact() {
        return this.page.version.getPagesByPercentImpact(this.name);
      }
      get isGroup() {
        return false
      }
      get timeVariance() {
        return this._timeVariance
      }
      get timeVariancePercent() {
        return this._timeVariancePercent
      }
1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835

      static fromLegacyJSON(position, data) {
        return new Entry(position, ...data);
      }

      static fromJSON(position, name, data) {
        let time = data.duration;
        let count = data.count;
        return new Entry(position, name, time.average, time.stddev, 0,
                        count.average, count.stddev, 0);
      }

      static fromTXT(position, splitLine) {
        let [name, time, timePercent, count, countPercent] = splitLine;
        time = time.split('ms')
        let timeDeviation = 0, countDeviation = 0;
        let timeDeviationPercent = 0, countDeviationPercent = 0
        return new Entry(position, name,
          Number.parseFloat(time), timeDeviation, timeDeviationPercent,
          Number.parseInt(count), countDeviation, countDeviationPercent)
      }
1836
    }
1837

1838
    class Group {
1839
      constructor(name, regexp, color, enabled=true, addsToTotal=true) {
1840
        this.name = name;
1841
        this.regexp = regexp;
1842
        this.color = color;
1843 1844
        this.enabled = enabled;
        this.addsToTotal = addsToTotal; 
1845 1846 1847 1848 1849 1850
      }
      entry() { return new GroupedEntry(this) };
    }
    Group.groups = new Map();
    Group.add = function(name, group) {
      this.groups.set(name, group);
1851
      return group;
1852
    }
1853
    Group.add('total', new Group('Total', /.*Total.*/, '#BBB', true, false));
1854
    Group.add('ic', new Group('IC', /.*IC_.*/, "#3366CC"));
1855
    Group.add('optimize-background', new Group('Optimize-Background',
1856
        /(.*OptimizeBackground.*)/, "#702000"));
1857 1858
    Group.add('optimize', new Group('Optimize',
        /StackGuard|.*Optimize.*|.*Deoptimize.*|Recompile.*/, "#DC3912"));
1859
    Group.add('compile-background', new Group('Compile-Background',
1860
        /(.*CompileBackground.*)/, "#b08000"));
1861 1862
    Group.add('compile', new Group('Compile',
        /(^Compile.*)|(.*_Compile.*)/, "#FFAA00"));
1863
    Group.add('parse-background',
1864
        new Group('Parse-Background', /.*ParseBackground.*/, "#c05000"));
1865
    Group.add('parse', new Group('Parse', /.*Parse.*/, "#FF6600"));
1866
    Group.add('callback', new Group('Blink C++', /.*Callback*/, "#109618"));
1867
    Group.add('api', new Group('API', /.*API.*/, "#990099"));
1868
    Group.add('gc-custom', new Group('GC-Custom', /GC_Custom_.*/, "#0099C6"));
1869 1870
    Group.add('gc-background',
        new Group('GC-Background', /.*GC.*BACKGROUND.*/, "#00597c"));
1871
    Group.add('gc', new Group('GC', /GC_.*|AllocateInTargetSpace/, "#00799c"));
1872
    Group.add('javascript', new Group('JavaScript', /JS_Execution/, "#DD4477"));
1873
    Group.add('runtime', new Group('V8 C++', /.*/, "#88BB00"));
1874 1875
    Group.add('blink', new Group('Blink RCS', /.*Blink_.*/, "#006600", false, false));
    Group.add('unclassified', new Group('Unclassified', /.*/, "#000", false));
1876 1877 1878

    class GroupedEntry extends Entry {
      constructor(group) {
1879
        super(0, GroupedEntry.prefix + group.name, 0, 0, 0, 0, 0, 0);
1880
        this.group = group;
1881
        this.entries = [];
1882
        this.missingEntries = null;
1883
        this.addsToTotal = group.addsToTotal;
1884
      }
1885 1886 1887
      get regexp() { return this.group.regexp }
      get color() { return this.group.color }
      get enabled() { return this.group.enabled }
1888
      add(entry) {
1889
        if (!this.regexp.test(entry.name)) return false;
1890 1891 1892 1893 1894 1895 1896
        this._time += entry.time;
        this._count += entry.count;
        // TODO: sum up variance
        this.entries.push(entry);
        entry.parent = this;
        return true;
      }
1897
      _initializeMissingEntries() {
1898
        let dummyEntryNames = new Set();
1899
        versions.forEach((version) => {
1900
          let groupEntry = version.getEntry(this);
1901
          if (groupEntry != this) {
1902
            for (let entry of groupEntry.entries) {
1903 1904 1905 1906 1907
              if (this.page.get(entry.name) == undefined) {
                dummyEntryNames.add(entry.name);
              }
            }
          }
1908
        });
1909
        this.missingEntries  = [];
1910 1911
        for (let name of dummyEntryNames) {
          let tmpEntry = new Entry(0, name, 0, 0, 0, 0, 0, 0);
1912
          tmpEntry.page = this.page;
1913
          this.missingEntries.push(tmpEntry);
1914
        };
1915
      }
1916

1917 1918
      forEach(fun) {
        // Show also all entries which are in at least one version.
1919
        // Concatenate our real entries.
1920 1921 1922
        if (this.missingEntries == null) {
          this._initializeMissingEntries();
        }
1923
        let tmpEntries = this.missingEntries.concat(this.entries);
1924 1925

        // The compared entries are sorted by absolute impact.
1926
        tmpEntries.sort((a, b) => {
1927
          return b.time - a.time
1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943
        });
        tmpEntries.forEach(fun);
      }
      sort() {
        this.entries.sort((a, b) => {
          return b.time - a.time;
        });
      }
      cssClass() {
        if (this.page.total == this) return 'total';
        return '';
      }
      get isGroup() {
        return true
      }
      getVarianceForProperty(property) {
1944
        let sum = 0;
1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958
        this.entries.forEach((entry) => {
          sum += entry[property + 'Variance'] * entry[property +
            'Variance'];
        });
        return Math.sqrt(sum);
      }
      get timeVariancePercent() {
        if (this._time == 0) return 0;
        return this.getVarianceForProperty('time')  / this._time * 100
      }
      get timeVariance() {
        return this.getVarianceForProperty('time')
      }
    }
1959
    GroupedEntry.prefix = 'Group-';
1960 1961

    class UnclassifiedEntry extends GroupedEntry {
1962 1963
      constructor(page) {
        super(Group.groups.get('unclassified'));
1964 1965 1966 1967 1968
        this.page = page;
        this._time = undefined;
        this._count = undefined;
      }
      add(entry) {
1969
        console.log("Adding unclassified:", entry);
1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984
        this.entries.push(entry);
        entry.parent = this;
        return true;
      }
      forEachPageGroup(fun) {
        this.page.forEachGroup((group) => {
          if (group == this) return;
          if (group == this.page.total) return;
          fun(group);
        });
      }
      get time() {
        if (this._time === undefined) {
          this._time = this.page.total._time;
          this.forEachPageGroup((group) => {
1985
            if (group.addsToTotal) this._time -= group._time;
1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002
          });
        }
        return this.getCompareWithBaseline(this._time, '_time');
      }
      get count() {
        if (this._count === undefined) {
          this._count = this.page.total._count;
          this.forEachPageGroup((group) => {
            this._count -= group._count;
          });
        }
        return this.getCompareWithBaseline(this._count, '_count');
      }
    }
  </script>
</head>

2003
<body id="body" onmousemove="handleUpdatePopover(event)" onload="handleBodyLoad()" class="noDiff">
2004 2005 2006 2007 2008 2009 2010
  <h1>Runtime Stats Komparator</h1>

  <div id="results">
    <div class="inline">
      <h2>Data</h2>
      <form name="fileForm">
        <p>
2011
          <label for="uploadInput">Load File:</label>
2012
          <input id="uploadInput" type="file" name="files" onchange="handleLoadFile();" accept=".json,.txt">
2013
        </p>
2014 2015
        <p>
          <label for="appendInput">Append File:</label>
2016
          <input id="appendInput" type="file" name="files" onchange="handleAppendFile();" accept=".json,.txt">
2017
        </p>
2018 2019
      </form>
    </div>
2020

2021 2022
    <div class="inline hidden">
      <h2>Result</h2>
2023
      <div class="compareSelector inline">
2024 2025 2026 2027
        Compare against:&nbsp;<select id="baseline" onchange="handleSelectBaseline(this, event)"></select><br/>
        <span style="color: #060">Green</span> the selected version above performs
        better on this measurement.
      </div>
2028
    </div>
2029

2030
    <div id="versionSelector" class="inline toggleContentVisibility">
2031
      <h2>Versions</h2>
2032
      <div class="content hidden">
2033 2034
        <ul></ul>
      </div>
2035
    </div>
2036

2037
    <div id="pageSelector" class="inline toggleContentVisibility">
2038 2039 2040 2041 2042 2043 2044 2045
      <h2>Pages</h2>
      <div class="content hidden">
        <ul></ul>
      </div>
    </div>

    <div id="groupSelector" class="inline toggleContentVisibility">
      <h2>Groups</h2>
2046 2047 2048 2049 2050
      <div class="content hidden">
        <ul></ul>
      </div>
    </div>

2051 2052 2053 2054
    <div id="view">
    </div>

    <div id="detailView" class="hidden">
2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070
      <div class="versionDetail inline toggleContentVisibility">
        <h3><span></span></h3>
        <div class="content">
          <table class="versionDetailTable" onclick="handleSelectDetailRow(this, event);">
            <thead>
              <tr>
                <th class="version">Version&nbsp;</th>
                <th class="position">Pos.&nbsp;</th>
                <th class="value time">Time▴&nbsp;</th>
                <th class="value time">Percent&nbsp;</th>
                <th class="value count">Count&nbsp;</th>
              </tr>
            </thead>
            <tbody></tbody>
          </table>
        </div>
2071
      </div>
2072
      <div class="pageDetail inline toggleContentVisibility">
2073
        <h3>Page Comparison for <span></span></h3>
2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096
        <div class="content">
          <table class="pageDetailTable" onclick="handleSelectDetailRow(this, event);">
            <thead>
              <tr>
                <th class="page">Page&nbsp;</th>
                <th class="value time">Time&nbsp;</th>
                <th class="value time">Percent▾&nbsp;</th>
                <th class="value time hideNoDiff">%/Entry&nbsp;</th>
                <th class="value count">Count&nbsp;</th>
              </tr>
            </thead>
            <tfoot>
              <tr>
                <td class="page">Total:</td>
                <td class="value time"></td>
                <td class="value time"></td>
                <td class="value time hideNoDiff"></td>
                <td class="value count"></td>
              </tr>
            </tfoot>
            <tbody></tbody>
          </table>
        </div>
2097
      </div>
2098
      <div class="impactView inline toggleContentVisibility">
2099
        <h3>Impact list for <span></span></h3>
2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112
        <div class="content">
          <table class="pageDetailTable" onclick="handleSelectDetailRow(this, event);">
            <thead>
              <tr>
                <th class="page">Name&nbsp;</th>
                <th class="value time">Time&nbsp;</th>
                <th class="value time">Percent▾&nbsp;</th>
                <th class="">Top Pages</th>
              </tr>
            </thead>
            <tbody></tbody>
          </table>
        </div>
2113 2114
      </div>
    </div>
2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125
    <div id="pageVersionGraph" class="graph hidden toggleContentVisibility">
      <h3><span></span></h3>
      <div class="content"></div>
    </div>
    <div id="pageGraph" class="graph hidden toggleContentVisibility">
      <h3><span></span></h3>
      <div class="content"></div>
    </div>
    <div id="versionGraph" class="graph hidden toggleContentVisibility">
      <h3><span></span></h3>
      <div class="content"></div>
2126
    </div>
2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150

    <div id="column" class="column">
      <div class="header">
        <select class="version" onchange="handleSelectVersion(this, event);"></select>
        <select class="pageVersion" onchange="handleSelectPage(this, event);"></select>
      </div>
      <table class="list" onclick="handleSelectRow(this, event);">
        <thead>
          <tr>
            <th class="position">Pos.&nbsp;</th>
            <th class="name">Name&nbsp;</th>
            <th class="value time">Time&nbsp;</th>
            <th class="value time">Percent&nbsp;</th>
            <th class="value count">Count&nbsp;</th>
          </tr>
        </thead>
        <tbody></tbody>
      </table>
    </div>
  </div>

  <div class="inline">
    <h2>Usage</h2>
    <ol>
2151
      <li>Build chrome.</li>
2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172
    </ol>
    <h3>Telemetry benchmark</h3>
    <ol>
      <li>Run <code>v8.browsing</code> benchmarks:
        <pre>$CHROMIUM_DIR/tools/perf/run_benchmark run v8.browsing_desktop \
          --browser=exact --browser-executable=$CHROMIUM_DIR/out/release/chrome \
          --story-filter='.*2020 ' \
          --also-run-disabled-tests
        </pre>
      </li>
      <li>Install <a href="https://stedolan.github.io/jq/">jq</a>.</li>
      <li>Convert the telemetry JSON files to callstats JSON file:
        <pre>
          $V8_DIR/tools/callstats-from-telemetry.sh $CHROMIUM_DIR/tools/perf/artifacts/run_XXXX
        </pre>
      </li>
      <li>Load the generated <code>out.json</code></li>
    </ol>
    <h3>Raw approach</h3>
    <ol>
      <li>Install scipy, e.g. <code>sudo aptitude install python-scipy</code>
2173 2174 2175
      <li>Check out a known working version of webpagereply:
        <pre>git -C $CHROME_DIR/third_party/webpagereplay checkout 7dbd94752d1cde5536ffc623a9e10a51721eff1d</pre>
      </li>
2176 2177
      <li>Run <code>callstats.py</code> with a web-page-replay archive:
        <pre>$V8_DIR/tools/callstats.py run \
2178
        --replay-bin=$CHROME_SRC/third_party/webpagereplay/replay.py \
2179
        --replay-wpr=$INPUT_DIR/top25.wpr \
2180 2181
        --js-flags="" \
        --with-chrome=$CHROME_SRC/out/Release/chrome \
2182
        --sites-file=$INPUT_DIR/top25.json</pre>
2183
      </li>
2184
      <li>Move results file to a subdirectory: <code>mkdir $VERSION_DIR; mv *.txt $VERSION_DIR</code></li>
2185
      <li>Repeat from step 1 with a different configuration (e.g. <code>--js-flags="--nolazy"</code>).</li>
2186
      <li>Create the final results file: <code>./callstats.py json $VERSION_DIR1 $VERSION_DIR2 > result.json</code></li>
2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215
      <li>Use <code>results.json</code> on this site.</code>
    </ol>
  </div>

  <div id="popover">
    <div class="popoverArrow"></div>
    <table>
      <tr>
        <td class="name" colspan="6"></td>
      </tr>
      <tr>
        <td>Page:</td>
        <td class="page name" colspan="6"></td>
      </tr>
      <tr>
        <td>Version:</td>
        <td class="version name" colspan="3"></td>
        <td class="compare version name" colspan="3"></td>
      </tr>
      <tr>
        <td>Time:</td>
        <td class="time"></td><td>±</td><td class="timeVariance"></td>
        <td class="compare time"></td><td class="compare"> ± </td><td class="compare timeVariance"></td>
      </tr>
      <tr>
        <td>Percent:</td>
        <td class="percent"></td><td>±</td><td class="percentVariance"></td>
        <td class="compare percent"></td><td class="compare"> ± </td><td class="compare percentVariance"></td>
      </tr>
2216 2217 2218 2219 2220
      <tr>
        <td>Percent per Entry:</td>
        <td class="percentPerEntry"></td><td colspan=2></td>
        <td class="compare percentPerEntry"></td><td colspan=2></td>
      </tr>
2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234
      <tr>
        <td>Count:</td>
        <td class="count"></td><td>±</td><td class="countVariance"></td>
        <td class="compare count"></td><td class="compare"> ± </td><td class="compare countVariance"></td>
      </tr>
      <tr>
        <td>Overall Impact:</td>
        <td class="timeImpact"></td><td>±</td><td class="timePercentImpact"></td>
        <td class="compare timeImpact"></td><td class="compare"> ± </td><td class="compare timePercentImpact"></td>
      </tr>
    </table>
  </div>
</body>
</html>