Commit 1ac40e69 authored by Leszek Swirski's avatar Leszek Swirski Committed by V8 LUCI CQ

[system-analyzer] Support inline scripts

Inline scripts share the same URL, so lookup of script by URL on them
can give the wrong result. Also, their source positions are relative to
the start of the HTML file, so we need to infer the starting line from
the Script's compilation event.

As a drive-by, fix the tooltip to lock in-place on click.

Change-Id: I5db6d35b0fbd2521531e48c34dea44b43b65ca4a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2963592
Auto-Submit: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75153}
parent c9249db6
......@@ -261,10 +261,10 @@ export class Processor extends LogReader {
if (inlinedPos > 0) {
deoptLocation = deoptLocation.substring(0, inlinedPos)
}
const script = this.getProfileEntryScript(codeEntry);
if (!script) return;
const colSeparator = deoptLocation.lastIndexOf(':');
const rowSeparator = deoptLocation.lastIndexOf(':', colSeparator - 1);
const script = this.getScript(deoptLocation.substring(1, rowSeparator));
if (!script) return;
const line =
parseInt(deoptLocation.substring(rowSeparator + 1, colSeparator));
const column = parseInt(
......
......@@ -185,9 +185,9 @@ class SourcePositionIterator {
}
}
function* lineIterator(source) {
function* lineIterator(source, startLine) {
let current = 0;
let line = 1;
let line = startLine;
while (current < source.length) {
const next = source.indexOf('\n', current);
if (next === -1) break;
......@@ -235,7 +235,18 @@ class LineBuilder {
createScriptNode() {
const scriptNode = DOM.div('scriptNode');
for (let [lineIndex, line] of lineIterator(this._script.source)) {
let startLine = 1;
// Try to infer the start line of the script from its code entries.
for (const entry of this._script.entries) {
if (entry.type.startsWith('Script')) {
if (entry.sourcePosition) {
startLine = entry.sourcePosition.line;
}
break;
}
}
for (let [lineIndex, line] of lineIterator(
this._script.source, startLine)) {
scriptNode.appendChild(this._createLineNode(lineIndex, line));
}
return scriptNode;
......
......@@ -308,10 +308,21 @@ export class TimelineTrackBase extends V8CustomElement {
// Subclass responsibility.
}
_handleUnlockedMouseEvent(event) {
const logEntry = this._getEntryForEvent(event);
if (!logEntry) return false;
this.dispatchEvent(new ToolTipEvent(logEntry, this.toolTipTargetNode));
const time = this.positionToTime(event.pageX);
this._drawAnnotations(logEntry, time);
}
_handleClick(event) {
if (event.button !== 0) return;
if (event.target === this.timelineChunks) return;
this.isLocked = !this.isLocked;
// Do this unconditionally since we want the tooltip to be update to the
// latest locked state.
this._handleUnlockedMouseEvent(event);
event.stopImmediatePropagation();
event.stopPropagation();
return false;
......@@ -331,12 +342,8 @@ export class TimelineTrackBase extends V8CustomElement {
_handleMouseMove(event) {
if (event.button !== 0) return;
if (this._selectionHandler.isSelecting) return false;
const logEntry = this._getEntryForEvent(event);
if (!logEntry) return false;
this.dispatchEvent(new ToolTipEvent(logEntry, this.toolTipTargetNode));
if (this.isLocked) return false;
const time = this.positionToTime(event.pageX);
this._drawAnnotations(logEntry, time);
this._handleUnlockedMouseEvent(event);
}
_getChunkForEvent(event) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment