2020-07-14 15:03:14 +00:00
|
|
|
// Copyright 2020 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.
|
|
|
|
|
2020-09-28 13:50:56 +00:00
|
|
|
|
2020-09-02 13:17:35 +00:00
|
|
|
import { SelectionEvent, FocusEvent, SelectTimeEvent } from "./events.mjs";
|
2020-08-12 15:10:23 +00:00
|
|
|
import { State } from "./app-model.mjs";
|
2020-10-19 10:13:33 +00:00
|
|
|
import { MapLogEntry } from "./log/map.mjs";
|
|
|
|
import { IcLogEntry } from "./log/ic.mjs";
|
|
|
|
import { Processor } from "./processor.mjs";
|
2020-09-28 13:50:56 +00:00
|
|
|
import { SourcePosition } from "../profile.mjs";
|
2020-08-12 15:10:23 +00:00
|
|
|
import { $ } from "./helper.mjs";
|
|
|
|
import "./ic-panel.mjs";
|
|
|
|
import "./timeline-panel.mjs";
|
|
|
|
import "./map-panel.mjs";
|
|
|
|
import "./log-file-reader.mjs";
|
2020-08-28 14:41:56 +00:00
|
|
|
import "./source-panel.mjs";
|
2020-09-28 13:50:56 +00:00
|
|
|
|
|
|
|
|
2020-07-16 10:02:52 +00:00
|
|
|
class App {
|
2020-10-19 10:45:42 +00:00
|
|
|
_state;
|
|
|
|
_view;
|
|
|
|
_navigation;
|
2020-08-13 07:35:23 +00:00
|
|
|
constructor(fileReaderId, mapPanelId, timelinePanelId,
|
2020-10-19 12:39:55 +00:00
|
|
|
icPanelId, mapTrackId, icTrackId, deoptTrackId, sourcePanelId) {
|
2020-10-19 10:45:42 +00:00
|
|
|
this._view = {
|
2020-08-04 08:51:59 +00:00
|
|
|
logFileReader: $(fileReaderId),
|
|
|
|
icPanel: $(icPanelId),
|
|
|
|
mapPanel: $(mapPanelId),
|
|
|
|
timelinePanel: $(timelinePanelId),
|
|
|
|
mapTrack: $(mapTrackId),
|
|
|
|
icTrack: $(icTrackId),
|
2020-10-19 12:39:55 +00:00
|
|
|
deoptTrack: $(deoptTrackId),
|
2020-08-28 14:41:56 +00:00
|
|
|
sourcePanel: $(sourcePanelId)
|
2020-08-12 15:10:23 +00:00
|
|
|
};
|
2020-10-19 10:45:42 +00:00
|
|
|
this._state = new State();
|
|
|
|
this._navigation = new Navigation(this._state, this._view);
|
2020-08-13 07:35:23 +00:00
|
|
|
document.addEventListener('keydown',
|
2020-10-19 10:45:42 +00:00
|
|
|
e => this._navigation.handleKeyDown(e));
|
2020-08-06 14:41:38 +00:00
|
|
|
this.toggleSwitch = $('.theme-switch input[type="checkbox"]');
|
2020-08-12 15:10:23 +00:00
|
|
|
this.toggleSwitch.addEventListener("change", (e) => this.switchTheme(e));
|
2020-10-19 10:45:42 +00:00
|
|
|
this._view.logFileReader.addEventListener("fileuploadstart", (e) =>
|
2020-08-12 15:10:23 +00:00
|
|
|
this.handleFileUpload(e)
|
|
|
|
);
|
2020-10-19 10:45:42 +00:00
|
|
|
this._view.logFileReader.addEventListener("fileuploadend", (e) =>
|
2020-08-12 15:10:23 +00:00
|
|
|
this.handleDataUpload(e)
|
|
|
|
);
|
2020-10-19 10:45:42 +00:00
|
|
|
Object.entries(this._view).forEach(([_, panel]) => {
|
2020-08-13 12:55:19 +00:00
|
|
|
panel.addEventListener(SelectionEvent.name,
|
2020-08-13 09:14:29 +00:00
|
|
|
e => this.handleShowEntries(e));
|
2020-08-13 12:55:19 +00:00
|
|
|
panel.addEventListener(FocusEvent.name,
|
2020-08-13 09:14:29 +00:00
|
|
|
e => this.handleShowEntryDetail(e));
|
2020-08-13 12:55:19 +00:00
|
|
|
panel.addEventListener(SelectTimeEvent.name,
|
2020-08-13 09:14:29 +00:00
|
|
|
e => this.handleTimeRangeSelect(e));
|
2020-08-06 14:41:38 +00:00
|
|
|
});
|
2020-07-23 08:41:38 +00:00
|
|
|
}
|
2020-08-12 15:10:23 +00:00
|
|
|
handleShowEntries(e) {
|
2020-10-19 10:13:33 +00:00
|
|
|
if (e.entries[0] instanceof MapLogEntry) {
|
2020-08-13 09:14:29 +00:00
|
|
|
this.showMapEntries(e.entries);
|
2020-10-19 10:13:33 +00:00
|
|
|
} else if (e.entries[0] instanceof IcLogEntry) {
|
2020-08-13 11:20:03 +00:00
|
|
|
this.showIcEntries(e.entries);
|
2020-09-23 10:30:17 +00:00
|
|
|
} else if (e.entries[0] instanceof SourcePosition) {
|
2020-08-28 14:41:56 +00:00
|
|
|
this.showSourcePositionEntries(e.entries);
|
2020-08-13 11:20:03 +00:00
|
|
|
} else {
|
2020-09-23 10:30:17 +00:00
|
|
|
throw new Error("Unknown selection type!");
|
2020-08-06 14:41:38 +00:00
|
|
|
}
|
2020-07-22 14:41:42 +00:00
|
|
|
}
|
2020-08-13 11:20:03 +00:00
|
|
|
showMapEntries(entries) {
|
2020-10-19 10:45:42 +00:00
|
|
|
this._state.selectedMapLogEntries = entries;
|
|
|
|
this._view.mapPanel.selectedMapLogEntries = this.#state.selectedMapLogEntries;
|
2020-08-13 11:20:03 +00:00
|
|
|
}
|
|
|
|
showIcEntries(entries) {
|
2020-10-19 10:45:42 +00:00
|
|
|
this._state.selectedIcLogEntries = entries;
|
|
|
|
this._view.icPanel.selectedLogEntries = this.#state.selectedIcLogEntries;
|
2020-08-13 11:20:03 +00:00
|
|
|
}
|
2020-08-28 14:41:56 +00:00
|
|
|
showSourcePositionEntries(entries) {
|
|
|
|
//TODO(zcankara) Handle multiple source position selection events
|
2020-10-19 10:45:42 +00:00
|
|
|
this._view.sourcePanel.selectedSourcePositions = entries;
|
2020-08-28 14:41:56 +00:00
|
|
|
}
|
2020-08-13 11:20:03 +00:00
|
|
|
|
2020-08-13 09:14:29 +00:00
|
|
|
handleTimeRangeSelect(e) {
|
|
|
|
this.selectTimeRange(e.start, e.end);
|
|
|
|
}
|
2020-08-12 15:10:23 +00:00
|
|
|
handleShowEntryDetail(e) {
|
2020-10-19 10:13:33 +00:00
|
|
|
if (e.entry instanceof MapLogEntry) {
|
|
|
|
this.selectMapLogEntry(e.entry);
|
|
|
|
} else if (e.entry instanceof IcLogEntry) {
|
|
|
|
this.selectICLogEntry(e.entry);
|
2020-09-23 10:30:17 +00:00
|
|
|
} else if (e.entry instanceof SourcePosition) {
|
2020-10-19 10:13:33 +00:00
|
|
|
this.selectSourcePosition(e.entry);
|
2020-08-12 15:10:23 +00:00
|
|
|
} else {
|
2020-09-23 10:30:17 +00:00
|
|
|
throw new Error("Unknown selection type!");
|
2020-08-06 14:41:38 +00:00
|
|
|
}
|
2020-07-22 14:41:42 +00:00
|
|
|
}
|
2020-08-13 09:14:29 +00:00
|
|
|
selectTimeRange(start, end) {
|
2020-10-19 10:45:42 +00:00
|
|
|
this._state.timeSelection.start = start;
|
|
|
|
this._state.timeSelection.end = end;
|
|
|
|
this._state.icTimeline.selectTimeRange(start, end);
|
|
|
|
this._state.mapTimeline.selectTimeRange(start, end);
|
2020-10-19 12:39:55 +00:00
|
|
|
this._view.mapPanel.selectedMapLogEntries =
|
2020-10-19 10:45:42 +00:00
|
|
|
this._state.mapTimeline.selection;
|
2020-10-19 12:39:55 +00:00
|
|
|
this._view.icPanel.selectedLogEntries = this._state.icTimeline.selection;
|
2020-08-13 09:14:29 +00:00
|
|
|
}
|
2020-10-19 10:13:33 +00:00
|
|
|
selectMapLogEntry(entry) {
|
2020-10-19 10:45:42 +00:00
|
|
|
this._state.map = entry;
|
|
|
|
this._view.mapTrack.selectedEntry = entry;
|
|
|
|
this._view.mapPanel.map = entry;
|
2020-08-04 08:51:59 +00:00
|
|
|
}
|
2020-10-19 10:13:33 +00:00
|
|
|
selectICLogEntry(entry) {
|
2020-10-19 10:45:42 +00:00
|
|
|
this._state.ic = entry;
|
2020-10-19 12:39:55 +00:00
|
|
|
this._view.icPanel.selectedLogEntries = [entry];
|
2020-08-04 08:51:59 +00:00
|
|
|
}
|
2020-10-19 10:13:33 +00:00
|
|
|
selectSourcePosition(sourcePositions) {
|
2020-08-28 14:41:56 +00:00
|
|
|
if (!sourcePositions.script) return;
|
2020-10-19 10:45:42 +00:00
|
|
|
this._view.sourcePanel.selectedSourcePositions = [sourcePositions];
|
2020-08-04 08:51:59 +00:00
|
|
|
}
|
2020-08-28 14:41:56 +00:00
|
|
|
|
2020-08-12 15:10:23 +00:00
|
|
|
handleFileUpload(e) {
|
2020-08-27 17:51:33 +00:00
|
|
|
this.restartApp();
|
2020-08-12 15:10:23 +00:00
|
|
|
$("#container").className = "initial";
|
2020-07-16 10:02:52 +00:00
|
|
|
}
|
2020-10-19 10:13:33 +00:00
|
|
|
|
2020-08-27 17:51:33 +00:00
|
|
|
restartApp() {
|
2020-10-19 10:45:42 +00:00
|
|
|
this._state = new State();
|
|
|
|
this._navigation = new Navigation(this._state, this._view);
|
2020-08-27 17:51:33 +00:00
|
|
|
}
|
2020-10-19 10:13:33 +00:00
|
|
|
|
2020-09-02 13:17:35 +00:00
|
|
|
// Event log processing
|
|
|
|
handleLoadTextProcessor(text) {
|
|
|
|
let logProcessor = new Processor();
|
|
|
|
logProcessor.processString(text);
|
|
|
|
return logProcessor;
|
2020-07-16 10:02:52 +00:00
|
|
|
}
|
2020-07-14 15:03:14 +00:00
|
|
|
|
2020-07-16 10:02:52 +00:00
|
|
|
// call when a new file uploaded
|
|
|
|
handleDataUpload(e) {
|
2020-08-12 15:10:23 +00:00
|
|
|
if (!e.detail) return;
|
|
|
|
$("#container").className = "loaded";
|
2020-07-16 10:02:52 +00:00
|
|
|
// instantiate the app logic
|
|
|
|
let fileData = e.detail;
|
2020-09-23 10:30:17 +00:00
|
|
|
const processor = this.handleLoadTextProcessor(fileData.chunk);
|
|
|
|
const mapTimeline = processor.mapTimeline;
|
|
|
|
const icTimeline = processor.icTimeline;
|
2020-10-19 12:39:55 +00:00
|
|
|
const deoptTimeline = processor.deoptTimeline;
|
2020-09-23 10:30:17 +00:00
|
|
|
// Load map log events timeline.
|
2020-10-19 10:45:42 +00:00
|
|
|
this._state.mapTimeline = mapTimeline;
|
2020-09-23 10:30:17 +00:00
|
|
|
// Transitions must be set before timeline for stats panel.
|
2020-10-19 10:45:42 +00:00
|
|
|
this._view.mapPanel.transitions = this._state.mapTimeline.transitions;
|
|
|
|
this._view.mapTrack.data = mapTimeline;
|
|
|
|
this._state.chunks = this._view.mapTrack.chunks;
|
|
|
|
this._view.mapPanel.timeline = mapTimeline;
|
2020-09-23 10:30:17 +00:00
|
|
|
// Load ic log events timeline.
|
2020-10-19 10:45:42 +00:00
|
|
|
this._state.icTimeline = icTimeline;
|
|
|
|
this._view.icPanel.timeline = icTimeline;
|
|
|
|
this._view.icTrack.data = icTimeline;
|
2020-10-19 12:39:55 +00:00
|
|
|
this._view.deoptTrack.data = deoptTimeline;
|
2020-10-19 10:45:42 +00:00
|
|
|
this._view.sourcePanel.data = processor.scripts
|
2020-07-28 09:02:26 +00:00
|
|
|
this.fileLoaded = true;
|
2020-07-16 10:02:52 +00:00
|
|
|
}
|
2020-07-14 15:03:14 +00:00
|
|
|
|
2020-08-12 15:10:23 +00:00
|
|
|
refreshTimelineTrackView() {
|
2020-10-19 10:45:42 +00:00
|
|
|
this._view.mapTrack.data = this._state.mapTimeline;
|
|
|
|
this._view.icTrack.data = this._state.icTimeline;
|
2020-08-05 04:13:01 +00:00
|
|
|
}
|
|
|
|
|
2020-07-28 09:02:26 +00:00
|
|
|
switchTheme(event) {
|
2020-08-12 15:10:23 +00:00
|
|
|
document.documentElement.dataset.theme = event.target.checked
|
|
|
|
? "light"
|
|
|
|
: "dark";
|
|
|
|
if (this.fileLoaded) {
|
2020-08-05 04:13:01 +00:00
|
|
|
this.refreshTimelineTrackView();
|
|
|
|
}
|
2020-07-28 09:02:26 +00:00
|
|
|
}
|
2020-07-15 07:28:00 +00:00
|
|
|
}
|
|
|
|
|
2020-08-13 07:35:23 +00:00
|
|
|
class Navigation {
|
2020-10-19 10:45:42 +00:00
|
|
|
_view;
|
2020-08-13 07:35:23 +00:00
|
|
|
constructor(state, view) {
|
|
|
|
this.state = state;
|
2020-10-19 10:45:42 +00:00
|
|
|
this._view = view;
|
2020-08-13 07:35:23 +00:00
|
|
|
}
|
|
|
|
get map() {
|
|
|
|
return this.state.map
|
|
|
|
}
|
|
|
|
set map(value) {
|
|
|
|
this.state.map = value
|
|
|
|
}
|
|
|
|
get chunks() {
|
|
|
|
return this.state.chunks
|
|
|
|
}
|
|
|
|
increaseTimelineResolution() {
|
2020-10-19 10:45:42 +00:00
|
|
|
this._view.timelinePanel.nofChunks *= 1.5;
|
2020-08-13 07:35:23 +00:00
|
|
|
this.state.nofChunks *= 1.5;
|
|
|
|
}
|
|
|
|
decreaseTimelineResolution() {
|
2020-10-19 10:45:42 +00:00
|
|
|
this._view.timelinePanel.nofChunks /= 1.5;
|
2020-08-13 07:35:23 +00:00
|
|
|
this.state.nofChunks /= 1.5;
|
|
|
|
}
|
|
|
|
selectNextEdge() {
|
|
|
|
if (!this.map) return;
|
|
|
|
if (this.map.children.length != 1) return;
|
|
|
|
this.map = this.map.children[0].to;
|
2020-10-19 10:45:42 +00:00
|
|
|
this._view.mapTrack.selectedEntry = this.map;
|
2020-08-13 07:35:23 +00:00
|
|
|
this.updateUrl();
|
2020-10-19 10:45:42 +00:00
|
|
|
this._view.mapPanel.map = this.map;
|
2020-08-13 07:35:23 +00:00
|
|
|
}
|
|
|
|
selectPrevEdge() {
|
|
|
|
if (!this.map) return;
|
|
|
|
if (!this.map.parent()) return;
|
|
|
|
this.map = this.map.parent();
|
2020-10-19 10:45:42 +00:00
|
|
|
this._view.mapTrack.selectedEntry = this.map;
|
2020-08-13 07:35:23 +00:00
|
|
|
this.updateUrl();
|
2020-10-19 10:45:42 +00:00
|
|
|
this._view.mapPanel.map = this.map;
|
2020-08-13 07:35:23 +00:00
|
|
|
}
|
|
|
|
selectDefaultMap() {
|
|
|
|
this.map = this.chunks[0].at(0);
|
2020-10-19 10:45:42 +00:00
|
|
|
this._view.mapTrack.selectedEntry = this.map;
|
2020-08-13 07:35:23 +00:00
|
|
|
this.updateUrl();
|
2020-10-19 10:45:42 +00:00
|
|
|
this._view.mapPanel.map = this.map;
|
2020-08-13 07:35:23 +00:00
|
|
|
}
|
|
|
|
moveInChunks(next) {
|
|
|
|
if (!this.map) return this.selectDefaultMap();
|
|
|
|
let chunkIndex = this.map.chunkIndex(this.chunks);
|
|
|
|
let chunk = this.chunks[chunkIndex];
|
|
|
|
let index = chunk.indexOf(this.map);
|
|
|
|
if (next) {
|
|
|
|
chunk = chunk.next(this.chunks);
|
|
|
|
} else {
|
|
|
|
chunk = chunk.prev(this.chunks);
|
|
|
|
}
|
|
|
|
if (!chunk) return;
|
|
|
|
index = Math.min(index, chunk.size() - 1);
|
|
|
|
this.map = chunk.at(index);
|
2020-10-19 10:45:42 +00:00
|
|
|
this._view.mapTrack.selectedEntry = this.map;
|
2020-08-13 07:35:23 +00:00
|
|
|
this.updateUrl();
|
2020-10-19 10:45:42 +00:00
|
|
|
this._view.mapPanel.map = this.map;
|
2020-08-13 07:35:23 +00:00
|
|
|
}
|
|
|
|
moveInChunk(delta) {
|
|
|
|
if (!this.map) return this.selectDefaultMap();
|
|
|
|
let chunkIndex = this.map.chunkIndex(this.chunks)
|
|
|
|
let chunk = this.chunks[chunkIndex];
|
|
|
|
let index = chunk.indexOf(this.map) + delta;
|
|
|
|
let map;
|
|
|
|
if (index < 0) {
|
|
|
|
map = chunk.prev(this.chunks).last();
|
|
|
|
} else if (index >= chunk.size()) {
|
|
|
|
map = chunk.next(this.chunks).first()
|
|
|
|
} else {
|
|
|
|
map = chunk.at(index);
|
|
|
|
}
|
|
|
|
this.map = map;
|
2020-10-19 10:45:42 +00:00
|
|
|
this._view.mapTrack.selectedEntry = this.map;
|
2020-08-13 07:35:23 +00:00
|
|
|
this.updateUrl();
|
2020-10-19 10:45:42 +00:00
|
|
|
this._view.mapPanel.map = this.map;
|
2020-08-13 07:35:23 +00:00
|
|
|
}
|
|
|
|
updateUrl() {
|
|
|
|
let entries = this.state.entries;
|
|
|
|
let params = new URLSearchParams(entries);
|
|
|
|
window.history.pushState(entries, '', '?' + params.toString());
|
|
|
|
}
|
|
|
|
handleKeyDown(event) {
|
|
|
|
switch (event.key) {
|
|
|
|
case "ArrowUp":
|
|
|
|
event.preventDefault();
|
|
|
|
if (event.shiftKey) {
|
|
|
|
this.selectPrevEdge();
|
|
|
|
} else {
|
|
|
|
this.moveInChunk(-1);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
case "ArrowDown":
|
|
|
|
event.preventDefault();
|
|
|
|
if (event.shiftKey) {
|
|
|
|
this.selectNextEdge();
|
|
|
|
} else {
|
|
|
|
this.moveInChunk(1);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
case "ArrowLeft":
|
|
|
|
this.moveInChunks(false);
|
|
|
|
break;
|
|
|
|
case "ArrowRight":
|
|
|
|
this.moveInChunks(true);
|
|
|
|
break;
|
|
|
|
case "+":
|
|
|
|
this.increaseTimelineResolution();
|
|
|
|
break;
|
|
|
|
case "-":
|
|
|
|
this.decreaseTimelineResolution();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-12 15:10:23 +00:00
|
|
|
export { App };
|