Fix for Chrome timelines containing multiple CPU profiles

This commit is contained in:
Jamie Wong 2018-01-30 12:26:44 -08:00
parent f9af0fddb2
commit f25f8fc5cc

View File

@ -45,12 +45,17 @@ interface CPUProfile {
} }
export function importFromChromeTimeline(events: TimelineEvent[]) { export function importFromChromeTimeline(events: TimelineEvent[]) {
const profileEvent = events[events.length - 1] // It seems like sometimes Chrome timeline files contain multiple CpuProfiles?
const chromeProfile = profileEvent.args.data.cpuProfile as CPUProfile // For now, choose the first one in the list.
return importFromChromeCPUProfile(chromeProfile) 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<CPUProfileCallFrame, FrameInfo>() const callFrameToFrameInfo = new Map<CPUProfileCallFrame, FrameInfo>()
function frameInfoForCallFrame(callFrame: CPUProfileCallFrame) { function frameInfoForCallFrame(callFrame: CPUProfileCallFrame) {
return getOrInsert(callFrameToFrameInfo, callFrame, (callFrame) => { return getOrInsert(callFrameToFrameInfo, callFrame, (callFrame) => {