-
Notifications
You must be signed in to change notification settings - Fork 249
/
file-format-spec.ts
145 lines (116 loc) · 4.26 KB
/
file-format-spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// This file contains types which specify the speedscope file format.
export namespace FileFormat {
export type Profile = EventedProfile | SampledProfile
export interface File {
$schema: 'https://www.speedscope.app/file-format-schema.json'
// Data shared between profiles
shared: {
frames: Frame[]
}
// List of profile definitions
profiles: Profile[]
// The name of the contained profile group. If omitted, will use the name of
// the file itself.
// Added in 0.6.0
name?: string
// The index into the `profiles` array that should be displayed upon file
// load. If omitted, will default to displaying the first profile in the
// file.
//
// Added in 0.6.0
activeProfileIndex?: number
// The name of the the program which exported this profile. This isn't
// consumed but can be helpful for debugging generated data by seeing what
// was generating it! Recommended format is "name@version". e.g. when the
// file was exported by speedscope v0.6.0 itself, it will be
// "[email protected]"
//
// Added in 0.6.0
exporter?: string
}
export interface Frame {
name: string
file?: string
line?: number
col?: number
}
export enum ProfileType {
EVENTED = 'evented',
SAMPLED = 'sampled',
}
export interface IProfile {
// Type of profile. This will future proof the file format to allow many
// different kinds of profiles to be contained and each type to be part of
// a discriminated union.
type: ProfileType
}
export interface EventedProfile extends IProfile {
type: ProfileType.EVENTED
// Name of the profile. Typically a filename for the source of the profile.
name: string
// Unit which all value are specified using in the profile.
unit: ValueUnit
// The starting value of the profile. This will typically be a timestamp.
// All event values will be displayed relative to this startValue.
startValue: number
// The final value of the profile. This will typically be a timestamp. This
// must be greater than or equal to the startValue. This is useful in
// situations where the recorded profile extends past the end of the recorded
// events, which may happen if nothing was happening at the end of the
// profile.
endValue: number
// List of events that occured as part of this profile.
// The "at" field of every event must be in non-decreasing order.
events: (OpenFrameEvent | CloseFrameEvent)[]
}
// List of indices into the frame array
type SampledStack = number[]
export interface SampledProfile extends IProfile {
type: ProfileType.SAMPLED
// Name of the profile. Typically a filename for the source of the profile.
name: string
// Unit which all value are specified using in the profile.
unit: ValueUnit
// The starting value of the profile. This will typically be a timestamp.
// All event values will be displayed relative to this startValue.
startValue: number
// The final value of the profile. This will typically be a timestamp. This
// must be greater than or equal to the startValue. This is useful in
// situations where the recorded profile extends past the end of the recorded
// events, which may happen if nothing was happening at the end of the
// profile.
endValue: number
// List of stacks
samples: SampledStack[]
// The weight of the sample at the given index. Should have
// the same length as the samples array.
weights: number[]
}
export type ValueUnit =
| 'none'
| 'nanoseconds'
| 'microseconds'
| 'milliseconds'
| 'seconds'
| 'bytes'
export enum EventType {
OPEN_FRAME = 'O',
CLOSE_FRAME = 'C',
}
interface IEvent {
type: EventType
at: number
}
// Indicates a stack frame opened. Every opened stack frame must have a
// corresponding close frame event, and the ordering must be balanced.
interface OpenFrameEvent extends IEvent {
type: EventType.OPEN_FRAME
// An index into the frames array in the shared data within the profile
frame: number
}
interface CloseFrameEvent extends IEvent {
type: EventType.CLOSE_FRAME
// An index into the frames array in the shared data within the profile
frame: number
}
}