forked from firefox-devtools/profiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data-structures.js
283 lines (263 loc) · 7.74 KB
/
data-structures.js
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// @flow
import { UniqueStringArray } from '../utils/unique-string-array';
import {
GECKO_PROFILE_VERSION,
PROCESSED_PROFILE_VERSION,
} from '../app-logic/constants';
import type {
Thread,
SamplesTable,
FrameTable,
StackTable,
FuncTable,
RawMarkerTable,
ResourceTable,
Profile,
ExtensionTable,
CategoryList,
JsTracerTable,
} from '../types/profile';
/**
* This module collects all of the creation of new empty profile data structures.
*/
export function getEmptyStackTable(): StackTable {
return {
// Important!
// If modifying this structure, please update all callers of this function to ensure
// that they are pushing on correctly to the data structure. These pushes may not
// be caught by the type system.
frame: [],
prefix: [],
category: [],
subcategory: [],
length: 0,
};
}
export function getEmptySamplesTable(): SamplesTable {
return {
// Important!
// If modifying this structure, please update all callers of this function to ensure
// that they are pushing on correctly to the data structure. These pushes may not
// be caught by the type system.
responsiveness: [],
stack: [],
time: [],
length: 0,
};
}
export function getEmptyFrameTable(): FrameTable {
return {
// Important!
// If modifying this structure, please update all callers of this function to ensure
// that they are pushing on correctly to the data structure. These pushes may not
// be caught by the type system.
address: [],
category: [],
subcategory: [],
func: [],
implementation: [],
line: [],
column: [],
optimizations: [],
length: 0,
};
}
export function shallowCloneFrameTable(frameTable: FrameTable): FrameTable {
return {
// Important!
// If modifying this structure, please update all callers of this function to ensure
// that they are pushing on correctly to the data structure. These pushes may not
// be caught by the type system.
address: frameTable.address.slice(),
category: frameTable.category.slice(),
subcategory: frameTable.subcategory.slice(),
func: frameTable.func.slice(),
implementation: frameTable.implementation.slice(),
line: frameTable.line.slice(),
column: frameTable.column.slice(),
optimizations: frameTable.optimizations.slice(),
length: frameTable.length,
};
}
export function getEmptyFuncTable(): FuncTable {
return {
// Important!
// If modifying this structure, please update all callers of this function to ensure
// that they are pushing on correctly to the data structure. These pushes may not
// be caught by the type system.
address: [],
isJS: [],
relevantForJS: [],
name: [],
resource: [],
fileName: [],
lineNumber: [],
columnNumber: [],
length: 0,
};
}
export function shallowCloneFuncTable(funcTable: FuncTable): FuncTable {
return {
// Important!
// If modifying this structure, please update all callers of this function to ensure
// that they are pushing on correctly to the data structure. These pushes may not
// be caught by the type system.
address: funcTable.address.slice(),
isJS: funcTable.isJS.slice(),
relevantForJS: funcTable.relevantForJS.slice(),
name: funcTable.name.slice(),
resource: funcTable.resource.slice(),
fileName: funcTable.fileName.slice(),
lineNumber: funcTable.lineNumber.slice(),
columnNumber: funcTable.columnNumber.slice(),
length: funcTable.length,
};
}
export function getEmptyResourceTable(): ResourceTable {
return {
// Important!
// If modifying this structure, please update all callers of this function to ensure
// that they are pushing on correctly to the data structure. These pushes may not
// be caught by the type system.
lib: [],
name: [],
host: [],
type: [],
length: 0,
};
}
export function getEmptyRawMarkerTable(): RawMarkerTable {
// Important!
// If modifying this structure, please update all callers of this function to ensure
// that they are pushing on correctly to the data structure. These pushes may not
// be caught by the type system.
return {
data: [],
name: [],
time: [],
length: 0,
};
}
export function shallowCloneRawMarkerTable(
markerTable: RawMarkerTable
): RawMarkerTable {
return {
// Important!
// If modifying this structure, please update all callers of this function to ensure
// that they are pushing on correctly to the data structure. These pushes may not
// be caught by the type system.
data: markerTable.data.slice(),
name: markerTable.name.slice(),
time: markerTable.time.slice(),
length: markerTable.length,
};
}
export function getResourceTypes(): * {
return {
unknown: 0,
library: 1,
addon: 2,
webhost: 3,
otherhost: 4,
url: 5,
};
}
/**
* Export a read-only copy of the resource types.
*/
export const resourceTypes = (getResourceTypes(): $Exact<
$ReadOnly<$Call<typeof getResourceTypes>>
>);
export function getEmptyExtensions(): ExtensionTable {
return {
// Important!
// If modifying this structure, please update all callers of this function to ensure
// that they are pushing on correctly to the data structure. These pushes may not
// be caught by the type system.
id: [],
name: [],
baseURL: [],
length: 0,
};
}
export function getDefaultCategories(): CategoryList {
return [
{ name: 'Idle', color: 'transparent', subcategories: ['Other'] },
{ name: 'Other', color: 'grey', subcategories: ['Other'] },
{ name: 'Layout', color: 'purple', subcategories: ['Other'] },
{ name: 'JavaScript', color: 'yellow', subcategories: ['Other'] },
{ name: 'GC / CC', color: 'orange', subcategories: ['Other'] },
{ name: 'Network', color: 'lightblue', subcategories: ['Other'] },
{ name: 'Graphics', color: 'green', subcategories: ['Other'] },
{ name: 'DOM', color: 'blue', subcategories: ['Other'] },
];
}
export function getEmptyJsTracerTable(): JsTracerTable {
return {
// Important!
// If modifying this structure, please update all callers of this function to ensure
// that they are pushing on correctly to the data structure. These pushes may not
// be caught by the type system.
events: [],
timestamps: [],
durations: [],
lines: [],
columns: [],
length: 0,
};
}
export function getEmptyThread(overrides?: $Shape<Thread>): Thread {
const defaultThread: Thread = {
processType: 'default',
processStartupTime: 0,
processShutdownTime: null,
registerTime: 0,
unregisterTime: null,
pausedRanges: [],
name: 'Empty',
pid: 0,
tid: 0,
samples: getEmptySamplesTable(),
markers: getEmptyRawMarkerTable(),
stackTable: getEmptyStackTable(),
frameTable: getEmptyFrameTable(),
stringTable: new UniqueStringArray(),
libs: [],
funcTable: getEmptyFuncTable(),
resourceTable: getEmptyResourceTable(),
};
return {
...defaultThread,
...overrides,
};
}
export function getEmptyProfile(): Profile {
return {
meta: {
interval: 1,
startTime: 0,
abi: '',
misc: '',
oscpu: '',
platform: '',
processType: 0,
extensions: getEmptyExtensions(),
categories: getDefaultCategories(),
product: 'Firefox',
stackwalk: 0,
toolkit: '',
version: GECKO_PROFILE_VERSION,
preprocessedProfileVersion: PROCESSED_PROFILE_VERSION,
appBuildID: '',
sourceURL: '',
physicalCPUs: 0,
logicalCPUs: 0,
symbolicated: true,
},
pages: [],
threads: [],
};
}