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 20:08:31 +00:00
|
|
|
import {Isolate} from './model.js';
|
2018-01-15 15:24:18 +00:00
|
|
|
|
2020-03-23 12:26:38 +00:00
|
|
|
defineCustomElement('trace-file-reader', (templateText) =>
|
|
|
|
class TraceFileReader 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
|
|
|
this.addEventListener('click', e => this.handleClick(e));
|
|
|
|
this.addEventListener('dragover', e => this.handleDragOver(e));
|
|
|
|
this.addEventListener('drop', e => this.handleChange(e));
|
|
|
|
this.$('#file').addEventListener('change', e => this.handleChange(e));
|
2018-03-02 12:22:56 +00:00
|
|
|
this.$('#fileReader').addEventListener('keydown', e => this.handleKeyEvent(e));
|
2018-01-15 15:24:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$(id) {
|
|
|
|
return this.shadowRoot.querySelector(id);
|
|
|
|
}
|
|
|
|
|
2018-02-14 08:26:42 +00:00
|
|
|
get section() {
|
|
|
|
return this.$('#fileReaderSection');
|
|
|
|
}
|
|
|
|
|
2018-01-15 15:24:18 +00:00
|
|
|
updateLabel(text) {
|
|
|
|
this.$('#label').innerText = text;
|
|
|
|
}
|
|
|
|
|
2018-03-02 12:22:56 +00:00
|
|
|
handleKeyEvent(event) {
|
|
|
|
if (event.key == "Enter") this.handleClick(event);
|
|
|
|
}
|
|
|
|
|
2018-01-15 15:24:18 +00:00
|
|
|
handleClick(event) {
|
|
|
|
this.$('#file').click();
|
|
|
|
}
|
|
|
|
|
|
|
|
handleChange(event) {
|
|
|
|
// Used for drop and file change.
|
|
|
|
event.preventDefault();
|
|
|
|
var host = event.dataTransfer ? event.dataTransfer : event.target;
|
|
|
|
this.readFile(host.files[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleDragOver(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
|
|
|
|
2018-03-02 12:22:56 +00:00
|
|
|
connectedCallback() {
|
|
|
|
this.$('#fileReader').focus();
|
|
|
|
}
|
2018-01-15 15:24:18 +00:00
|
|
|
|
|
|
|
readFile(file) {
|
|
|
|
if (!file) {
|
|
|
|
this.updateLabel('Failed to load file.');
|
|
|
|
return;
|
|
|
|
}
|
2018-03-02 12:22:56 +00:00
|
|
|
this.$('#fileReader').blur();
|
2018-01-15 15:24:18 +00:00
|
|
|
|
2018-02-14 08:26:42 +00:00
|
|
|
this.section.className = 'loading';
|
2018-01-23 14:48:08 +00:00
|
|
|
const reader = new FileReader();
|
|
|
|
|
2018-01-26 12:43:31 +00:00
|
|
|
if (['application/gzip', 'application/x-gzip'].includes(file.type)) {
|
2018-01-23 14:48:08 +00:00
|
|
|
reader.onload = (e) => {
|
|
|
|
try {
|
|
|
|
const textResult = pako.inflate(e.target.result, {to: 'string'});
|
|
|
|
this.processRawText(file, textResult);
|
2018-02-14 08:26:42 +00:00
|
|
|
this.section.className = 'success';
|
2018-03-02 10:51:03 +00:00
|
|
|
this.$('#fileReader').classList.add('done');
|
2018-01-23 14:48:08 +00:00
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
2018-02-14 08:26:42 +00:00
|
|
|
this.section.className = 'failure';
|
2018-01-23 14:48:08 +00:00
|
|
|
}
|
|
|
|
};
|
2018-03-02 10:51:03 +00:00
|
|
|
// Delay the loading a bit to allow for CSS animations to happen.
|
2018-11-20 20:43:55 +00:00
|
|
|
setTimeout(() => reader.readAsArrayBuffer(file), 0);
|
2018-01-23 14:48:08 +00:00
|
|
|
} else {
|
2018-07-30 19:52:23 +00:00
|
|
|
reader.onload = (e) => {
|
|
|
|
try {
|
|
|
|
this.processRawText(file, e.target.result);
|
|
|
|
this.section.className = 'success';
|
|
|
|
this.$('#fileReader').classList.add('done');
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
this.section.className = 'failure';
|
|
|
|
}
|
|
|
|
};
|
2018-11-20 20:43:55 +00:00
|
|
|
// Delay the loading a bit to allow for CSS animations to happen.
|
|
|
|
setTimeout(() => reader.readAsText(file), 0);
|
2018-01-23 14:48:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
processRawText(file, result) {
|
2020-03-27 10:02:24 +00:00
|
|
|
let return_data;
|
|
|
|
if (result.includes('V8.GC_Objects_Stats')) {
|
|
|
|
return_data = this.createModelFromChromeTraceFile(result);
|
|
|
|
} else {
|
|
|
|
let contents = result.split('\n');
|
|
|
|
return_data = this.createModelFromV8TraceFile(contents);
|
|
|
|
}
|
2018-02-01 15:19:18 +00:00
|
|
|
this.extendAndSanitizeModel(return_data);
|
2018-01-23 14:48:08 +00:00
|
|
|
this.updateLabel('Finished loading \'' + file.name + '\'.');
|
|
|
|
this.dispatchEvent(new CustomEvent(
|
|
|
|
'change', {bubbles: true, composed: true, detail: return_data}));
|
2018-01-15 15:24:18 +00:00
|
|
|
}
|
|
|
|
|
2018-02-01 15:19:18 +00:00
|
|
|
createOrUpdateEntryIfNeeded(data, entry) {
|
2018-01-16 13:14:26 +00:00
|
|
|
console.assert(entry.isolate, 'entry should have an isolate');
|
|
|
|
if (!(entry.isolate in data)) {
|
2018-02-13 14:03:38 +00:00
|
|
|
data[entry.isolate] = new Isolate(entry.isolate);
|
2018-01-16 13:14:26 +00:00
|
|
|
}
|
|
|
|
const data_object = data[entry.isolate];
|
|
|
|
if (('id' in entry) && !(entry.id in data_object.gcs)) {
|
|
|
|
data_object.gcs[entry.id] = {non_empty_instance_types: new Set()};
|
|
|
|
}
|
|
|
|
if ('time' in entry) {
|
2018-03-02 10:51:03 +00:00
|
|
|
if (data_object.end === null || data_object.end < entry.time) {
|
2018-01-15 15:24:18 +00:00
|
|
|
data_object.end = entry.time;
|
2018-03-02 10:51:03 +00:00
|
|
|
}
|
|
|
|
if (data_object.start === null || data_object.start > entry.time) {
|
2018-01-15 15:24:18 +00:00
|
|
|
data_object.start = entry.time;
|
2018-03-02 10:51:03 +00:00
|
|
|
}
|
2018-01-16 13:14:26 +00:00
|
|
|
}
|
|
|
|
}
|
2018-01-15 15:24:18 +00:00
|
|
|
|
2018-02-01 15:19:18 +00:00
|
|
|
createDatasetIfNeeded(data, entry, data_set) {
|
2018-01-16 13:14:26 +00:00
|
|
|
if (!(data_set in data[entry.isolate].gcs[entry.id])) {
|
|
|
|
data[entry.isolate].gcs[entry.id][data_set] = {
|
|
|
|
instance_type_data: {},
|
|
|
|
non_empty_instance_types: new Set(),
|
|
|
|
overall: 0
|
|
|
|
};
|
|
|
|
data[entry.isolate].data_sets.add(data_set);
|
2018-01-15 15:24:18 +00:00
|
|
|
}
|
2018-01-16 13:14:26 +00:00
|
|
|
}
|
2018-01-15 15:24:18 +00:00
|
|
|
|
2018-05-14 13:06:24 +00:00
|
|
|
addFieldTypeData(data, isolate, gc_id, data_set, tagged_fields,
|
2019-07-25 12:30:24 +00:00
|
|
|
inobject_smi_fields, embedder_fields, unboxed_double_fields,
|
|
|
|
boxed_double_fields, string_data, other_raw_fields) {
|
2018-05-14 13:06:24 +00:00
|
|
|
data[isolate].gcs[gc_id][data_set].field_data = {
|
|
|
|
tagged_fields,
|
2019-07-25 12:30:24 +00:00
|
|
|
inobject_smi_fields,
|
2018-05-14 13:06:24 +00:00
|
|
|
embedder_fields,
|
|
|
|
unboxed_double_fields,
|
2019-07-25 12:30:24 +00:00
|
|
|
boxed_double_fields,
|
|
|
|
string_data,
|
2018-05-14 13:06:24 +00:00
|
|
|
other_raw_fields
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-02-01 15:19:18 +00:00
|
|
|
addInstanceTypeData(data, isolate, gc_id, data_set, instance_type, entry) {
|
2018-01-16 13:14:26 +00:00
|
|
|
data[isolate].gcs[gc_id][data_set].instance_type_data[instance_type] = {
|
|
|
|
overall: entry.overall,
|
|
|
|
count: entry.count,
|
|
|
|
histogram: entry.histogram,
|
|
|
|
over_allocated: entry.over_allocated,
|
|
|
|
over_allocated_histogram: entry.over_allocated_histogram
|
|
|
|
};
|
|
|
|
data[isolate].gcs[gc_id][data_set].overall += entry.overall;
|
|
|
|
if (entry.overall !== 0) {
|
|
|
|
data[isolate].gcs[gc_id][data_set].non_empty_instance_types.add(
|
|
|
|
instance_type);
|
|
|
|
data[isolate].gcs[gc_id].non_empty_instance_types.add(instance_type);
|
|
|
|
data[isolate].non_empty_instance_types.add(instance_type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-01 15:19:18 +00:00
|
|
|
extendAndSanitizeModel(data) {
|
2018-01-16 13:14:26 +00:00
|
|
|
const checkNonNegativeProperty = (obj, property) => {
|
|
|
|
console.assert(obj[property] >= 0, 'negative property', obj, property);
|
2018-01-15 15:24:18 +00:00
|
|
|
};
|
|
|
|
|
2018-02-13 14:03:38 +00:00
|
|
|
Object.values(data).forEach(isolate => isolate.finalize());
|
2018-01-16 13:14:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
createModelFromChromeTraceFile(contents) {
|
2020-03-27 10:02:24 +00:00
|
|
|
const data = Object.create(null); // Final data container.
|
|
|
|
const parseOneGCEvent = (actual_data) => {
|
|
|
|
Object.keys(actual_data).forEach(data_set => {
|
|
|
|
const string_entry = actual_data[data_set];
|
|
|
|
try {
|
|
|
|
const entry = JSON.parse(string_entry);
|
|
|
|
this.createOrUpdateEntryIfNeeded(data, entry);
|
|
|
|
this.createDatasetIfNeeded(data, entry, data_set);
|
|
|
|
const isolate = entry.isolate;
|
|
|
|
const time = entry.time;
|
|
|
|
const gc_id = entry.id;
|
|
|
|
data[isolate].gcs[gc_id].time = time;
|
2018-01-16 13:14:26 +00:00
|
|
|
|
2020-03-27 10:02:24 +00:00
|
|
|
const field_data = entry.field_data;
|
|
|
|
this.addFieldTypeData(data, isolate, gc_id, data_set,
|
|
|
|
field_data.tagged_fields,
|
|
|
|
field_data.inobject_smi_fields,
|
|
|
|
field_data.embedder_fields,
|
|
|
|
field_data.unboxed_double_fields,
|
|
|
|
field_data.boxed_double_fields,
|
|
|
|
field_data.string_data,
|
|
|
|
field_data.other_raw_fields);
|
2018-02-01 15:19:18 +00:00
|
|
|
|
2020-03-27 10:02:24 +00:00
|
|
|
data[isolate].gcs[gc_id][data_set].bucket_sizes =
|
|
|
|
entry.bucket_sizes;
|
|
|
|
for (let [instance_type, value] of Object.entries(
|
|
|
|
entry.type_data)) {
|
|
|
|
// Trace file format uses markers that do not have actual
|
|
|
|
// properties.
|
|
|
|
if (!('overall' in value)) continue;
|
|
|
|
this.addInstanceTypeData(
|
|
|
|
data, isolate, gc_id, data_set, instance_type, value);
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
console.error('Unable to parse data set entry', e);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
console.log(`Processing log as chrome trace file.`);
|
2018-01-16 13:14:26 +00:00
|
|
|
try {
|
2020-03-27 10:02:24 +00:00
|
|
|
let gc_events_filter = (event) => {
|
|
|
|
if (event.name == 'V8.GC_Objects_Stats') {
|
|
|
|
parseOneGCEvent(event.args);
|
|
|
|
}
|
|
|
|
return oboe.drop;
|
|
|
|
};
|
2018-05-14 13:06:24 +00:00
|
|
|
|
2020-03-27 10:02:24 +00:00
|
|
|
let oboe_stream = oboe();
|
|
|
|
// Trace files support two formats.
|
|
|
|
oboe_stream
|
|
|
|
// 1) {traceEvents: [ data ]}
|
|
|
|
.node('traceEvents.*', gc_events_filter)
|
|
|
|
// 2) [ data ]
|
|
|
|
.node('!.*', gc_events_filter)
|
|
|
|
.fail(() => { throw new Error("Trace data parse failed!"); });
|
|
|
|
oboe_stream.emit('data', contents);
|
2018-01-16 13:14:26 +00:00
|
|
|
} catch (e) {
|
2018-01-23 14:48:08 +00:00
|
|
|
console.error('Unable to parse chrome trace file.', e);
|
2018-01-16 13:14:26 +00:00
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
createModelFromV8TraceFile(contents) {
|
|
|
|
console.log('Processing log as V8 trace file.');
|
|
|
|
contents = contents.map(function(line) {
|
|
|
|
try {
|
|
|
|
// Strip away a potentially present adb logcat prefix.
|
|
|
|
line = line.replace(/^I\/v8\s*\(\d+\):\s+/g, '');
|
|
|
|
return JSON.parse(line);
|
|
|
|
} catch (e) {
|
2018-07-30 19:52:23 +00:00
|
|
|
console.log('Unable to parse line: \'' + line + '\' (' + e + ')');
|
2018-01-16 13:14:26 +00:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
});
|
|
|
|
|
|
|
|
const data = Object.create(null); // Final data container.
|
|
|
|
for (var entry of contents) {
|
|
|
|
if (entry === null || entry.type === undefined) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (entry.type === 'zone') {
|
2018-02-01 15:19:18 +00:00
|
|
|
this.createOrUpdateEntryIfNeeded(data, entry);
|
2018-01-16 13:14:26 +00:00
|
|
|
const stacktrace = ('stacktrace' in entry) ? entry.stacktrace : [];
|
|
|
|
data[entry.isolate].samples.zone[entry.time] = {
|
|
|
|
allocated: entry.allocated,
|
|
|
|
pooled: entry.pooled,
|
|
|
|
stacktrace: stacktrace
|
|
|
|
};
|
|
|
|
} else if (
|
|
|
|
entry.type === 'zonecreation' || entry.type === 'zonedestruction') {
|
2018-02-01 15:19:18 +00:00
|
|
|
this.createOrUpdateEntryIfNeeded(data, entry);
|
2018-01-16 13:14:26 +00:00
|
|
|
data[entry.isolate].zonetags.push(
|
|
|
|
Object.assign({opening: entry.type === 'zonecreation'}, entry));
|
|
|
|
} else if (entry.type === 'gc_descriptor') {
|
2018-02-01 15:19:18 +00:00
|
|
|
this.createOrUpdateEntryIfNeeded(data, entry);
|
2018-01-16 13:14:26 +00:00
|
|
|
data[entry.isolate].gcs[entry.id].time = entry.time;
|
|
|
|
if ('zone' in entry)
|
|
|
|
data[entry.isolate].gcs[entry.id].malloced = entry.zone;
|
2018-05-14 13:06:24 +00:00
|
|
|
} else if (entry.type === 'field_data') {
|
|
|
|
this.createOrUpdateEntryIfNeeded(data, entry);
|
|
|
|
this.createDatasetIfNeeded(data, entry, entry.key);
|
|
|
|
this.addFieldTypeData(data, entry.isolate, entry.id, entry.key,
|
2019-07-25 12:30:24 +00:00
|
|
|
entry.tagged_fields, entry.embedder_fields, entry.inobject_smi_fields,
|
|
|
|
entry.unboxed_double_fields, entry.boxed_double_fields,
|
|
|
|
entry.string_data, entry.other_raw_fields);
|
2018-01-16 13:14:26 +00:00
|
|
|
} else if (entry.type === 'instance_type_data') {
|
|
|
|
if (entry.id in data[entry.isolate].gcs) {
|
2018-02-01 15:19:18 +00:00
|
|
|
this.createOrUpdateEntryIfNeeded(data, entry);
|
|
|
|
this.createDatasetIfNeeded(data, entry, entry.key);
|
2018-01-16 13:14:26 +00:00
|
|
|
this.addInstanceTypeData(
|
2018-02-01 15:19:18 +00:00
|
|
|
data, entry.isolate, entry.id, entry.key,
|
2018-01-16 13:14:26 +00:00
|
|
|
entry.instance_type_name, entry);
|
|
|
|
}
|
|
|
|
} else if (entry.type === 'bucket_sizes') {
|
|
|
|
if (entry.id in data[entry.isolate].gcs) {
|
2018-02-01 15:19:18 +00:00
|
|
|
this.createOrUpdateEntryIfNeeded(data, entry);
|
|
|
|
this.createDatasetIfNeeded(data, entry, entry.key);
|
2018-01-16 13:14:26 +00:00
|
|
|
data[entry.isolate].gcs[entry.id][entry.key].bucket_sizes =
|
|
|
|
entry.sizes;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
console.log('Unknown entry type: ' + entry.type);
|
|
|
|
}
|
|
|
|
}
|
2018-01-15 15:24:18 +00:00
|
|
|
return data;
|
|
|
|
}
|
2020-03-23 12:26:38 +00:00
|
|
|
});
|