11cb0ef41Sopenharmony_ci// Copyright 2020 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ciimport {Script, SourcePosition} from '../profile.mjs';
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciimport {State} from './app-model.mjs';
81cb0ef41Sopenharmony_ciimport {CodeLogEntry} from './log/code.mjs';
91cb0ef41Sopenharmony_ciimport {DeoptLogEntry} from './log/code.mjs';
101cb0ef41Sopenharmony_ciimport {SharedLibLogEntry} from './log/code.mjs';
111cb0ef41Sopenharmony_ciimport {IcLogEntry} from './log/ic.mjs';
121cb0ef41Sopenharmony_ciimport {LogEntry} from './log/log.mjs';
131cb0ef41Sopenharmony_ciimport {MapLogEntry} from './log/map.mjs';
141cb0ef41Sopenharmony_ciimport {TickLogEntry} from './log/tick.mjs';
151cb0ef41Sopenharmony_ciimport {TimerLogEntry} from './log/timer.mjs';
161cb0ef41Sopenharmony_ciimport {Processor} from './processor.mjs';
171cb0ef41Sopenharmony_ciimport {FocusEvent, SelectionEvent, SelectRelatedEvent, SelectTimeEvent, ToolTipEvent,} from './view/events.mjs';
181cb0ef41Sopenharmony_ciimport {$, groupBy} from './view/helper.mjs';
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ciclass App {
211cb0ef41Sopenharmony_ci  _state;
221cb0ef41Sopenharmony_ci  _view;
231cb0ef41Sopenharmony_ci  _navigation;
241cb0ef41Sopenharmony_ci  _startupPromise;
251cb0ef41Sopenharmony_ci  constructor() {
261cb0ef41Sopenharmony_ci    this._view = {
271cb0ef41Sopenharmony_ci      __proto__: null,
281cb0ef41Sopenharmony_ci      logFileReader: $('#log-file-reader'),
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_ci      timelinePanel: $('#timeline-panel'),
311cb0ef41Sopenharmony_ci      tickTrack: $('#tick-track'),
321cb0ef41Sopenharmony_ci      mapTrack: $('#map-track'),
331cb0ef41Sopenharmony_ci      icTrack: $('#ic-track'),
341cb0ef41Sopenharmony_ci      deoptTrack: $('#deopt-track'),
351cb0ef41Sopenharmony_ci      codeTrack: $('#code-track'),
361cb0ef41Sopenharmony_ci      timerTrack: $('#timer-track'),
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ci      icList: $('#ic-list'),
391cb0ef41Sopenharmony_ci      mapList: $('#map-list'),
401cb0ef41Sopenharmony_ci      codeList: $('#code-list'),
411cb0ef41Sopenharmony_ci      deoptList: $('#deopt-list'),
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_ci      mapPanel: $('#map-panel'),
441cb0ef41Sopenharmony_ci      codePanel: $('#code-panel'),
451cb0ef41Sopenharmony_ci      scriptPanel: $('#script-panel'),
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_ci      toolTip: $('#tool-tip'),
481cb0ef41Sopenharmony_ci    };
491cb0ef41Sopenharmony_ci    this._view.logFileReader.addEventListener(
501cb0ef41Sopenharmony_ci        'fileuploadstart', this.handleFileUploadStart.bind(this));
511cb0ef41Sopenharmony_ci    this._view.logFileReader.addEventListener(
521cb0ef41Sopenharmony_ci        'fileuploadchunk', this.handleFileUploadChunk.bind(this));
531cb0ef41Sopenharmony_ci    this._view.logFileReader.addEventListener(
541cb0ef41Sopenharmony_ci        'fileuploadend', this.handleFileUploadEnd.bind(this));
551cb0ef41Sopenharmony_ci    this._startupPromise = this._loadCustomElements();
561cb0ef41Sopenharmony_ci    this._view.codeTrack.svg = true;
571cb0ef41Sopenharmony_ci  }
581cb0ef41Sopenharmony_ci
591cb0ef41Sopenharmony_ci  static get allEventTypes() {
601cb0ef41Sopenharmony_ci    return new Set([
611cb0ef41Sopenharmony_ci      SourcePosition,
621cb0ef41Sopenharmony_ci      MapLogEntry,
631cb0ef41Sopenharmony_ci      IcLogEntry,
641cb0ef41Sopenharmony_ci      CodeLogEntry,
651cb0ef41Sopenharmony_ci      DeoptLogEntry,
661cb0ef41Sopenharmony_ci      SharedLibLogEntry,
671cb0ef41Sopenharmony_ci      TickLogEntry,
681cb0ef41Sopenharmony_ci      TimerLogEntry,
691cb0ef41Sopenharmony_ci    ]);
701cb0ef41Sopenharmony_ci  }
711cb0ef41Sopenharmony_ci
721cb0ef41Sopenharmony_ci  async _loadCustomElements() {
731cb0ef41Sopenharmony_ci    await Promise.all([
741cb0ef41Sopenharmony_ci      import('./view/list-panel.mjs'),
751cb0ef41Sopenharmony_ci      import('./view/timeline-panel.mjs'),
761cb0ef41Sopenharmony_ci      import('./view/map-panel.mjs'),
771cb0ef41Sopenharmony_ci      import('./view/script-panel.mjs'),
781cb0ef41Sopenharmony_ci      import('./view/code-panel.mjs'),
791cb0ef41Sopenharmony_ci      import('./view/property-link-table.mjs'),
801cb0ef41Sopenharmony_ci      import('./view/tool-tip.mjs'),
811cb0ef41Sopenharmony_ci    ]);
821cb0ef41Sopenharmony_ci    this._addEventListeners();
831cb0ef41Sopenharmony_ci  }
841cb0ef41Sopenharmony_ci
851cb0ef41Sopenharmony_ci  _addEventListeners() {
861cb0ef41Sopenharmony_ci    document.addEventListener(
871cb0ef41Sopenharmony_ci        'keydown', e => this._navigation?.handleKeyDown(e));
881cb0ef41Sopenharmony_ci    document.addEventListener(
891cb0ef41Sopenharmony_ci        SelectRelatedEvent.name, this.handleSelectRelatedEntries.bind(this));
901cb0ef41Sopenharmony_ci    document.addEventListener(
911cb0ef41Sopenharmony_ci        SelectionEvent.name, this.handleSelectEntries.bind(this))
921cb0ef41Sopenharmony_ci    document.addEventListener(
931cb0ef41Sopenharmony_ci        FocusEvent.name, this.handleFocusLogEntry.bind(this));
941cb0ef41Sopenharmony_ci    document.addEventListener(
951cb0ef41Sopenharmony_ci        SelectTimeEvent.name, this.handleTimeRangeSelect.bind(this));
961cb0ef41Sopenharmony_ci    document.addEventListener(ToolTipEvent.name, this.handleToolTip.bind(this));
971cb0ef41Sopenharmony_ci  }
981cb0ef41Sopenharmony_ci
991cb0ef41Sopenharmony_ci  handleSelectRelatedEntries(e) {
1001cb0ef41Sopenharmony_ci    e.stopImmediatePropagation();
1011cb0ef41Sopenharmony_ci    this.selectRelatedEntries(e.entry);
1021cb0ef41Sopenharmony_ci  }
1031cb0ef41Sopenharmony_ci
1041cb0ef41Sopenharmony_ci  selectRelatedEntries(entry) {
1051cb0ef41Sopenharmony_ci    let entries = [entry];
1061cb0ef41Sopenharmony_ci    switch (entry.constructor) {
1071cb0ef41Sopenharmony_ci      case SourcePosition:
1081cb0ef41Sopenharmony_ci        entries = entries.concat(entry.entries);
1091cb0ef41Sopenharmony_ci        break;
1101cb0ef41Sopenharmony_ci      case MapLogEntry:
1111cb0ef41Sopenharmony_ci        entries = this._state.icTimeline.filter(each => each.map === entry);
1121cb0ef41Sopenharmony_ci        break;
1131cb0ef41Sopenharmony_ci      case IcLogEntry:
1141cb0ef41Sopenharmony_ci        if (entry.map) entries.push(entry.map);
1151cb0ef41Sopenharmony_ci        break;
1161cb0ef41Sopenharmony_ci      case DeoptLogEntry:
1171cb0ef41Sopenharmony_ci        // TODO select map + code entries
1181cb0ef41Sopenharmony_ci        if (entry.fileSourcePosition) entries.push(entry.fileSourcePosition);
1191cb0ef41Sopenharmony_ci        break;
1201cb0ef41Sopenharmony_ci      case Script:
1211cb0ef41Sopenharmony_ci        entries = entry.entries.concat(entry.sourcePositions);
1221cb0ef41Sopenharmony_ci        break;
1231cb0ef41Sopenharmony_ci      case TimerLogEntry:
1241cb0ef41Sopenharmony_ci      case CodeLogEntry:
1251cb0ef41Sopenharmony_ci      case TickLogEntry:
1261cb0ef41Sopenharmony_ci      case SharedLibLogEntry:
1271cb0ef41Sopenharmony_ci        break;
1281cb0ef41Sopenharmony_ci      default:
1291cb0ef41Sopenharmony_ci        throw new Error(`Unknown selection type: ${entry.constructor?.name}`);
1301cb0ef41Sopenharmony_ci    }
1311cb0ef41Sopenharmony_ci    if (entry.sourcePosition) {
1321cb0ef41Sopenharmony_ci      entries.push(entry.sourcePosition);
1331cb0ef41Sopenharmony_ci      // TODO: find the matching Code log entries.
1341cb0ef41Sopenharmony_ci    }
1351cb0ef41Sopenharmony_ci    this.selectEntries(entries);
1361cb0ef41Sopenharmony_ci  }
1371cb0ef41Sopenharmony_ci
1381cb0ef41Sopenharmony_ci  static isClickable(object) {
1391cb0ef41Sopenharmony_ci    if (typeof object !== 'object') return false;
1401cb0ef41Sopenharmony_ci    if (object instanceof LogEntry) return true;
1411cb0ef41Sopenharmony_ci    if (object instanceof SourcePosition) return true;
1421cb0ef41Sopenharmony_ci    if (object instanceof Script) return true;
1431cb0ef41Sopenharmony_ci    return false;
1441cb0ef41Sopenharmony_ci  }
1451cb0ef41Sopenharmony_ci
1461cb0ef41Sopenharmony_ci  handleSelectEntries(e) {
1471cb0ef41Sopenharmony_ci    e.stopImmediatePropagation();
1481cb0ef41Sopenharmony_ci    this.selectEntries(e.entries);
1491cb0ef41Sopenharmony_ci  }
1501cb0ef41Sopenharmony_ci
1511cb0ef41Sopenharmony_ci  selectEntries(entries) {
1521cb0ef41Sopenharmony_ci    const missingTypes = App.allEventTypes;
1531cb0ef41Sopenharmony_ci    groupBy(entries, each => each.constructor, true).forEach(group => {
1541cb0ef41Sopenharmony_ci      this.selectEntriesOfSingleType(group.entries);
1551cb0ef41Sopenharmony_ci      missingTypes.delete(group.key);
1561cb0ef41Sopenharmony_ci    });
1571cb0ef41Sopenharmony_ci    missingTypes.forEach(
1581cb0ef41Sopenharmony_ci        type => this.selectEntriesOfSingleType([], type, false));
1591cb0ef41Sopenharmony_ci  }
1601cb0ef41Sopenharmony_ci
1611cb0ef41Sopenharmony_ci  selectEntriesOfSingleType(entries, type, focusView = true) {
1621cb0ef41Sopenharmony_ci    const entryType = entries[0]?.constructor ?? type;
1631cb0ef41Sopenharmony_ci    switch (entryType) {
1641cb0ef41Sopenharmony_ci      case Script:
1651cb0ef41Sopenharmony_ci        entries = entries.flatMap(script => script.sourcePositions);
1661cb0ef41Sopenharmony_ci        return this.showSourcePositions(entries, focusView);
1671cb0ef41Sopenharmony_ci      case SourcePosition:
1681cb0ef41Sopenharmony_ci        return this.showSourcePositions(entries, focusView);
1691cb0ef41Sopenharmony_ci      case MapLogEntry:
1701cb0ef41Sopenharmony_ci        return this.showMapEntries(entries, focusView);
1711cb0ef41Sopenharmony_ci      case IcLogEntry:
1721cb0ef41Sopenharmony_ci        return this.showIcEntries(entries, focusView);
1731cb0ef41Sopenharmony_ci      case CodeLogEntry:
1741cb0ef41Sopenharmony_ci        return this.showCodeEntries(entries, focusView);
1751cb0ef41Sopenharmony_ci      case DeoptLogEntry:
1761cb0ef41Sopenharmony_ci        return this.showDeoptEntries(entries, focusView);
1771cb0ef41Sopenharmony_ci      case SharedLibLogEntry:
1781cb0ef41Sopenharmony_ci        return this.showSharedLibEntries(entries, focusView);
1791cb0ef41Sopenharmony_ci      case TimerLogEntry:
1801cb0ef41Sopenharmony_ci      case TickLogEntry:
1811cb0ef41Sopenharmony_ci        break;
1821cb0ef41Sopenharmony_ci      default:
1831cb0ef41Sopenharmony_ci        throw new Error(`Unknown selection type: ${entryType?.name}`);
1841cb0ef41Sopenharmony_ci    }
1851cb0ef41Sopenharmony_ci  }
1861cb0ef41Sopenharmony_ci
1871cb0ef41Sopenharmony_ci  showMapEntries(entries, focusView = true) {
1881cb0ef41Sopenharmony_ci    this._view.mapPanel.selectedLogEntries = entries;
1891cb0ef41Sopenharmony_ci    this._view.mapList.selectedLogEntries = entries;
1901cb0ef41Sopenharmony_ci    if (focusView) this._view.mapPanel.show();
1911cb0ef41Sopenharmony_ci  }
1921cb0ef41Sopenharmony_ci
1931cb0ef41Sopenharmony_ci  showIcEntries(entries, focusView = true) {
1941cb0ef41Sopenharmony_ci    this._view.icList.selectedLogEntries = entries;
1951cb0ef41Sopenharmony_ci    if (focusView) this._view.icList.show();
1961cb0ef41Sopenharmony_ci  }
1971cb0ef41Sopenharmony_ci
1981cb0ef41Sopenharmony_ci  showDeoptEntries(entries, focusView = true) {
1991cb0ef41Sopenharmony_ci    this._view.deoptList.selectedLogEntries = entries;
2001cb0ef41Sopenharmony_ci    if (focusView) this._view.deoptList.show();
2011cb0ef41Sopenharmony_ci  }
2021cb0ef41Sopenharmony_ci
2031cb0ef41Sopenharmony_ci  showSharedLibEntries(entries, focusView = true) {}
2041cb0ef41Sopenharmony_ci
2051cb0ef41Sopenharmony_ci  showCodeEntries(entries, focusView = true) {
2061cb0ef41Sopenharmony_ci    this._view.codePanel.selectedEntries = entries;
2071cb0ef41Sopenharmony_ci    this._view.codeList.selectedLogEntries = entries;
2081cb0ef41Sopenharmony_ci    if (focusView) this._view.codePanel.show();
2091cb0ef41Sopenharmony_ci  }
2101cb0ef41Sopenharmony_ci
2111cb0ef41Sopenharmony_ci  showTickEntries(entries, focusView = true) {}
2121cb0ef41Sopenharmony_ci  showTimerEntries(entries, focusView = true) {}
2131cb0ef41Sopenharmony_ci
2141cb0ef41Sopenharmony_ci  showSourcePositions(entries, focusView = true) {
2151cb0ef41Sopenharmony_ci    this._view.scriptPanel.selectedSourcePositions = entries
2161cb0ef41Sopenharmony_ci    if (focusView) this._view.scriptPanel.show();
2171cb0ef41Sopenharmony_ci  }
2181cb0ef41Sopenharmony_ci
2191cb0ef41Sopenharmony_ci  handleTimeRangeSelect(e) {
2201cb0ef41Sopenharmony_ci    e.stopImmediatePropagation();
2211cb0ef41Sopenharmony_ci    this.selectTimeRange(e.start, e.end, e.focus, e.zoom);
2221cb0ef41Sopenharmony_ci  }
2231cb0ef41Sopenharmony_ci
2241cb0ef41Sopenharmony_ci  selectTimeRange(start, end, focus = false, zoom = false) {
2251cb0ef41Sopenharmony_ci    this._state.selectTimeRange(start, end);
2261cb0ef41Sopenharmony_ci    this.showMapEntries(this._state.mapTimeline.selectionOrSelf, false);
2271cb0ef41Sopenharmony_ci    this.showIcEntries(this._state.icTimeline.selectionOrSelf, false);
2281cb0ef41Sopenharmony_ci    this.showDeoptEntries(this._state.deoptTimeline.selectionOrSelf, false);
2291cb0ef41Sopenharmony_ci    this.showCodeEntries(this._state.codeTimeline.selectionOrSelf, false);
2301cb0ef41Sopenharmony_ci    this.showTickEntries(this._state.tickTimeline.selectionOrSelf, false);
2311cb0ef41Sopenharmony_ci    this.showTimerEntries(this._state.timerTimeline.selectionOrSelf, false);
2321cb0ef41Sopenharmony_ci    this._view.timelinePanel.timeSelection = {start, end, focus, zoom};
2331cb0ef41Sopenharmony_ci  }
2341cb0ef41Sopenharmony_ci
2351cb0ef41Sopenharmony_ci  handleFocusLogEntry(e) {
2361cb0ef41Sopenharmony_ci    e.stopImmediatePropagation();
2371cb0ef41Sopenharmony_ci    this.focusLogEntry(e.entry);
2381cb0ef41Sopenharmony_ci  }
2391cb0ef41Sopenharmony_ci
2401cb0ef41Sopenharmony_ci  focusLogEntry(entry) {
2411cb0ef41Sopenharmony_ci    switch (entry.constructor) {
2421cb0ef41Sopenharmony_ci      case Script:
2431cb0ef41Sopenharmony_ci        return this.focusSourcePosition(entry.sourcePositions[0]);
2441cb0ef41Sopenharmony_ci      case SourcePosition:
2451cb0ef41Sopenharmony_ci        return this.focusSourcePosition(entry);
2461cb0ef41Sopenharmony_ci      case MapLogEntry:
2471cb0ef41Sopenharmony_ci        return this.focusMapLogEntry(entry);
2481cb0ef41Sopenharmony_ci      case IcLogEntry:
2491cb0ef41Sopenharmony_ci        return this.focusIcLogEntry(entry);
2501cb0ef41Sopenharmony_ci      case CodeLogEntry:
2511cb0ef41Sopenharmony_ci        return this.focusCodeLogEntry(entry);
2521cb0ef41Sopenharmony_ci      case DeoptLogEntry:
2531cb0ef41Sopenharmony_ci        return this.focusDeoptLogEntry(entry);
2541cb0ef41Sopenharmony_ci      case SharedLibLogEntry:
2551cb0ef41Sopenharmony_ci        return this.focusDeoptLogEntry(entry);
2561cb0ef41Sopenharmony_ci      case TickLogEntry:
2571cb0ef41Sopenharmony_ci        return this.focusTickLogEntry(entry);
2581cb0ef41Sopenharmony_ci      case TimerLogEntry:
2591cb0ef41Sopenharmony_ci        return this.focusTimerLogEntry(entry);
2601cb0ef41Sopenharmony_ci      default:
2611cb0ef41Sopenharmony_ci        throw new Error(`Unknown selection type: ${entry.constructor?.name}`);
2621cb0ef41Sopenharmony_ci    }
2631cb0ef41Sopenharmony_ci  }
2641cb0ef41Sopenharmony_ci
2651cb0ef41Sopenharmony_ci  focusMapLogEntry(entry, focusSourcePosition = true) {
2661cb0ef41Sopenharmony_ci    this._state.map = entry;
2671cb0ef41Sopenharmony_ci    this._view.mapTrack.focusedEntry = entry;
2681cb0ef41Sopenharmony_ci    this._view.mapPanel.map = entry;
2691cb0ef41Sopenharmony_ci    if (focusSourcePosition) {
2701cb0ef41Sopenharmony_ci      this.focusCodeLogEntry(entry.code, false);
2711cb0ef41Sopenharmony_ci      this.focusSourcePosition(entry.sourcePosition);
2721cb0ef41Sopenharmony_ci    }
2731cb0ef41Sopenharmony_ci    this._view.mapPanel.show();
2741cb0ef41Sopenharmony_ci  }
2751cb0ef41Sopenharmony_ci
2761cb0ef41Sopenharmony_ci  focusIcLogEntry(entry) {
2771cb0ef41Sopenharmony_ci    this._state.ic = entry;
2781cb0ef41Sopenharmony_ci    this.focusMapLogEntry(entry.map, false);
2791cb0ef41Sopenharmony_ci    this.focusCodeLogEntry(entry.code, false);
2801cb0ef41Sopenharmony_ci    this.focusSourcePosition(entry.sourcePosition);
2811cb0ef41Sopenharmony_ci  }
2821cb0ef41Sopenharmony_ci
2831cb0ef41Sopenharmony_ci  focusCodeLogEntry(entry, focusSourcePosition = true) {
2841cb0ef41Sopenharmony_ci    this._state.code = entry;
2851cb0ef41Sopenharmony_ci    this._view.codePanel.entry = entry;
2861cb0ef41Sopenharmony_ci    if (focusSourcePosition) this.focusSourcePosition(entry.sourcePosition);
2871cb0ef41Sopenharmony_ci    this._view.codePanel.show();
2881cb0ef41Sopenharmony_ci  }
2891cb0ef41Sopenharmony_ci
2901cb0ef41Sopenharmony_ci  focusDeoptLogEntry(entry) {
2911cb0ef41Sopenharmony_ci    this._state.deoptLogEntry = entry;
2921cb0ef41Sopenharmony_ci    this.focusCodeLogEntry(entry.code, false);
2931cb0ef41Sopenharmony_ci    this.focusSourcePosition(entry.sourcePosition);
2941cb0ef41Sopenharmony_ci  }
2951cb0ef41Sopenharmony_ci
2961cb0ef41Sopenharmony_ci  focusSharedLibLogEntry(entry) {
2971cb0ef41Sopenharmony_ci    // no-op.
2981cb0ef41Sopenharmony_ci  }
2991cb0ef41Sopenharmony_ci
3001cb0ef41Sopenharmony_ci  focusTickLogEntry(entry) {
3011cb0ef41Sopenharmony_ci    this._state.tickLogEntry = entry;
3021cb0ef41Sopenharmony_ci    this._view.tickTrack.focusedEntry = entry;
3031cb0ef41Sopenharmony_ci  }
3041cb0ef41Sopenharmony_ci
3051cb0ef41Sopenharmony_ci  focusTimerLogEntry(entry) {
3061cb0ef41Sopenharmony_ci    this._state.timerLogEntry = entry;
3071cb0ef41Sopenharmony_ci    this._view.timerTrack.focusedEntry = entry;
3081cb0ef41Sopenharmony_ci  }
3091cb0ef41Sopenharmony_ci
3101cb0ef41Sopenharmony_ci  focusSourcePosition(sourcePosition) {
3111cb0ef41Sopenharmony_ci    if (!sourcePosition) return;
3121cb0ef41Sopenharmony_ci    this._view.scriptPanel.focusedSourcePositions = [sourcePosition];
3131cb0ef41Sopenharmony_ci    this._view.scriptPanel.show();
3141cb0ef41Sopenharmony_ci  }
3151cb0ef41Sopenharmony_ci
3161cb0ef41Sopenharmony_ci  handleToolTip(event) {
3171cb0ef41Sopenharmony_ci    let content = event.content;
3181cb0ef41Sopenharmony_ci    if (typeof content !== 'string' &&
3191cb0ef41Sopenharmony_ci        !(content?.nodeType && content?.nodeName)) {
3201cb0ef41Sopenharmony_ci      content = content?.toolTipDict;
3211cb0ef41Sopenharmony_ci    }
3221cb0ef41Sopenharmony_ci    if (!content) {
3231cb0ef41Sopenharmony_ci      throw new Error(
3241cb0ef41Sopenharmony_ci          `Unknown tooltip content type: ${content.constructor?.name}`);
3251cb0ef41Sopenharmony_ci    }
3261cb0ef41Sopenharmony_ci    this.setToolTip(content, event.positionOrTargetNode);
3271cb0ef41Sopenharmony_ci  }
3281cb0ef41Sopenharmony_ci
3291cb0ef41Sopenharmony_ci  setToolTip(content, positionOrTargetNode) {
3301cb0ef41Sopenharmony_ci    this._view.toolTip.positionOrTargetNode = positionOrTargetNode;
3311cb0ef41Sopenharmony_ci    this._view.toolTip.content = content;
3321cb0ef41Sopenharmony_ci  }
3331cb0ef41Sopenharmony_ci
3341cb0ef41Sopenharmony_ci  restartApp() {
3351cb0ef41Sopenharmony_ci    this._state = new State();
3361cb0ef41Sopenharmony_ci    this._navigation = new Navigation(this._state, this._view);
3371cb0ef41Sopenharmony_ci  }
3381cb0ef41Sopenharmony_ci
3391cb0ef41Sopenharmony_ci  handleFileUploadStart(e) {
3401cb0ef41Sopenharmony_ci    this.restartApp();
3411cb0ef41Sopenharmony_ci    $('#container').className = 'initial';
3421cb0ef41Sopenharmony_ci    this._processor = new Processor();
3431cb0ef41Sopenharmony_ci    this._processor.setProgressCallback(
3441cb0ef41Sopenharmony_ci        e.detail.totalSize, e.detail.progressCallback);
3451cb0ef41Sopenharmony_ci  }
3461cb0ef41Sopenharmony_ci
3471cb0ef41Sopenharmony_ci  async handleFileUploadChunk(e) {
3481cb0ef41Sopenharmony_ci    this._processor.processChunk(e.detail);
3491cb0ef41Sopenharmony_ci  }
3501cb0ef41Sopenharmony_ci
3511cb0ef41Sopenharmony_ci  async handleFileUploadEnd(e) {
3521cb0ef41Sopenharmony_ci    try {
3531cb0ef41Sopenharmony_ci      const processor = this._processor;
3541cb0ef41Sopenharmony_ci      await processor.finalize();
3551cb0ef41Sopenharmony_ci      await this._startupPromise;
3561cb0ef41Sopenharmony_ci
3571cb0ef41Sopenharmony_ci      this._state.profile = processor.profile;
3581cb0ef41Sopenharmony_ci      const mapTimeline = processor.mapTimeline;
3591cb0ef41Sopenharmony_ci      const icTimeline = processor.icTimeline;
3601cb0ef41Sopenharmony_ci      const deoptTimeline = processor.deoptTimeline;
3611cb0ef41Sopenharmony_ci      const codeTimeline = processor.codeTimeline;
3621cb0ef41Sopenharmony_ci      const tickTimeline = processor.tickTimeline;
3631cb0ef41Sopenharmony_ci      const timerTimeline = processor.timerTimeline;
3641cb0ef41Sopenharmony_ci      this._state.setTimelines(
3651cb0ef41Sopenharmony_ci          mapTimeline, icTimeline, deoptTimeline, codeTimeline, tickTimeline,
3661cb0ef41Sopenharmony_ci          timerTimeline);
3671cb0ef41Sopenharmony_ci      this._view.mapPanel.timeline = mapTimeline;
3681cb0ef41Sopenharmony_ci      this._view.icList.timeline = icTimeline;
3691cb0ef41Sopenharmony_ci      this._view.mapList.timeline = mapTimeline;
3701cb0ef41Sopenharmony_ci      this._view.deoptList.timeline = deoptTimeline;
3711cb0ef41Sopenharmony_ci      this._view.codeList.timeline = codeTimeline;
3721cb0ef41Sopenharmony_ci      this._view.scriptPanel.scripts = processor.scripts;
3731cb0ef41Sopenharmony_ci      this._view.codePanel.timeline = codeTimeline;
3741cb0ef41Sopenharmony_ci      this._view.codePanel.timeline = codeTimeline;
3751cb0ef41Sopenharmony_ci      this.refreshTimelineTrackView();
3761cb0ef41Sopenharmony_ci    } catch (e) {
3771cb0ef41Sopenharmony_ci      this._view.logFileReader.error = 'Log file contains errors!'
3781cb0ef41Sopenharmony_ci      throw (e);
3791cb0ef41Sopenharmony_ci    } finally {
3801cb0ef41Sopenharmony_ci      $('#container').className = 'loaded';
3811cb0ef41Sopenharmony_ci      this.fileLoaded = true;
3821cb0ef41Sopenharmony_ci    }
3831cb0ef41Sopenharmony_ci  }
3841cb0ef41Sopenharmony_ci
3851cb0ef41Sopenharmony_ci  refreshTimelineTrackView() {
3861cb0ef41Sopenharmony_ci    this._view.mapTrack.data = this._state.mapTimeline;
3871cb0ef41Sopenharmony_ci    this._view.icTrack.data = this._state.icTimeline;
3881cb0ef41Sopenharmony_ci    this._view.deoptTrack.data = this._state.deoptTimeline;
3891cb0ef41Sopenharmony_ci    this._view.codeTrack.data = this._state.codeTimeline;
3901cb0ef41Sopenharmony_ci    this._view.tickTrack.data = this._state.tickTimeline;
3911cb0ef41Sopenharmony_ci    this._view.timerTrack.data = this._state.timerTimeline;
3921cb0ef41Sopenharmony_ci  }
3931cb0ef41Sopenharmony_ci}
3941cb0ef41Sopenharmony_ci
3951cb0ef41Sopenharmony_ciclass Navigation {
3961cb0ef41Sopenharmony_ci  _view;
3971cb0ef41Sopenharmony_ci  constructor(state, view) {
3981cb0ef41Sopenharmony_ci    this.state = state;
3991cb0ef41Sopenharmony_ci    this._view = view;
4001cb0ef41Sopenharmony_ci  }
4011cb0ef41Sopenharmony_ci
4021cb0ef41Sopenharmony_ci  get map() {
4031cb0ef41Sopenharmony_ci    return this.state.map
4041cb0ef41Sopenharmony_ci  }
4051cb0ef41Sopenharmony_ci
4061cb0ef41Sopenharmony_ci  set map(value) {
4071cb0ef41Sopenharmony_ci    this.state.map = value
4081cb0ef41Sopenharmony_ci  }
4091cb0ef41Sopenharmony_ci
4101cb0ef41Sopenharmony_ci  get chunks() {
4111cb0ef41Sopenharmony_ci    return this.state.mapTimeline.chunks;
4121cb0ef41Sopenharmony_ci  }
4131cb0ef41Sopenharmony_ci
4141cb0ef41Sopenharmony_ci  increaseTimelineResolution() {
4151cb0ef41Sopenharmony_ci    this._view.timelinePanel.nofChunks *= 1.5;
4161cb0ef41Sopenharmony_ci    this.state.nofChunks *= 1.5;
4171cb0ef41Sopenharmony_ci  }
4181cb0ef41Sopenharmony_ci
4191cb0ef41Sopenharmony_ci  decreaseTimelineResolution() {
4201cb0ef41Sopenharmony_ci    this._view.timelinePanel.nofChunks /= 1.5;
4211cb0ef41Sopenharmony_ci    this.state.nofChunks /= 1.5;
4221cb0ef41Sopenharmony_ci  }
4231cb0ef41Sopenharmony_ci
4241cb0ef41Sopenharmony_ci  updateUrl() {
4251cb0ef41Sopenharmony_ci    let entries = this.state.entries;
4261cb0ef41Sopenharmony_ci    let params = new URLSearchParams(entries);
4271cb0ef41Sopenharmony_ci    window.history.pushState(entries, '', '?' + params.toString());
4281cb0ef41Sopenharmony_ci  }
4291cb0ef41Sopenharmony_ci
4301cb0ef41Sopenharmony_ci  scrollLeft() {}
4311cb0ef41Sopenharmony_ci
4321cb0ef41Sopenharmony_ci  scrollRight() {}
4331cb0ef41Sopenharmony_ci
4341cb0ef41Sopenharmony_ci  handleKeyDown(event) {
4351cb0ef41Sopenharmony_ci    switch (event.key) {
4361cb0ef41Sopenharmony_ci      case 'd':
4371cb0ef41Sopenharmony_ci        this.scrollLeft();
4381cb0ef41Sopenharmony_ci        return false;
4391cb0ef41Sopenharmony_ci      case 'a':
4401cb0ef41Sopenharmony_ci        this.scrollRight();
4411cb0ef41Sopenharmony_ci        return false;
4421cb0ef41Sopenharmony_ci      case '+':
4431cb0ef41Sopenharmony_ci        this.increaseTimelineResolution();
4441cb0ef41Sopenharmony_ci        return false;
4451cb0ef41Sopenharmony_ci      case '-':
4461cb0ef41Sopenharmony_ci        this.decreaseTimelineResolution();
4471cb0ef41Sopenharmony_ci        return false;
4481cb0ef41Sopenharmony_ci    }
4491cb0ef41Sopenharmony_ci  }
4501cb0ef41Sopenharmony_ci}
4511cb0ef41Sopenharmony_ci
4521cb0ef41Sopenharmony_ciexport {App};
453