Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,692 changes: 1,692 additions & 0 deletions sample/profiles/Safari/26.4/simple.html-recording.json

Large diffs are not rendered by default.

131 changes: 131 additions & 0 deletions src/import/__snapshots__/safari.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,137 @@ exports[`importFromSafari 1`] = `
}
`;

exports[`importFromSafari 26.4 1`] = `
{
"frames": [
Frame {
"col": 1,
"file": "file:///./speedscope/sample/programs/javascript/simple.js",
"key": "(program):file:///./speedscope/sample/programs/javascript/simple.js:1:1",
"line": 1,
"name": "(program)",
"selfWeight": 0,
"totalWeight": 0.012226333332364447,
},
Frame {
"col": 15,
"file": "file:///./speedscope/sample/programs/javascript/simple.js",
"key": "alpha:file:///./speedscope/sample/programs/javascript/simple.js:1:15",
"line": 1,
"name": "alpha",
"selfWeight": 0,
"totalWeight": 0.012226333332364447,
},
Frame {
"col": 14,
"file": "file:///./speedscope/sample/programs/javascript/simple.js",
"key": "beta:file:///./speedscope/sample/programs/javascript/simple.js:8:14",
"line": 8,
"name": "beta",
"selfWeight": 0,
"totalWeight": 0.006986476189922541,
},
Frame {
"col": 15,
"file": "file:///./speedscope/sample/programs/javascript/simple.js",
"key": "gamma:file:///./speedscope/sample/programs/javascript/simple.js:20:15",
"line": 20,
"name": "gamma",
"selfWeight": 0.012226333332364447,
"totalWeight": 0.012226333332364447,
},
Frame {
"col": 15,
"file": "file:///./speedscope/sample/programs/javascript/simple.js",
"key": "delta:file:///./speedscope/sample/programs/javascript/simple.js:14:15",
"line": 14,
"name": "delta",
"selfWeight": 0,
"totalWeight": 0.005239857142441906,
},
Frame {
"col": 11,
"file": "",
"key": "createInspectorInjectedScript::1:11",
"line": 1,
"name": "createInspectorInjectedScript",
"selfWeight": 0,
"totalWeight": 0.001,
},
Frame {
"col": 11,
"file": "",
"key": "createObjectWithoutPrototype::1:11",
"line": 1,
"name": "createObjectWithoutPrototype",
"selfWeight": 0.001,
"totalWeight": 0.001,
},
Frame {
"col": 1,
"file": "__InjectedScript_FormMetadata.js",
"key": "(program):__InjectedScript_FormMetadata.js:1:1",
"line": 1,
"name": "(program)",
"selfWeight": 0,
"totalWeight": 0.001,
},
Frame {
"col": 33612,
"file": "__InjectedScript_FormMetadata.js",
"key": "FormMetadata:__InjectedScript_FormMetadata.js:3:33612",
"line": 3,
"name": "FormMetadata",
"selfWeight": 0,
"totalWeight": 0.001,
},
Frame {
"col": 11,
"file": "",
"key": "reduce::1:11",
"line": 1,
"name": "reduce",
"selfWeight": 0,
"totalWeight": 0.001,
},
Frame {
"col": 34295,
"file": "__InjectedScript_FormMetadata.js",
"key": ":__InjectedScript_FormMetadata.js:3:34295",
"line": 3,
"name": "(anonymous __InjectedScript_FormMetadata.js:3)",
"selfWeight": 0.001,
"totalWeight": 0.001,
},
Frame {
"col": 66678,
"file": "__InjectedScript_ReaderArticleFinder.js",
"key": "findTextSamplesByVisualExamination:__InjectedScript_ReaderArticleFinder.js:13:66678",
"line": 13,
"name": "findTextSamplesByVisualExamination",
"selfWeight": 0.0002195416745962575,
"totalWeight": 0.0002195416745962575,
},
],
"name": "Timeline Recording 5",
"stacks": [
"(program);alpha;beta;gamma 5.24ms",
"(program);alpha;delta;gamma 3.49ms",
"(program);alpha;beta;gamma 1.75ms",
"(program);alpha;delta;gamma 1.75ms",
" 254.58ms",
"createInspectorInjectedScript;createObjectWithoutPrototype 1.00ms",
"(program);FormMetadata;reduce;(anonymous __InjectedScript_FormMetadata.js:3) 1.00ms",
" 1.58s",
"findTextSamplesByVisualExamination 219.54µs",
],
}
`;

exports[`importFromSafari 26.4: indexToView 1`] = `0`;

exports[`importFromSafari 26.4: profileGroup.name 1`] = `"Timeline Recording 5"`;

exports[`importFromSafari: indexToView 1`] = `0`;

exports[`importFromSafari: profileGroup.name 1`] = `"Grabación de Control temporal 1"`;
4 changes: 2 additions & 2 deletions src/import/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {importSpeedscopeProfiles} from '../lib/file-format'
import {importFromV8ProfLog} from './v8proflog'
import {importFromLinuxPerf} from './linux-tools-perf'
import {importFromHaskell} from './haskell'
import {importFromSafari} from './safari'
import {isSafariTimeline, importFromSafari} from './safari'
import {ProfileDataSource, TextProfileDataSource, MaybeCompressedDataReader} from './utils'
import {importAsPprofProfile} from './pprof'
import {decodeBase64} from '../lib/utils'
Expand Down Expand Up @@ -175,7 +175,7 @@ async function _importProfileGroup(dataSource: ProfileDataSource): Promise<Profi
} else if ('rts_arguments' in parsed && 'initial_capabilities' in parsed) {
console.log('Importing as Haskell GHC JSON Profile')
return importFromHaskell(parsed)
} else if ('recording' in parsed && 'sampleStackTraces' in parsed.recording) {
} else if (isSafariTimeline(parsed)) {
console.log('Importing as Safari profile')
return toGroup(importFromSafari(parsed))
}
Expand Down
4 changes: 4 additions & 0 deletions src/import/safari.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ import {checkProfileSnapshot} from '../lib/test-utils'
test('importFromSafari', async () => {
await checkProfileSnapshot('./sample/profiles/Safari/13.1/simple.html-recording.json')
})

test('importFromSafari 26.4', async () => {
await checkProfileSnapshot('./sample/profiles/Safari/26.4/simple.html-recording.json')
})
43 changes: 37 additions & 6 deletions src/import/safari.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,17 @@ interface StackFrame {
expressionLocation?: ExprLocation
}

interface Sample {
interface StackFramesSample {
timestamp: number
stackFrames: StackFrame[]
}

interface Recording {
interface Sample {
stackTraces: StackFramesSample[]
durations: number[]
}

type Recording = {
displayName: string
startTime: number
endTime: number
Expand All @@ -48,9 +53,15 @@ interface Recording {
records: Record[]
markers: any[]
memoryPressureEvents: any[]
sampleStackTraces: Sample[]
sampleDurations: number[]
}
} & (
| {
sampleStackTraces: StackFramesSample[]
sampleDurations: number[]
}
| {
samples: Sample[]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new format moves sampleStackTraces and sampleDurations into the samples array (e.g. samples: [{ stackTraces: [], durations: []}])

}
)

interface Overview {
secondsPerPixel: number
Expand All @@ -77,13 +88,33 @@ function makeStack(frames: StackFrame[]): FrameInfo[] {
.reverse()
}

function extractSample(recording: Recording) {
if ('sampleStackTraces' in recording) {
return recording
}

const {samples} = recording
const sample = samples.length > 0 ? samples[0] : {stackTraces: [], durations: []}
return {
sampleStackTraces: sample.stackTraces,
sampleDurations: sample.durations,
}
}

export function isSafariTimeline(rawProfile: any): rawProfile is SafariProfile {
return (
'recording' in rawProfile &&
('sampleStackTraces' in rawProfile.recording || 'samples' in rawProfile.recording)
)
}

export function importFromSafari(contents: SafariProfile): Profile | null {
if (contents.version !== 1) {
console.warn(`Unknown Safari profile version ${contents.version}... Might be incompatible.`)
}

const {recording} = contents
const {sampleStackTraces, sampleDurations} = recording
const {sampleStackTraces, sampleDurations} = extractSample(recording)

const count = sampleStackTraces.length
if (count < 1) {
Expand Down
Loading