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';
|
|
|
|
|
2020-03-23 12:26:38 +00:00
|
|
|
import {
|
|
|
|
VIEW_BY_INSTANCE_TYPE,
|
|
|
|
VIEW_BY_INSTANCE_CATEGORY,
|
|
|
|
VIEW_BY_FIELD_TYPE
|
2020-03-23 20:08:31 +00:00
|
|
|
} from './details-selection.js';
|
2020-03-23 12:26:38 +00:00
|
|
|
|
|
|
|
defineCustomElement('global-timeline', (templateText) =>
|
|
|
|
class GlobalTimeline extends HTMLElement {
|
2018-01-15 15:24:18 +00:00
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
const shadowRoot = this.attachShadow({mode: 'open'});
|
2020-03-23 12:26:38 +00:00
|
|
|
shadowRoot.innerHTML = templateText;
|
2018-01-15 15:24:18 +00:00
|
|
|
}
|
|
|
|
|
2018-01-15 17:58:02 +00:00
|
|
|
$(id) {
|
|
|
|
return this.shadowRoot.querySelector(id);
|
|
|
|
}
|
|
|
|
|
2018-01-15 15:24:18 +00:00
|
|
|
set data(value) {
|
|
|
|
this._data = value;
|
|
|
|
this.stateChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
get data() {
|
|
|
|
return this._data;
|
|
|
|
}
|
|
|
|
|
|
|
|
set selection(value) {
|
|
|
|
this._selection = value;
|
|
|
|
this.stateChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
get selection() {
|
|
|
|
return this._selection;
|
|
|
|
}
|
|
|
|
|
|
|
|
isValid() {
|
|
|
|
return this.data && this.selection;
|
|
|
|
}
|
|
|
|
|
2018-01-15 20:27:40 +00:00
|
|
|
hide() {
|
|
|
|
this.$('#container').style.display = 'none';
|
|
|
|
}
|
|
|
|
|
|
|
|
show() {
|
|
|
|
this.$('#container').style.display = 'block';
|
|
|
|
}
|
|
|
|
|
2018-01-15 15:24:18 +00:00
|
|
|
stateChanged() {
|
2018-01-15 20:27:40 +00:00
|
|
|
if (this.isValid()) {
|
|
|
|
this.drawChart();
|
|
|
|
} else {
|
|
|
|
this.hide();
|
|
|
|
}
|
2018-01-15 15:24:18 +00:00
|
|
|
}
|
|
|
|
|
2018-05-14 13:06:24 +00:00
|
|
|
getFieldData() {
|
2018-05-23 10:25:52 +00:00
|
|
|
const labels = [
|
|
|
|
{type: 'number', label: 'Time'},
|
|
|
|
{type: 'number', label: 'Ptr compression benefit'},
|
|
|
|
{type: 'string', role: 'tooltip'},
|
|
|
|
{type: 'number', label: 'Embedder fields'},
|
2019-07-25 12:30:24 +00:00
|
|
|
{type: 'number', label: 'Tagged fields (excl. in-object Smis)'},
|
|
|
|
{type: 'number', label: 'In-object Smi-only fields'},
|
2018-05-23 10:25:52 +00:00
|
|
|
{type: 'number', label: 'Other raw fields'},
|
2019-07-25 12:30:24 +00:00
|
|
|
{type: 'number', label: 'Unboxed doubles'},
|
|
|
|
{type: 'number', label: 'Boxed doubles'},
|
|
|
|
{type: 'number', label: 'String data'}
|
2018-05-23 10:25:52 +00:00
|
|
|
];
|
2018-05-14 13:06:24 +00:00
|
|
|
const chart_data = [labels];
|
|
|
|
const isolate_data = this.data[this.selection.isolate];
|
2018-05-23 10:25:52 +00:00
|
|
|
let sum_total = 0;
|
|
|
|
let sum_ptr_compr_benefit_perc = 0;
|
|
|
|
let count = 0;
|
2018-05-14 13:06:24 +00:00
|
|
|
Object.keys(isolate_data.gcs).forEach(gc_key => {
|
|
|
|
const gc_data = isolate_data.gcs[gc_key];
|
|
|
|
const data_set = gc_data[this.selection.data_set].field_data;
|
|
|
|
const data = [];
|
|
|
|
data.push(gc_data.time * kMillis2Seconds);
|
2018-05-23 10:25:52 +00:00
|
|
|
const total = data_set.tagged_fields +
|
2019-07-25 12:30:24 +00:00
|
|
|
data_set.inobject_smi_fields +
|
2018-05-23 10:25:52 +00:00
|
|
|
data_set.embedder_fields +
|
|
|
|
data_set.other_raw_fields +
|
2019-07-25 12:30:24 +00:00
|
|
|
data_set.unboxed_double_fields +
|
|
|
|
data_set.boxed_double_fields +
|
|
|
|
data_set.string_data;
|
|
|
|
const ptr_compr_benefit =
|
2019-07-25 13:55:02 +00:00
|
|
|
(data_set.inobject_smi_fields + data_set.tagged_fields) / 2;
|
2018-05-23 10:25:52 +00:00
|
|
|
const ptr_compr_benefit_perc = ptr_compr_benefit / total * 100;
|
|
|
|
sum_total += total;
|
|
|
|
sum_ptr_compr_benefit_perc += ptr_compr_benefit_perc;
|
|
|
|
count++;
|
|
|
|
const tooltip = "Ptr compression benefit: " +
|
|
|
|
(ptr_compr_benefit / KB).toFixed(2) + "KB " +
|
|
|
|
" (" + ptr_compr_benefit_perc.toFixed(2) + "%)";
|
|
|
|
data.push(ptr_compr_benefit / KB);
|
|
|
|
data.push(tooltip);
|
2018-05-14 13:06:24 +00:00
|
|
|
data.push(data_set.embedder_fields / KB);
|
|
|
|
data.push(data_set.tagged_fields / KB);
|
2019-07-25 13:55:02 +00:00
|
|
|
data.push(data_set.inobject_smi_fields / KB);
|
2018-05-14 13:06:24 +00:00
|
|
|
data.push(data_set.other_raw_fields / KB);
|
|
|
|
data.push(data_set.unboxed_double_fields / KB);
|
2019-07-25 12:30:24 +00:00
|
|
|
data.push(data_set.boxed_double_fields / KB);
|
|
|
|
data.push(data_set.string_data / KB);
|
2018-05-14 13:06:24 +00:00
|
|
|
chart_data.push(data);
|
|
|
|
});
|
2018-05-23 10:25:52 +00:00
|
|
|
const avg_ptr_compr_benefit_perc =
|
|
|
|
count ? sum_ptr_compr_benefit_perc / count : 0;
|
|
|
|
console.log("==================================================");
|
|
|
|
console.log("= Average ptr compression benefit is " +
|
|
|
|
avg_ptr_compr_benefit_perc.toFixed(2) + "%");
|
|
|
|
console.log("= Average V8 heap size " +
|
|
|
|
(sum_total / count / KB).toFixed(2) + " KB");
|
|
|
|
console.log("==================================================");
|
2018-05-14 13:06:24 +00:00
|
|
|
return chart_data;
|
|
|
|
}
|
|
|
|
|
2018-01-15 17:58:02 +00:00
|
|
|
getCategoryData() {
|
2018-01-15 15:24:18 +00:00
|
|
|
const categories = Object.keys(this.selection.categories)
|
|
|
|
.map(k => this.selection.category_names.get(k));
|
|
|
|
const labels = ['Time', ...categories];
|
|
|
|
const chart_data = [labels];
|
|
|
|
const isolate_data = this.data[this.selection.isolate];
|
2018-01-15 17:58:02 +00:00
|
|
|
Object.keys(isolate_data.gcs).forEach(gc_key => {
|
|
|
|
const gc_data = isolate_data.gcs[gc_key];
|
2018-01-15 15:24:18 +00:00
|
|
|
const data_set = gc_data[this.selection.data_set].instance_type_data;
|
|
|
|
const data = [];
|
2018-03-02 10:51:03 +00:00
|
|
|
data.push(gc_data.time * kMillis2Seconds);
|
2018-01-15 17:58:02 +00:00
|
|
|
Object.values(this.selection.categories).forEach(instance_types => {
|
|
|
|
data.push(
|
|
|
|
instance_types
|
|
|
|
.map(instance_type => {
|
|
|
|
return data_set[instance_type].overall;
|
|
|
|
})
|
|
|
|
.reduce((accu, current) => accu + current, 0) /
|
|
|
|
KB);
|
|
|
|
});
|
2018-01-15 15:24:18 +00:00
|
|
|
chart_data.push(data);
|
2018-01-15 17:58:02 +00:00
|
|
|
});
|
|
|
|
return chart_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
getInstanceTypeData() {
|
|
|
|
const instance_types =
|
|
|
|
Object.values(this.selection.categories)
|
|
|
|
.reduce((accu, current) => accu.concat(current), []);
|
|
|
|
const labels = ['Time', ...instance_types];
|
|
|
|
const chart_data = [labels];
|
|
|
|
const isolate_data = this.data[this.selection.isolate];
|
|
|
|
Object.keys(isolate_data.gcs).forEach(gc_key => {
|
|
|
|
const gc_data = isolate_data.gcs[gc_key];
|
|
|
|
const data_set = gc_data[this.selection.data_set].instance_type_data;
|
|
|
|
const data = [];
|
2018-03-02 10:51:03 +00:00
|
|
|
data.push(gc_data.time * kMillis2Seconds);
|
2018-01-15 17:58:02 +00:00
|
|
|
instance_types.forEach(instance_type => {
|
|
|
|
data.push(data_set[instance_type].overall / KB);
|
|
|
|
});
|
|
|
|
chart_data.push(data);
|
|
|
|
});
|
|
|
|
return chart_data;
|
|
|
|
}
|
|
|
|
|
2018-05-14 13:06:24 +00:00
|
|
|
getChartData() {
|
|
|
|
switch (this.selection.data_view) {
|
|
|
|
case VIEW_BY_FIELD_TYPE:
|
|
|
|
return this.getFieldData();
|
|
|
|
case VIEW_BY_INSTANCE_CATEGORY:
|
|
|
|
return this.getCategoryData();
|
|
|
|
case VIEW_BY_INSTANCE_TYPE:
|
|
|
|
default:
|
|
|
|
return this.getInstanceTypeData();
|
|
|
|
}
|
|
|
|
}
|
2018-01-15 15:24:18 +00:00
|
|
|
|
2018-05-14 13:06:24 +00:00
|
|
|
getChartOptions() {
|
2018-01-15 15:24:18 +00:00
|
|
|
const options = {
|
|
|
|
isStacked: true,
|
|
|
|
hAxis: {
|
2018-03-02 10:51:03 +00:00
|
|
|
format: '###.##s',
|
|
|
|
title: 'Time [s]',
|
|
|
|
},
|
|
|
|
vAxis: {
|
|
|
|
format: '#,###KB',
|
|
|
|
title: 'Memory consumption [KBytes]'
|
2018-01-15 15:24:18 +00:00
|
|
|
},
|
2018-03-02 10:51:03 +00:00
|
|
|
chartArea: {left:100, width: '85%', height: '70%'},
|
2018-01-15 15:24:18 +00:00
|
|
|
legend: {position: 'top', maxLines: '1'},
|
|
|
|
pointsVisible: true,
|
|
|
|
pointSize: 5,
|
2018-01-15 17:58:02 +00:00
|
|
|
explorer: {},
|
2018-01-15 15:24:18 +00:00
|
|
|
};
|
2018-05-14 13:06:24 +00:00
|
|
|
switch (this.selection.data_view) {
|
|
|
|
case VIEW_BY_FIELD_TYPE:
|
|
|
|
// Overlay pointer compression benefit on top of the graph
|
|
|
|
return Object.assign(options, {
|
|
|
|
series: {0: {type: 'line', lineDashStyle: [13, 13]}},
|
|
|
|
});
|
|
|
|
case VIEW_BY_INSTANCE_CATEGORY:
|
|
|
|
case VIEW_BY_INSTANCE_TYPE:
|
|
|
|
default:
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
drawChart() {
|
2020-05-25 08:37:56 +00:00
|
|
|
setTimeout(() => this._drawChart(), 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
_drawChart() {
|
2018-05-14 13:06:24 +00:00
|
|
|
console.assert(this.data, 'invalid data');
|
|
|
|
console.assert(this.selection, 'invalid selection');
|
|
|
|
|
|
|
|
const chart_data = this.getChartData();
|
|
|
|
|
|
|
|
const data = google.visualization.arrayToDataTable(chart_data);
|
|
|
|
const options = this.getChartOptions();
|
2018-01-15 17:58:02 +00:00
|
|
|
const chart = new google.visualization.AreaChart(this.$('#chart'));
|
2018-01-15 20:27:40 +00:00
|
|
|
this.show();
|
2018-01-15 15:24:18 +00:00
|
|
|
chart.draw(data, google.charts.Line.convertOptions(options));
|
|
|
|
}
|
2020-03-23 12:26:38 +00:00
|
|
|
});
|