From f25f8fc5cc4cc8164398201b990e0c6a7faefcb8 Mon Sep 17 00:00:00 2001 From: Jamie Wong Date: Tue, 30 Jan 2018 12:26:44 -0800 Subject: [PATCH] Fix for Chrome timelines containing multiple CPU profiles --- import/chrome.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/import/chrome.ts b/import/chrome.ts index e280fff..be05af3 100644 --- a/import/chrome.ts +++ b/import/chrome.ts @@ -45,12 +45,17 @@ interface CPUProfile { } export function importFromChromeTimeline(events: TimelineEvent[]) { - const profileEvent = events[events.length - 1] - const chromeProfile = profileEvent.args.data.cpuProfile as CPUProfile - return importFromChromeCPUProfile(chromeProfile) + // It seems like sometimes Chrome timeline files contain multiple CpuProfiles? + // For now, choose the first one in the list. + for (let event of events) { + if (event.name == "CpuProfile") { + const chromeProfile = event.args.data.cpuProfile as CPUProfile + return importFromChromeCPUProfile(chromeProfile) + } + } + throw new Error("Could not find CPU profile in Timeline") } - const callFrameToFrameInfo = new Map() function frameInfoForCallFrame(callFrame: CPUProfileCallFrame) { return getOrInsert(callFrameToFrameInfo, callFrame, (callFrame) => {