From 783c44298b998c3eb743fa326960511a6ccff59a Mon Sep 17 00:00:00 2001 From: Jeremy Rose Date: Tue, 26 Apr 2022 12:52:59 -0700 Subject: [PATCH] add support for JS Self-Profiling data --- src/import/index.ts | 9 +++++ src/import/js-self-profiling.ts | 71 +++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 src/import/js-self-profiling.ts diff --git a/src/import/index.ts b/src/import/index.ts index e4e341c13..f46058900 100644 --- a/src/import/index.ts +++ b/src/import/index.ts @@ -22,6 +22,7 @@ import {decodeBase64} from '../lib/utils' import {importFromChromeHeapProfile} from './v8heapalloc' import {isTraceEventFormatted, importTraceEvents} from './trace-event' import {importFromCallgrind} from './callgrind' +import {importFromJSSelfProfiling} from './js-self-profiling' export async function importProfileGroupFromText( fileName: string, @@ -180,6 +181,14 @@ async function _importProfileGroup(dataSource: ProfileDataSource): Promise s.timestamp), + ), + endValue: Math.max.apply( + null, + json.samples.map(s => s.timestamp), + ), + samples: json.samples.map(({stackId}) => getFrames(stackId)), + weights: json.samples.map(({timestamp}, i) => + i === 0 ? 0 : timestamp - json.samples[i - 1].timestamp, + ), + } as FileFormat.Profile + + const frames = json.frames.map(f => { + return { + name: f.name, + line: f.line, + col: f.column, + file: f.resourceId != null ? json.resources[f.resourceId] : '(unknown)', + } + }) + + return { + $schema: 'https://www.speedscope.app/file-format-schema.json', + shared: { + frames, + }, + profiles: [profile], + } +} + +export function importFromJSSelfProfiling(serialized: JSSelfProfilingData): ProfileGroup { + return importSpeedscopeProfiles(jsspToSpeedscope(serialized)) +}