Normalize line & column numbers to be 1-based in Chrome & Firefox imports (#318)

This also fixes a dumb bug in the Firefox import that just completely failed to import column numbers.
This commit is contained in:
Jamie Wong 2020-10-02 14:56:22 -07:00 committed by GitHub
parent 8a4f38a8cb
commit 16e32dc08e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 332 additions and 319 deletions

File diff suppressed because it is too large Load Diff

View File

@ -64,17 +64,17 @@ exports[`importFromFirefox ignore self-hosted 1`] = `
Object { Object {
"frames": Array [ "frames": Array [
Frame { Frame {
"col": undefined, "col": 15,
"file": "http://localhost:8000/simple.js:1", "file": "http://localhost:8000/simple.js",
"key": "alpha (http://localhost:8000/simple.js:1:14)", "key": "alpha (http://localhost:8000/simple.js:1:14)",
"line": 14, "line": 1,
"name": "alpha", "name": "alpha",
"selfWeight": 0, "selfWeight": 0,
"totalWeight": 26.983816999942064, "totalWeight": 26.983816999942064,
}, },
Frame { Frame {
"col": undefined, "col": 15,
"file": "http://localhost:8000/simple.js:14", "file": "http://localhost:8000/simple.js",
"key": "delta (http://localhost:8000/simple.js:14:14)", "key": "delta (http://localhost:8000/simple.js:14:14)",
"line": 14, "line": 14,
"name": "delta", "name": "delta",
@ -82,19 +82,19 @@ Object {
"totalWeight": 11.946324001066387, "totalWeight": 11.946324001066387,
}, },
Frame { Frame {
"col": undefined, "col": 15,
"file": "http://localhost:8000/simple.js:20", "file": "http://localhost:8000/simple.js",
"key": "gamma (http://localhost:8000/simple.js:20:14)", "key": "gamma (http://localhost:8000/simple.js:20:14)",
"line": 14, "line": 20,
"name": "gamma", "name": "gamma",
"selfWeight": 26.983816999942064, "selfWeight": 26.983816999942064,
"totalWeight": 26.983816999942064, "totalWeight": 26.983816999942064,
}, },
Frame { Frame {
"col": undefined, "col": 14,
"file": "http://localhost:8000/simple.js:8", "file": "http://localhost:8000/simple.js",
"key": "beta (http://localhost:8000/simple.js:8:13)", "key": "beta (http://localhost:8000/simple.js:8:13)",
"line": 13, "line": 8,
"name": "beta", "name": "beta",
"selfWeight": 0, "selfWeight": 0,
"totalWeight": 15.037492998875678, "totalWeight": 15.037492998875678,

View File

@ -170,8 +170,17 @@ function frameInfoForCallFrame(callFrame: CPUProfileCallFrame) {
return getOrInsert(callFrameToFrameInfo, callFrame, callFrame => { return getOrInsert(callFrameToFrameInfo, callFrame, callFrame => {
const name = callFrame.functionName || '(anonymous)' const name = callFrame.functionName || '(anonymous)'
const file = callFrame.url const file = callFrame.url
const line = callFrame.lineNumber
const col = callFrame.columnNumber // In Chrome profiles, line numbers & column numbers are both 0-indexed.
//
// We're going to normalize these to be 1-based to avoid needing to normalize
// these at the presentation layer.
let line = callFrame.lineNumber
if (line != null) line++
let col = callFrame.columnNumber
if (col != null) col++
return { return {
key: `${name}:${file}:${line}:${col}`, key: `${name}:${file}:${line}:${col}`,
name, name,

View File

@ -176,7 +176,7 @@ export function importFromFirefox(firefoxProfile: FirefoxProfile): Profile {
const frameData = thread.frameTable.data[f] const frameData = thread.frameTable.data[f]
const location = thread.stringTable[frameData[0]] const location = thread.stringTable[frameData[0]]
const match = /(.*)\s+\((.*?):?(\d+)?\)$/.exec(location) const match = /(.*)\s+\((.*?)(?::(\d+))?(?::(\d+))?\)$/.exec(location)
if (!match) return null if (!match) return null
@ -193,7 +193,11 @@ export function importFromFirefox(firefoxProfile: FirefoxProfile): Profile {
key: location, key: location,
name: match[1]!, name: match[1]!,
file: match[2]!, file: match[2]!,
// In Firefox profiles, line numbers are 1-based, but columns are
// 0-based. Let's normalize both to be 1-based.
line: match[3] ? parseInt(match[3]) : undefined, line: match[3] ? parseInt(match[3]) : undefined,
col: match[4] ? parseInt(match[4]) + 1 : undefined,
})) }))
}) })
.filter(f => f != null) as FrameInfo[] .filter(f => f != null) as FrameInfo[]

View File

@ -68,9 +68,9 @@ class StackTraceView extends Component<StackTraceViewProps, {}> {
if (frame.file) { if (frame.file) {
let pos = frame.file let pos = frame.file
if (frame.line) { if (frame.line != null) {
pos += `:${frame.line}` pos += `:${frame.line}`
if (frame.col) { if (frame.col != null) {
pos += `:${frame.col}` pos += `:${frame.col}`
} }
} }