forked from firefox-devtools/profiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata-structures.js
436 lines (409 loc) · 12.5 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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
/* 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,
JsAllocationsTable,
UnbalancedNativeAllocationsTable,
BalancedNativeAllocationsTable,
ResourceTable,
NativeSymbolTable,
Profile,
ExtensionTable,
CategoryList,
JsTracerTable,
CallNodeTable,
} from 'firefox-profiler/types';
/**
* 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,
};
}
/**
* Returns an empty samples table with eventDelay field instead of responsiveness.
* eventDelay is a new field and it replaced responsiveness. We should still
* account for older profiles and use both of the flavors if needed.
*/
export function getEmptySamplesTableWithEventDelay(): 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.
weightType: 'samples',
weight: null,
eventDelay: [],
stack: [],
time: [],
length: 0,
};
}
/**
* Returns an empty samples table with responsiveness field instead of eventDelay.
* responsiveness is the older field and replaced with eventDelay. We should
* account for older profiles and use both of the flavors if needed.
*/
export function getEmptySamplesTableWithResponsiveness(): 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.
weightType: 'samples',
weight: null,
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: [],
inlineDepth: [],
category: [],
subcategory: [],
func: [],
nativeSymbol: [],
innerWindowID: [],
implementation: [],
line: [],
column: [],
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(),
inlineDepth: frameTable.inlineDepth.slice(),
category: frameTable.category.slice(),
subcategory: frameTable.subcategory.slice(),
func: frameTable.func.slice(),
nativeSymbol: frameTable.nativeSymbol.slice(),
innerWindowID: frameTable.innerWindowID.slice(),
implementation: frameTable.implementation.slice(),
line: frameTable.line.slice(),
column: frameTable.column.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.
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.
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 shallowCloneNativeSymbolTable(
nativeSymbols: NativeSymbolTable
): NativeSymbolTable {
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.
libIndex: nativeSymbols.libIndex.slice(),
address: nativeSymbols.address.slice(),
name: nativeSymbols.name.slice(),
functionSize: nativeSymbols.functionSize.slice(),
length: nativeSymbols.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 getEmptyNativeSymbolTable(): NativeSymbolTable {
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.
libIndex: [],
address: [],
name: [],
functionSize: [],
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: [],
startTime: [],
endTime: [],
phase: [],
category: [],
length: 0,
};
}
export function getEmptyJsAllocationsTable(): JsAllocationsTable {
// 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 {
time: [],
className: [],
typeName: [],
coarseType: [],
weight: [],
weightType: 'bytes',
inNursery: [],
stack: [],
length: 0,
};
}
/**
* The native allocation tables come in two varieties. Get one of the members of the
* union.
*/
export function getEmptyUnbalancedNativeAllocationsTable(): UnbalancedNativeAllocationsTable {
// 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 {
time: [],
weight: [],
weightType: 'bytes',
stack: [],
length: 0,
};
}
/**
* The native allocation tables come in two varieties. Get one of the members of the
* union.
*/
export function getEmptyBalancedNativeAllocationsTable(): BalancedNativeAllocationsTable {
// 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 {
time: [],
weight: [],
weightType: 'bytes',
stack: [],
memoryAddress: [],
threadId: [],
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(),
startTime: markerTable.startTime.slice(),
endTime: markerTable.endTime.slice(),
phase: markerTable.phase.slice(),
category: markerTable.category.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 [
// Make sure 'Other' is at index 0, as it's used as the category for stacks when no
// categories are provided by an imported (non-Gecko profiler) profile.
{ name: 'Other', color: 'grey', subcategories: ['Other'] },
{ name: 'Idle', color: 'transparent', 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: [],
line: [],
column: [],
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',
isMainThread: false,
pid: '0',
tid: 0,
// Creating samples with event delay since it's the new samples table.
samples: getEmptySamplesTableWithEventDelay(),
markers: getEmptyRawMarkerTable(),
stackTable: getEmptyStackTable(),
frameTable: getEmptyFrameTable(),
stringTable: new UniqueStringArray(),
funcTable: getEmptyFuncTable(),
resourceTable: getEmptyResourceTable(),
nativeSymbols: getEmptyNativeSymbolTable(),
};
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,
CPUName: '',
symbolicated: true,
markerSchema: [],
},
libs: [],
pages: [],
threads: [],
};
}
export function getEmptyCallNodeTable(): CallNodeTable {
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.
prefix: new Int32Array(0),
subtreeRangeEnd: new Uint32Array(0),
nextSibling: new Int32Array(0),
func: new Int32Array(0),
category: new Int32Array(0),
subcategory: new Int32Array(0),
innerWindowID: new Float64Array(0),
sourceFramesInlinedIntoSymbol: [],
depth: [],
maxDepth: -1,
length: 0,
};
}