Renamed Store importedProfilingData -> profilingData
Brian Vaughn committed
May 20, 2019 at 10:45 UTC
7ce9f4859c79d7f4e60b7916fd1a1efb55aa2619
7 files changed
+54
-57
src/__tests__/utils.js
+5
-5
@@ -169,21 +169,21 @@ export function exportImportHelper(
169
expect(typeof exportedProfilingDataJsonString).toBe('string');
170
expect(exportedProfilingDataJsonString).not.toBe('');
171
172
- const importedProfilingData = prepareImportedProfilingData(
172
+ const profilingData = prepareImportedProfilingData(
173
exportedProfilingDataJsonString
174
);
175
// Sanity check that profiling snapshots are serialized correctly.
176
expect(store.profilingSnapshots.get(rootID)).toEqual(
177
- importedProfilingData.profilingSnapshots.get(rootID)
177
+ profilingData.profilingSnapshots.get(rootID)
178
);
179
expect(store.profilingOperations.get(rootID)).toEqual(
180
- importedProfilingData.profilingOperations.get(rootID)
180
+ profilingData.profilingOperations.get(rootID)
181
);
182
183
// Snapshot the JSON-parsed object, rather than the raw string, because Jest formats the diff nicer.
184
- expect(importedProfilingData).toMatchSnapshot('imported data');
184
+ expect(profilingData).toMatchSnapshot('imported data');
185
186
act(() => {
187
- store.importedProfilingData = importedProfilingData;
187
+ store.profilingData = profilingData;
188
});
189
}
src/devtools/ProfilingCache.js
+12
-13
@@ -98,10 +98,9 @@ export default class ProfilingCache {
98
({ commitIndex, rendererID, rootID }: CommitDetailsParams) => {
99
return new Promise(resolve => {
100
const pendingKey = `${rootID}-${commitIndex}`;
101
- const importedProfilingData = this._store.importedProfilingData;
102
- if (importedProfilingData !== null) {
103
- const commitDetailsByCommitIndex =
104
- importedProfilingData.commitDetails;
101
+ const profilingData = this._store.profilingData;
102
+ if (profilingData !== null) {
103
+ const commitDetailsByCommitIndex = profilingData.commitDetails;
104
if (
105
commitDetailsByCommitIndex != null &&
106
commitIndex < commitDetailsByCommitIndex.length
@@ -148,9 +147,9 @@ export default class ProfilingCache {
147
({ fiberID, rendererID, rootID }: FiberCommitsParams) => {
148
return new Promise(resolve => {
149
const pendingKey = `${rootID}-${fiberID}`;
151
- const importedProfilingData = this._store.importedProfilingData;
152
- if (importedProfilingData !== null) {
153
- const { commitDetails } = importedProfilingData;
150
+ const profilingData = this._store.profilingData;
151
+ if (profilingData !== null) {
152
+ const { commitDetails } = profilingData;
153
const commitDurations = [];
154
commitDetails.forEach(({ selfDurations }, commitIndex) => {
155
const selfDuration = selfDurations.get(fiberID);
@@ -197,10 +196,10 @@ export default class ProfilingCache {
196
({ rendererID, rootID }: InteractionsParams) => {
197
return new Promise(resolve => {
198
const pendingKey = rootID;
200
- const importedProfilingData = this._store.importedProfilingData;
201
- if (importedProfilingData !== null) {
199
+ const profilingData = this._store.profilingData;
200
+ if (profilingData !== null) {
201
const interactionsFrontend: InteractionsFrontend =
203
- importedProfilingData.interactions;
202
+ profilingData.interactions;
203
if (interactionsFrontend != null) {
204
this._pendingInteractionsMap.delete(pendingKey);
205
resolve(interactionsFrontend);
@@ -235,10 +234,10 @@ export default class ProfilingCache {
234
({ rendererID, rootID }: ProfilingSummaryParams) => {
235
return new Promise(resolve => {
236
const pendingKey = rootID;
238
- const importedProfilingData = this._store.importedProfilingData;
239
- if (importedProfilingData !== null) {
237
+ const profilingData = this._store.profilingData;
238
+ if (profilingData !== null) {
239
const profilingSummaryFrontend: ProfilingSummaryFrontend =
241
- importedProfilingData.profilingSummary;
240
+ profilingData.profilingSummary;
241
if (profilingSummaryFrontend != null) {
242
this._pendingProfileSummaryMap.delete(pendingKey);
243
resolve(profilingSummaryFrontend);
src/devtools/store.js
+19
-20
@@ -80,9 +80,6 @@ export default class Store extends EventEmitter {
80
// The InspectedElementContext also relies on this mutability for its WeakMap usage.
81
_idToElement: Map<number, Element> = new Map();
82
83
- // The user has imported a previously exported profiling session.
84
- _importedProfilingData: ImportedProfilingData | null = null;
85
-
83
// The backend is currently profiling.
84
// When profiling is in progress, operations are stored so that we can later reconstruct past commit trees.
85
_isProfiling: boolean = false;
@@ -94,6 +91,9 @@ export default class Store extends EventEmitter {
91
// Suspense cache for reading profiling data.
92
_profilingCache: ProfilingCache;
93
94
+ // The user has imported a previously exported profiling session.
95
+ _profilingData: ImportedProfilingData | null = null;
96
+
97
// Map of root (id) to a list of tree mutation that occur during profiling.
98
// Once profiling is finished, these mutations can be used, along with the initial tree snapshots,
99
// to reconstruct the state of each root for each commit.
@@ -298,24 +298,10 @@ export default class Store extends EventEmitter {
298
// Profiling data has been recorded for at least one root.
299
get hasProfilingData(): boolean {
300
return (
301
- this._importedProfilingData !== null ||
302
- this._profilingOperationsByRootID.size > 0
301
+ this._profilingData !== null || this._profilingOperationsByRootID.size > 0
302
);
303
}
304
306
- get importedProfilingData(): ImportedProfilingData | null {
307
- return this._importedProfilingData;
308
- }
309
- set importedProfilingData(value: ImportedProfilingData | null): void {
310
- this._importedProfilingData = value;
311
- this._profilingOperationsByRootID = new Map();
312
- this._profilingScreenshotsByRootID = new Map();
313
- this._profilingSnapshotsByRootID = new Map();
314
- this._profilingCache.invalidate();
315
-
316
- this.emit('importedProfilingData');
317
- }
318
-
305
get isProfiling(): boolean {
306
return this._isProfiling;
307
}
@@ -328,6 +314,19 @@ export default class Store extends EventEmitter {
314
return this._profilingCache;
315
}
316
317
+ get profilingData(): ImportedProfilingData | null {
318
+ return this._profilingData;
319
+ }
320
+ set profilingData(value: ImportedProfilingData | null): void {
321
+ this._profilingData = value;
322
+ this._profilingOperationsByRootID = new Map();
323
+ this._profilingScreenshotsByRootID = new Map();
324
+ this._profilingSnapshotsByRootID = new Map();
325
+ this._profilingCache.invalidate();
326
+
327
+ this.emit('profilingData');
328
+ }
329
+
330
get profilingOperations(): Map<number, Array<Uint32Array>> {
331
return this._profilingOperationsByRootID;
332
}
@@ -365,7 +364,7 @@ export default class Store extends EventEmitter {
364
}
365
366
clearProfilingData(): void {
368
- this._importedProfilingData = null;
367
+ this._profilingData = null;
368
this._profilingOperationsByRootID = new Map();
369
this._profilingScreenshotsByRootID = new Map();
370
this._profilingSnapshotsByRootID = new Map();
@@ -1068,7 +1067,7 @@ export default class Store extends EventEmitter {
1067
1068
onProfilingStatus = (isProfiling: boolean) => {
1069
if (isProfiling) {
1071
- this._importedProfilingData = null;
1070
+ this._profilingData = null;
1071
this._profilingOperationsByRootID = new Map();
1072
this._profilingScreenshotsByRootID = new Map();
1073
this._profilingSnapshotsByRootID = new Map();
src/devtools/views/Profiler/CommitTreeBuilder.js
+6
-6
@@ -55,10 +55,10 @@ export function getCommitTree({
55
return commitTrees[commitIndex];
56
}
57
58
- const { importedProfilingData } = store;
58
+ const { profilingData } = store;
59
const profilingOperations =
60
- importedProfilingData != null
61
- ? importedProfilingData.profilingOperations
60
+ profilingData != null
61
+ ? profilingData.profilingOperations
62
: store.profilingOperations;
63
64
// Commits are generated sequentially and cached.
@@ -67,10 +67,10 @@ export function getCommitTree({
67
if (commitIndex === 0) {
68
const nodes = new Map();
69
70
- const { importedProfilingData } = store;
70
+ const { profilingData } = store;
71
const profilingSnapshots =
72
- importedProfilingData != null
73
- ? importedProfilingData.profilingSnapshots.get(rootID)
72
+ profilingData != null
73
+ ? profilingData.profilingSnapshots.get(rootID)
74
: store.profilingSnapshots.get(rootID);
75
76
if (profilingSnapshots == null) {
src/devtools/views/Profiler/ProfilerContext.js
+9
-10
@@ -72,7 +72,7 @@ ProfilerContext.displayName = 'ProfilerContext';
72
73
type StoreProfilingState = {|
74
hasProfilingData: boolean,
75
- importedProfilingData: ImportedProfilingData | null,
75
+ profilingData: ImportedProfilingData | null,
76
isProfiling: boolean,
77
|};
78
@@ -89,30 +89,29 @@ function ProfilerContextController({ children }: Props) {
89
() => ({
90
getCurrentValue: () => ({
91
hasProfilingData: store.hasProfilingData,
92
- importedProfilingData: store.importedProfilingData,
92
+ profilingData: store.profilingData,
93
isProfiling: store.isProfiling,
94
}),
95
subscribe: (callback: Function) => {
96
- store.addListener('importedProfilingData', callback);
96
+ store.addListener('profilingData', callback);
97
store.addListener('isProfiling', callback);
98
return () => {
99
- store.removeListener('importedProfilingData', callback);
99
+ store.removeListener('profilingData', callback);
100
store.removeListener('isProfiling', callback);
101
};
102
},
103
}),
104
[store]
105
);
106
- const {
107
- isProfiling,
108
- hasProfilingData,
109
- importedProfilingData,
110
- } = useSubscription<StoreProfilingState, Store>(subscription);
106
+ const { isProfiling, hasProfilingData, profilingData } = useSubscription<
107
+ StoreProfilingState,
108
+ Store
109
+ >(subscription);
110
111
let rendererID = null;
112
let rootID = null;
113
let rootHasProfilingData = false;
115
- if (importedProfilingData !== null) {
114
+ if (profilingData !== null) {
115
rootHasProfilingData = true;
116
} else if (selectedElementID !== null) {
117
rendererID = store.getRendererIDForElement(selectedElementID);
src/devtools/views/Profiler/ProfilingImportExportButtons.js
+1
-1
@@ -57,7 +57,7 @@ export default function ProfilingImportExportButtons() {
57
fileReader.addEventListener('load', () => {
58
try {
59
const raw = ((fileReader.result: any): string);
60
- store.importedProfilingData = prepareImportedProfilingData(raw);
60
+ store.profilingData = prepareImportedProfilingData(raw);
61
} catch (error) {
62
modalDialogDispatch({
63
type: 'SHOW',
src/devtools/views/Profiler/utils.js
+2
-2
@@ -120,7 +120,7 @@ export const prepareImportedProfilingData = (
120
initialTreeBaseDurationsMap.set(fiberID, initialTreeBaseDuration);
121
}
122
123
- const importedProfilingData: ImportedProfilingData = {
123
+ const profilingData: ImportedProfilingData = {
124
version: parsed.version,
125
profilingOperations: new Map(
126
exportedProfilingData.profilingOperationsByRootID.map(
@@ -169,7 +169,7 @@ export const prepareImportedProfilingData = (
169
interactionCount: profilingSummaryExported.interactionCount,
170
},
171
};
172
- return importedProfilingData;
172
+ return profilingData;
173
};
174
175
export const getGradientColor = (value: number) => {