2018-01-15 15:24:18 +00:00
|
|
|
// Copyright 2018 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.
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const details_selection_template =
|
|
|
|
document.currentScript.ownerDocument.querySelector(
|
|
|
|
'#details-selection-template');
|
|
|
|
|
|
|
|
class DetailsSelection extends HTMLElement {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
const shadowRoot = this.attachShadow({mode: 'open'});
|
|
|
|
shadowRoot.appendChild(details_selection_template.content.cloneNode(true));
|
|
|
|
this.isolateSelect.addEventListener(
|
|
|
|
'change', e => this.handleIsolateChange(e));
|
|
|
|
this.datasetSelect.addEventListener(
|
|
|
|
'change', e => this.notifySelectionChanged(e));
|
2018-01-17 15:37:29 +00:00
|
|
|
this.gcSelect.addEventListener(
|
|
|
|
'change', e => this.notifySelectionChanged(e));
|
2018-01-26 16:30:08 +00:00
|
|
|
this.$('#csv-export-btn')
|
2018-01-17 15:37:29 +00:00
|
|
|
.addEventListener('click', e => this.exportCurrentSelection(e));
|
2018-01-15 17:58:02 +00:00
|
|
|
this.$('#merge-categories')
|
|
|
|
.addEventListener('change', e => this.notifySelectionChanged(e));
|
2018-01-26 16:30:08 +00:00
|
|
|
this.$('#category-filter-btn')
|
|
|
|
.addEventListener('click', e => this.filterCurrentSeclection(e));
|
2018-01-15 15:24:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
connectedCallback() {
|
|
|
|
for (let category of CATEGORIES.keys()) {
|
|
|
|
this.$('#categories').appendChild(this.buildCategory(category));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
set data(value) {
|
|
|
|
this._data = value;
|
|
|
|
this.dataChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
get data() {
|
|
|
|
return this._data;
|
|
|
|
}
|
|
|
|
|
2018-01-22 15:50:48 +00:00
|
|
|
get selectedData() {
|
|
|
|
console.assert(this.data, 'invalid data');
|
|
|
|
console.assert(this.selection, 'invalid selection');
|
|
|
|
return this.data[this.selection.isolate]
|
|
|
|
.gcs[this.selection.gc][this.selection.data_set];
|
|
|
|
}
|
|
|
|
|
2018-01-15 15:24:18 +00:00
|
|
|
buildCategory(name) {
|
|
|
|
const div = document.createElement('div');
|
|
|
|
div.id = name;
|
|
|
|
div.classList.add('box');
|
2018-01-22 15:50:48 +00:00
|
|
|
const ul = document.createElement('ul');
|
|
|
|
div.appendChild(ul);
|
|
|
|
const name_li = document.createElement('li');
|
|
|
|
ul.appendChild(name_li);
|
|
|
|
name_li.innerHTML = CATEGORY_NAMES.get(name);
|
|
|
|
const percent_li = document.createElement('li');
|
|
|
|
ul.appendChild(percent_li);
|
2018-01-23 15:25:24 +00:00
|
|
|
percent_li.innerHTML = '0%';
|
2018-01-22 15:50:48 +00:00
|
|
|
percent_li.id = name + 'PercentContent';
|
|
|
|
const all_li = document.createElement('li');
|
|
|
|
ul.appendChild(all_li);
|
2018-01-15 15:24:18 +00:00
|
|
|
const all_button = document.createElement('button');
|
2018-01-22 15:50:48 +00:00
|
|
|
all_li.appendChild(all_button);
|
2018-01-15 15:24:18 +00:00
|
|
|
all_button.innerHTML = 'All';
|
|
|
|
all_button.addEventListener('click', e => this.selectCategory(name));
|
2018-01-22 15:50:48 +00:00
|
|
|
const none_li = document.createElement('li');
|
|
|
|
ul.appendChild(none_li);
|
2018-01-15 15:24:18 +00:00
|
|
|
const none_button = document.createElement('button');
|
2018-01-22 15:50:48 +00:00
|
|
|
none_li.appendChild(none_button);
|
2018-01-15 15:24:18 +00:00
|
|
|
none_button.innerHTML = 'None';
|
|
|
|
none_button.addEventListener('click', e => this.unselectCategory(name));
|
|
|
|
const innerDiv = document.createElement('div');
|
|
|
|
div.appendChild(innerDiv);
|
|
|
|
innerDiv.id = name + 'Content';
|
|
|
|
return div;
|
|
|
|
}
|
|
|
|
|
|
|
|
$(id) {
|
|
|
|
return this.shadowRoot.querySelector(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
get datasetSelect() {
|
|
|
|
return this.$('#dataset-select');
|
|
|
|
}
|
|
|
|
|
|
|
|
get isolateSelect() {
|
|
|
|
return this.$('#isolate-select');
|
|
|
|
}
|
|
|
|
|
2018-01-17 15:37:29 +00:00
|
|
|
get gcSelect() {
|
|
|
|
return this.$('#gc-select');
|
|
|
|
}
|
|
|
|
|
2018-01-15 15:24:18 +00:00
|
|
|
dataChanged() {
|
2018-01-24 09:02:55 +00:00
|
|
|
this.selection = {categories: {}};
|
|
|
|
this.resetUI(true);
|
2018-02-13 14:03:38 +00:00
|
|
|
this.populateIsolateSelect();
|
2018-01-15 15:24:18 +00:00
|
|
|
this.handleIsolateChange();
|
2018-02-14 08:26:42 +00:00
|
|
|
this.$('#dataSelectionSection').style.display = 'block';
|
2018-01-15 15:24:18 +00:00
|
|
|
}
|
|
|
|
|
2018-02-13 14:03:38 +00:00
|
|
|
populateIsolateSelect() {
|
|
|
|
let entries = Object.entries(this.data);
|
|
|
|
// Sorty by peak heap memory consumption.
|
|
|
|
entries.sort((a, b) => b[1].peakMemory - a[1].peakMemory);
|
|
|
|
this.populateSelect(
|
|
|
|
'#isolate-select', entries, (key, isolate) => isolate.getLabel());
|
|
|
|
}
|
|
|
|
|
2018-01-24 09:02:55 +00:00
|
|
|
resetUI(resetIsolateSelect) {
|
|
|
|
if (resetIsolateSelect) removeAllChildren(this.isolateSelect);
|
|
|
|
|
2018-01-15 15:24:18 +00:00
|
|
|
removeAllChildren(this.datasetSelect);
|
2018-01-17 15:37:29 +00:00
|
|
|
removeAllChildren(this.gcSelect);
|
2018-01-15 15:24:18 +00:00
|
|
|
this.clearCategories();
|
2018-01-26 16:30:08 +00:00
|
|
|
this.$('#csv-export-btn').disabled = 'disabled';
|
|
|
|
this.$('#category-filter-btn').disabled = 'disabled';
|
|
|
|
this.$('#category-filter').disabled = 'disabled';
|
2018-01-15 15:24:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleIsolateChange(e) {
|
|
|
|
this.selection.isolate = this.isolateSelect.value;
|
2018-01-15 20:27:40 +00:00
|
|
|
if (this.selection.isolate.length === 0) {
|
|
|
|
this.selection.isolate = null;
|
|
|
|
return;
|
|
|
|
}
|
2018-01-24 09:02:55 +00:00
|
|
|
this.resetUI(false);
|
2018-01-15 15:24:18 +00:00
|
|
|
this.populateSelect(
|
2018-01-17 15:37:29 +00:00
|
|
|
'#dataset-select',
|
2018-02-13 14:03:38 +00:00
|
|
|
this.data[this.selection.isolate].data_sets.entries(), null, 'live');
|
2018-01-17 15:37:29 +00:00
|
|
|
this.populateSelect(
|
|
|
|
'#gc-select',
|
|
|
|
Object.keys(this.data[this.selection.isolate].gcs)
|
2018-02-13 14:03:38 +00:00
|
|
|
.map(v => [v, this.data[this.selection.isolate].gcs[v].time]),
|
|
|
|
time => time + 'ms');
|
2018-01-15 15:24:18 +00:00
|
|
|
this.populateCategories();
|
|
|
|
this.notifySelectionChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
notifySelectionChanged(e) {
|
|
|
|
if (!this.selection.isolate) return;
|
2018-01-15 17:58:02 +00:00
|
|
|
|
|
|
|
this.selection.categories = {};
|
2018-01-15 15:24:18 +00:00
|
|
|
for (let category of CATEGORIES.keys()) {
|
2018-01-15 17:58:02 +00:00
|
|
|
const selected = this.selectedInCategory(category);
|
|
|
|
if (selected.length > 0) this.selection.categories[category] = selected;
|
2018-01-15 15:24:18 +00:00
|
|
|
}
|
|
|
|
this.selection.category_names = CATEGORY_NAMES;
|
|
|
|
this.selection.data_set = this.datasetSelect.value;
|
2018-01-15 17:58:02 +00:00
|
|
|
this.selection.merge_categories = this.$('#merge-categories').checked;
|
2018-01-17 15:37:29 +00:00
|
|
|
this.selection.gc = this.gcSelect.value;
|
2018-01-26 16:30:08 +00:00
|
|
|
this.$('#csv-export-btn').disabled = false;
|
|
|
|
this.$('#category-filter-btn').disabled = false;
|
|
|
|
this.$('#category-filter').disabled = false;
|
2018-01-23 15:25:24 +00:00
|
|
|
this.updatePercentagesInCategory();
|
2018-01-15 15:24:18 +00:00
|
|
|
this.dispatchEvent(new CustomEvent(
|
|
|
|
'change', {bubbles: true, composed: true, detail: this.selection}));
|
2018-01-23 15:25:24 +00:00
|
|
|
}
|
2018-01-22 15:50:48 +00:00
|
|
|
|
2018-01-26 16:30:08 +00:00
|
|
|
filterCurrentSeclection(e) {
|
|
|
|
const filter_value = this.$('#category-filter').value * KB;
|
|
|
|
if (filter_value === 0) return;
|
|
|
|
|
|
|
|
this.selection.category_names.forEach((_, category) => {
|
|
|
|
for (let checkbox of this.shadowRoot.querySelectorAll(
|
|
|
|
'input[name=' + category + 'Checkbox]')) {
|
|
|
|
checkbox.checked =
|
|
|
|
this.selectedData.instance_type_data[checkbox.instance_type]
|
|
|
|
.overall > filter_value;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.notifySelectionChanged();
|
|
|
|
}
|
|
|
|
|
2018-01-23 15:25:24 +00:00
|
|
|
updatePercentagesInCategory() {
|
2018-01-22 15:50:48 +00:00
|
|
|
const overalls = {};
|
|
|
|
let overall = 0;
|
2018-01-23 15:25:24 +00:00
|
|
|
// Reset all categories.
|
|
|
|
this.selection.category_names.forEach((_, category) => {
|
|
|
|
this.$(`#${category}PercentContent`).innerHTML = '0%';
|
|
|
|
});
|
|
|
|
// Only update categories that have selections.
|
|
|
|
Object.entries(this.selection.categories).forEach(([category, value]) => {
|
|
|
|
overalls[category] =
|
2018-01-22 15:50:48 +00:00
|
|
|
Object.values(value).reduce(
|
|
|
|
(accu, current) =>
|
|
|
|
accu + this.selectedData.instance_type_data[current].overall,
|
|
|
|
0) /
|
|
|
|
KB;
|
2018-01-23 15:25:24 +00:00
|
|
|
overall += overalls[category];
|
2018-01-22 15:50:48 +00:00
|
|
|
});
|
2018-01-23 15:25:24 +00:00
|
|
|
Object.entries(overalls).forEach(([category, category_overall]) => {
|
|
|
|
this.$(`#${category}PercentContent`).innerHTML =
|
|
|
|
`${(category_overall / overall * 100).toFixed(1)}%`;
|
2018-01-22 15:50:48 +00:00
|
|
|
});
|
2018-01-15 15:24:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
selectedInCategory(category) {
|
|
|
|
const selected = this.shadowRoot.querySelectorAll(
|
|
|
|
'input[name=' + category + 'Checkbox]:checked');
|
|
|
|
var tmp = [];
|
|
|
|
for (var val of selected.values()) tmp.push(val.value);
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
categoryForType(instance_type) {
|
|
|
|
for (let [key, value] of CATEGORIES.entries()) {
|
|
|
|
if (value.has(instance_type)) return key;
|
|
|
|
}
|
|
|
|
return 'unclassified';
|
|
|
|
}
|
|
|
|
|
2018-01-17 15:37:29 +00:00
|
|
|
createOption(value, text) {
|
2018-01-15 15:24:18 +00:00
|
|
|
const option = document.createElement('option');
|
2018-01-17 15:37:29 +00:00
|
|
|
option.value = value;
|
2018-01-15 15:24:18 +00:00
|
|
|
option.text = text;
|
|
|
|
return option;
|
|
|
|
}
|
|
|
|
|
2018-02-13 14:03:38 +00:00
|
|
|
populateSelect(id, iterable, labelFn = null, autoselect = null) {
|
|
|
|
if (labelFn == null) labelFn = e => e;
|
|
|
|
for (let [key, value] of iterable) {
|
|
|
|
const label = labelFn(key, value);
|
|
|
|
const option = this.createOption(key, label);
|
|
|
|
if (autoselect === key) {
|
2018-01-15 15:24:18 +00:00
|
|
|
option.selected = 'selected';
|
|
|
|
}
|
|
|
|
this.$(id).appendChild(option);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
clearCategories() {
|
|
|
|
for (const category of CATEGORIES.keys()) {
|
|
|
|
let f = this.$('#' + category + 'Content');
|
|
|
|
while (f.firstChild) {
|
|
|
|
f.removeChild(f.firstChild);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
populateCategories() {
|
|
|
|
this.clearCategories();
|
|
|
|
const categories = {};
|
|
|
|
for (let cat of CATEGORIES.keys()) {
|
|
|
|
categories[cat] = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let instance_type of this.data[this.selection.isolate]
|
|
|
|
.non_empty_instance_types) {
|
|
|
|
const category = this.categoryForType(instance_type);
|
|
|
|
categories[category].push(instance_type);
|
|
|
|
}
|
|
|
|
for (let category of Object.keys(categories)) {
|
|
|
|
categories[category].sort();
|
|
|
|
for (let instance_type of categories[category]) {
|
|
|
|
this.$('#' + category + 'Content')
|
|
|
|
.appendChild(this.createCheckBox(instance_type, category));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unselectCategory(category) {
|
|
|
|
for (let checkbox of this.shadowRoot.querySelectorAll(
|
|
|
|
'input[name=' + category + 'Checkbox]')) {
|
|
|
|
checkbox.checked = false;
|
|
|
|
}
|
|
|
|
this.notifySelectionChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
selectCategory(category) {
|
|
|
|
for (let checkbox of this.shadowRoot.querySelectorAll(
|
|
|
|
'input[name=' + category + 'Checkbox]')) {
|
|
|
|
checkbox.checked = true;
|
|
|
|
}
|
|
|
|
this.notifySelectionChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
createCheckBox(instance_type, category) {
|
|
|
|
const div = document.createElement('div');
|
|
|
|
div.classList.add('boxDiv');
|
|
|
|
const input = document.createElement('input');
|
|
|
|
div.appendChild(input);
|
|
|
|
input.type = 'checkbox';
|
|
|
|
input.name = category + 'Checkbox';
|
|
|
|
input.checked = 'checked';
|
|
|
|
input.id = instance_type + 'Checkbox';
|
2018-01-26 16:30:08 +00:00
|
|
|
input.instance_type = instance_type;
|
2018-01-15 15:24:18 +00:00
|
|
|
input.value = instance_type;
|
|
|
|
input.addEventListener('change', e => this.notifySelectionChanged(e));
|
|
|
|
const label = document.createElement('label');
|
|
|
|
div.appendChild(label);
|
|
|
|
label.innerText = instance_type;
|
|
|
|
label.htmlFor = instance_type + 'Checkbox';
|
|
|
|
return div;
|
|
|
|
}
|
2018-01-17 15:37:29 +00:00
|
|
|
|
|
|
|
exportCurrentSelection(e) {
|
|
|
|
const data = [];
|
|
|
|
const selected_data = this.data[this.selection.isolate]
|
|
|
|
.gcs[this.selection.gc][this.selection.data_set]
|
|
|
|
.instance_type_data;
|
|
|
|
Object.values(this.selection.categories).forEach(instance_types => {
|
|
|
|
instance_types.forEach(instance_type => {
|
|
|
|
data.push([instance_type, selected_data[instance_type].overall / KB]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
const createInlineContent = arrayOfRows => {
|
|
|
|
const content = arrayOfRows.reduce(
|
|
|
|
(accu, rowAsArray) => {return accu + `${rowAsArray.join(',')}\n`},
|
|
|
|
'');
|
|
|
|
return `data:text/csv;charset=utf-8,${content}`;
|
|
|
|
};
|
|
|
|
const encodedUri = encodeURI(createInlineContent(data));
|
|
|
|
const link = document.createElement('a');
|
|
|
|
link.setAttribute('href', encodedUri);
|
|
|
|
link.setAttribute(
|
|
|
|
'download',
|
|
|
|
`heap_objects_data_${this.selection.isolate}_${this.selection.gc}.csv`);
|
|
|
|
this.shadowRoot.appendChild(link);
|
|
|
|
link.click();
|
|
|
|
this.shadowRoot.removeChild(link);
|
|
|
|
}
|
2018-01-15 15:24:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
customElements.define('details-selection', DetailsSelection);
|