diff --git a/src/import/__snapshots__/chrome.test.ts.snap b/src/import/__snapshots__/chrome.test.ts.snap index c9601db..1dd0be8 100644 --- a/src/import/__snapshots__/chrome.test.ts.snap +++ b/src/import/__snapshots__/chrome.test.ts.snap @@ -633,7 +633,7 @@ Object { "line": 0, "name": "(anonymous)", "selfWeight": 0, - "totalWeight": 2591, + "totalWeight": 2524, }, Frame { "col": -1, @@ -641,8 +641,8 @@ Object { "key": "Worker::-1:-1", "line": -1, "name": "Worker", - "selfWeight": 873, - "totalWeight": 2591, + "selfWeight": 806, + "totalWeight": 2524, }, Frame { "col": 29, @@ -731,7 +731,7 @@ Object { "(program) 11.20ms", " 296.00µs", "(program) 1.90ms", - "(anonymous);Worker 873.00µs", + "(anonymous);Worker 806.00µs", "(anonymous);Worker;(program) 1.72ms", " 670.00µs", "(program) 28.45ms", @@ -1305,7 +1305,7 @@ Object { "line": 0, "name": "(anonymous)", "selfWeight": 542, - "totalWeight": 6218, + "totalWeight": 6115, }, Frame { "col": 25, @@ -1314,7 +1314,7 @@ Object { "line": 30, "name": "insertTextScript", "selfWeight": 392, - "totalWeight": 977, + "totalWeight": 874, }, Frame { "col": 25, @@ -1322,8 +1322,8 @@ Object { "key": "insertHeaderNode:chrome-extension://denbgaamihkadbghdceggmchnflmhpmk/contentScript.js:57:25", "line": 57, "name": "insertHeaderNode", - "selfWeight": 292, - "totalWeight": 585, + "selfWeight": 189, + "totalWeight": 482, }, Frame { "col": undefined, @@ -1558,7 +1558,7 @@ Object { "(anonymous);(anonymous);(anonymous);(program) 27.49ms", "(anonymous) 542.00µs", "(anonymous);insertTextScript 392.00µs", - "(anonymous);insertTextScript;insertHeaderNode 292.00µs", + "(anonymous);insertTextScript;insertHeaderNode 189.00µs", "(anonymous);insertTextScript;insertHeaderNode;appendChild;(anonymous);(anonymous) 148.00µs", "(anonymous);insertTextScript;insertHeaderNode;appendChild 145.00µs", "(anonymous);listenForMessage;get webstore 148.00µs", diff --git a/src/import/chrome.ts b/src/import/chrome.ts index bde1930..01175f6 100644 --- a/src/import/chrome.ts +++ b/src/import/chrome.ts @@ -224,6 +224,9 @@ export function importFromChromeCPUProfile(chromeProfile: CPUProfile): Profile { // Ref: https://github.com/v8/v8/blob/44bd8fd7/src/inspector/js_protocol.json#L1485 let elapsed = chromeProfile.timeDeltas[0] + // Prevents negative time deltas from causing bad data. + let lastElapsed = elapsed + let lastNodeId = NaN // The chrome CPU profile format doesn't collapse identical samples. We'll do that @@ -232,21 +235,30 @@ export function importFromChromeCPUProfile(chromeProfile: CPUProfile): Profile { const nodeId = chromeProfile.samples[i] if (nodeId != lastNodeId) { samples.push(nodeId) - sampleTimes.push(elapsed) + if (elapsed < lastElapsed) { + sampleTimes.push(lastElapsed) + } else { + sampleTimes.push(elapsed) + lastElapsed = elapsed + } } if (i === chromeProfile.samples.length - 1) { if (!isNaN(lastNodeId)) { samples.push(lastNodeId) - sampleTimes.push(elapsed) + if (elapsed < lastElapsed) { + sampleTimes.push(lastElapsed) + } else { + sampleTimes.push(elapsed) + lastElapsed = elapsed + } } } else { - let timeDelta = chromeProfile.timeDeltas[i + 1] - if (timeDelta < 0) { - // This is super noisy, but can be helpful when debugging strange data - // console.warn('Substituting zero for unexpected time delta:', timeDelta, 'at index', i) - timeDelta = 0 - } + const timeDelta = chromeProfile.timeDeltas[i + 1] + // This is super noisy, but can be helpful when debugging strange data + // if (timeDelta < 0) { + // console.warn('Substituting zero for unexpected time delta:', timeDelta, 'at index', i) + // } elapsed += timeDelta lastNodeId = nodeId