@react-native-oh/react-native-harmony 0.72.23-3 → 0.72.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Libraries/Alert/Alert.harmony.js +71 -71
- package/Libraries/Alert/AlertManager.ts +35 -35
- package/Libraries/Animated/NativeAnimatedHelper.harmony.js +601 -601
- package/Libraries/Components/AccessibilityInfo/AccessibilityInfo.harmony.js +445 -426
- package/Libraries/Components/AccessibilityInfo/NativeAccessibilityManager.harmony.js +30 -0
- package/Libraries/Components/AccessibilityInfo/legacySendAccessibilityEvent.harmony.js +26 -0
- package/Libraries/Components/Button/Button.harmony.js +450 -450
- package/Libraries/Components/Image/Image.flow.harmony.js +53 -0
- package/Libraries/Components/Image/Image.harmony.js +299 -0
- package/Libraries/Components/Image/NativeImageLoaderHarmony.js +38 -0
- package/Libraries/Components/RefreshControl/RefreshControl.harmony.js +210 -210
- package/Libraries/Components/SafeAreaView/SafeAreaView.harmony.tsx +76 -75
- package/Libraries/Components/ScrollView/ScrollView.harmony.js +1951 -1951
- package/Libraries/Components/ScrollView/processDecelerationRate.harmony.js +24 -24
- package/Libraries/Components/StatusBar/NativeStatusBarManagerHarmony.js +71 -68
- package/Libraries/Components/StatusBar/StatusBar.harmony.js +447 -447
- package/Libraries/Components/TextInput/TextInput.harmony.js +1707 -1707
- package/Libraries/Components/TextInput/TextInputState.harmony.js +220 -220
- package/Libraries/Components/Touchable/TouchableHighlight.harmony.js +396 -396
- package/Libraries/Components/Touchable/TouchableNativeFeedback.harmony.js +364 -364
- package/Libraries/Components/Touchable/TouchableWithoutFeedback.harmony.js +227 -227
- package/Libraries/Components/View/View.harmony.js +149 -149
- package/Libraries/Core/setUpReactDevTools.harmony.js +93 -93
- package/Libraries/Image/AssetSourceResolver.harmony.ts +78 -78
- package/Libraries/NativeComponent/BaseViewConfig.harmony.js +337 -337
- package/Libraries/ReactNative/UIManager.harmony.js +210 -210
- package/Libraries/Settings/Settings.harmony.js +15 -15
- package/Libraries/Share/Share.harmony.js +174 -174
- package/Libraries/StyleSheet/NativePlatformColor.ts +8 -8
- package/Libraries/StyleSheet/PlatformColorValueTypes.harmony.ts +14 -14
- package/Libraries/Utilities/BackHandler.harmony.js +109 -109
- package/Libraries/Utilities/{NativePlatformConstantsHarmony.ts → NativePlatformConstants.harmony.ts} +8 -8
- package/Libraries/Utilities/Platform.d.ts +117 -117
- package/Libraries/Utilities/Platform.harmony.ts +33 -33
- package/Libraries/Utilities/createPerformanceLogger.harmony.js +328 -328
- package/Libraries/Vibration/Vibration.harmony.js +88 -88
- package/index.js +212 -212
- package/jest.config.js +5 -5
- package/metro.config.js +348 -348
- package/package.json +57 -57
- package/react-native.config.js +10 -10
- package/react_native_openharmony.har +0 -0
- package/tsconfig.json +13 -13
- package/types/index.d.ts +101 -101
|
@@ -1,328 +1,328 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
-
*
|
|
4
|
-
* This source code is licensed under the MIT license found in the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
6
|
-
*
|
|
7
|
-
* @flow strict
|
|
8
|
-
* @format
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
const Systrace = require('react-native/Libraries/Performance/Systrace'); // RNOH: patch
|
|
12
|
-
const infoLog = require('react-native/Libraries/Utilities/infoLog'); // RNOH: patch
|
|
13
|
-
|
|
14
|
-
export type Timespan = {
|
|
15
|
-
startTime: number,
|
|
16
|
-
endTime?: number,
|
|
17
|
-
totalTime?: number,
|
|
18
|
-
startExtras?: Extras,
|
|
19
|
-
endExtras?: Extras,
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
// Extra values should be serializable primitives
|
|
23
|
-
export type ExtraValue = number | string | boolean;
|
|
24
|
-
|
|
25
|
-
export type Extras = {[key: string]: ExtraValue};
|
|
26
|
-
|
|
27
|
-
export interface IPerformanceLogger {
|
|
28
|
-
addTimespan(
|
|
29
|
-
key: string,
|
|
30
|
-
startTime: number,
|
|
31
|
-
endTime: number,
|
|
32
|
-
startExtras?: Extras,
|
|
33
|
-
endExtras?: Extras,
|
|
34
|
-
): void;
|
|
35
|
-
append(logger: IPerformanceLogger): void;
|
|
36
|
-
clear(): void;
|
|
37
|
-
clearCompleted(): void;
|
|
38
|
-
close(): void;
|
|
39
|
-
currentTimestamp(): number;
|
|
40
|
-
getExtras(): $ReadOnly<{[key: string]: ?ExtraValue, ...}>;
|
|
41
|
-
getPoints(): $ReadOnly<{[key: string]: ?number, ...}>;
|
|
42
|
-
getPointExtras(): $ReadOnly<{[key: string]: ?Extras, ...}>;
|
|
43
|
-
getTimespans(): $ReadOnly<{[key: string]: ?Timespan, ...}>;
|
|
44
|
-
hasTimespan(key: string): boolean;
|
|
45
|
-
isClosed(): boolean;
|
|
46
|
-
logEverything(): void;
|
|
47
|
-
markPoint(key: string, timestamp?: number, extras?: Extras): void;
|
|
48
|
-
removeExtra(key: string): ?ExtraValue;
|
|
49
|
-
setExtra(key: string, value: ExtraValue): void;
|
|
50
|
-
startTimespan(key: string, timestamp?: number, extras?: Extras): void;
|
|
51
|
-
stopTimespan(key: string, timestamp?: number, extras?: Extras): void;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const _cookies: {[key: string]: number, ...} = {};
|
|
55
|
-
|
|
56
|
-
const PRINT_TO_CONSOLE: false = false; // Type as false to prevent accidentally committing `true`;
|
|
57
|
-
|
|
58
|
-
export const getCurrentTimestamp: () => number =
|
|
59
|
-
global.nativeQPLTimestamp ?? global.performance ? global.performance.now.bind(global.performance) : Date.now; // RNOH: patch
|
|
60
|
-
|
|
61
|
-
class PerformanceLogger implements IPerformanceLogger {
|
|
62
|
-
_timespans: {[key: string]: ?Timespan} = {};
|
|
63
|
-
_extras: {[key: string]: ?ExtraValue} = {};
|
|
64
|
-
_points: {[key: string]: ?number} = {};
|
|
65
|
-
_pointExtras: {[key: string]: ?Extras, ...} = {};
|
|
66
|
-
_closed: boolean = false;
|
|
67
|
-
|
|
68
|
-
addTimespan(
|
|
69
|
-
key: string,
|
|
70
|
-
startTime: number,
|
|
71
|
-
endTime: number,
|
|
72
|
-
startExtras?: Extras,
|
|
73
|
-
endExtras?: Extras,
|
|
74
|
-
) {
|
|
75
|
-
if (this._closed) {
|
|
76
|
-
if (PRINT_TO_CONSOLE && __DEV__) {
|
|
77
|
-
infoLog('PerformanceLogger: addTimespan - has closed ignoring: ', key);
|
|
78
|
-
}
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
if (this._timespans[key]) {
|
|
82
|
-
if (PRINT_TO_CONSOLE && __DEV__) {
|
|
83
|
-
infoLog(
|
|
84
|
-
'PerformanceLogger: Attempting to add a timespan that already exists ',
|
|
85
|
-
key,
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
this._timespans[key] = {
|
|
92
|
-
startTime,
|
|
93
|
-
endTime,
|
|
94
|
-
totalTime: endTime - (startTime || 0),
|
|
95
|
-
startExtras,
|
|
96
|
-
endExtras,
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
append(performanceLogger: IPerformanceLogger) {
|
|
101
|
-
this._timespans = {
|
|
102
|
-
...performanceLogger.getTimespans(),
|
|
103
|
-
...this._timespans,
|
|
104
|
-
};
|
|
105
|
-
this._extras = {...performanceLogger.getExtras(), ...this._extras};
|
|
106
|
-
this._points = {...performanceLogger.getPoints(), ...this._points};
|
|
107
|
-
this._pointExtras = {
|
|
108
|
-
...performanceLogger.getPointExtras(),
|
|
109
|
-
...this._pointExtras,
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
clear() {
|
|
114
|
-
this._timespans = {};
|
|
115
|
-
this._extras = {};
|
|
116
|
-
this._points = {};
|
|
117
|
-
if (PRINT_TO_CONSOLE) {
|
|
118
|
-
infoLog('PerformanceLogger.js', 'clear');
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
clearCompleted() {
|
|
123
|
-
for (const key in this._timespans) {
|
|
124
|
-
if (this._timespans[key]?.totalTime != null) {
|
|
125
|
-
delete this._timespans[key];
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
this._extras = {};
|
|
129
|
-
this._points = {};
|
|
130
|
-
if (PRINT_TO_CONSOLE) {
|
|
131
|
-
infoLog('PerformanceLogger.js', 'clearCompleted');
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
close() {
|
|
136
|
-
this._closed = true;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
currentTimestamp(): number {
|
|
140
|
-
return getCurrentTimestamp();
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
getExtras(): {[key: string]: ?ExtraValue} {
|
|
144
|
-
return this._extras;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
getPoints(): {[key: string]: ?number} {
|
|
148
|
-
return this._points;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
getPointExtras(): {[key: string]: ?Extras} {
|
|
152
|
-
return this._pointExtras;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
getTimespans(): {[key: string]: ?Timespan} {
|
|
156
|
-
return this._timespans;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
hasTimespan(key: string): boolean {
|
|
160
|
-
return !!this._timespans[key];
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
isClosed(): boolean {
|
|
164
|
-
return this._closed;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
logEverything() {
|
|
168
|
-
if (PRINT_TO_CONSOLE) {
|
|
169
|
-
// log timespans
|
|
170
|
-
for (const key in this._timespans) {
|
|
171
|
-
if (this._timespans[key]?.totalTime != null) {
|
|
172
|
-
infoLog(key + ': ' + this._timespans[key].totalTime + 'ms');
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// log extras
|
|
177
|
-
infoLog(this._extras);
|
|
178
|
-
|
|
179
|
-
// log points
|
|
180
|
-
for (const key in this._points) {
|
|
181
|
-
if (this._points[key] != null) {
|
|
182
|
-
infoLog(key + ': ' + this._points[key] + 'ms');
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
markPoint(
|
|
189
|
-
key: string,
|
|
190
|
-
timestamp?: number = getCurrentTimestamp(),
|
|
191
|
-
extras?: Extras,
|
|
192
|
-
) {
|
|
193
|
-
if (this._closed) {
|
|
194
|
-
if (PRINT_TO_CONSOLE && __DEV__) {
|
|
195
|
-
infoLog('PerformanceLogger: markPoint - has closed ignoring: ', key);
|
|
196
|
-
}
|
|
197
|
-
return;
|
|
198
|
-
}
|
|
199
|
-
if (this._points[key] != null) {
|
|
200
|
-
if (PRINT_TO_CONSOLE && __DEV__) {
|
|
201
|
-
infoLog(
|
|
202
|
-
'PerformanceLogger: Attempting to mark a point that has been already logged ',
|
|
203
|
-
key,
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
this._points[key] = timestamp;
|
|
209
|
-
if (extras) {
|
|
210
|
-
this._pointExtras[key] = extras;
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
removeExtra(key: string): ?ExtraValue {
|
|
215
|
-
const value = this._extras[key];
|
|
216
|
-
delete this._extras[key];
|
|
217
|
-
return value;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
setExtra(key: string, value: ExtraValue) {
|
|
221
|
-
if (this._closed) {
|
|
222
|
-
if (PRINT_TO_CONSOLE && __DEV__) {
|
|
223
|
-
infoLog('PerformanceLogger: setExtra - has closed ignoring: ', key);
|
|
224
|
-
}
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
if (this._extras.hasOwnProperty(key)) {
|
|
229
|
-
if (PRINT_TO_CONSOLE && __DEV__) {
|
|
230
|
-
infoLog(
|
|
231
|
-
'PerformanceLogger: Attempting to set an extra that already exists ',
|
|
232
|
-
{key, currentValue: this._extras[key], attemptedValue: value},
|
|
233
|
-
);
|
|
234
|
-
}
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
this._extras[key] = value;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
startTimespan(
|
|
241
|
-
key: string,
|
|
242
|
-
timestamp?: number = getCurrentTimestamp(),
|
|
243
|
-
extras?: Extras,
|
|
244
|
-
) {
|
|
245
|
-
if (this._closed) {
|
|
246
|
-
if (PRINT_TO_CONSOLE && __DEV__) {
|
|
247
|
-
infoLog(
|
|
248
|
-
'PerformanceLogger: startTimespan - has closed ignoring: ',
|
|
249
|
-
key,
|
|
250
|
-
);
|
|
251
|
-
}
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
if (this._timespans[key]) {
|
|
256
|
-
if (PRINT_TO_CONSOLE && __DEV__) {
|
|
257
|
-
infoLog(
|
|
258
|
-
'PerformanceLogger: Attempting to start a timespan that already exists ',
|
|
259
|
-
key,
|
|
260
|
-
);
|
|
261
|
-
}
|
|
262
|
-
return;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
this._timespans[key] = {
|
|
266
|
-
startTime: timestamp,
|
|
267
|
-
startExtras: extras,
|
|
268
|
-
};
|
|
269
|
-
_cookies[key] = Systrace.beginAsyncEvent(key);
|
|
270
|
-
if (PRINT_TO_CONSOLE) {
|
|
271
|
-
infoLog('PerformanceLogger.js', 'start: ' + key);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
stopTimespan(
|
|
276
|
-
key: string,
|
|
277
|
-
timestamp?: number = getCurrentTimestamp(),
|
|
278
|
-
extras?: Extras,
|
|
279
|
-
) {
|
|
280
|
-
if (this._closed) {
|
|
281
|
-
if (PRINT_TO_CONSOLE && __DEV__) {
|
|
282
|
-
infoLog('PerformanceLogger: stopTimespan - has closed ignoring: ', key);
|
|
283
|
-
}
|
|
284
|
-
return;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
const timespan = this._timespans[key];
|
|
288
|
-
if (!timespan || timespan.startTime == null) {
|
|
289
|
-
if (PRINT_TO_CONSOLE && __DEV__) {
|
|
290
|
-
infoLog(
|
|
291
|
-
'PerformanceLogger: Attempting to end a timespan that has not started ',
|
|
292
|
-
key,
|
|
293
|
-
);
|
|
294
|
-
}
|
|
295
|
-
return;
|
|
296
|
-
}
|
|
297
|
-
if (timespan.endTime != null) {
|
|
298
|
-
if (PRINT_TO_CONSOLE && __DEV__) {
|
|
299
|
-
infoLog(
|
|
300
|
-
'PerformanceLogger: Attempting to end a timespan that has already ended ',
|
|
301
|
-
key,
|
|
302
|
-
);
|
|
303
|
-
}
|
|
304
|
-
return;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
timespan.endExtras = extras;
|
|
308
|
-
timespan.endTime = timestamp;
|
|
309
|
-
timespan.totalTime = timespan.endTime - (timespan.startTime || 0);
|
|
310
|
-
if (PRINT_TO_CONSOLE) {
|
|
311
|
-
infoLog('PerformanceLogger.js', 'end: ' + key);
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
if (_cookies[key] != null) {
|
|
315
|
-
Systrace.endAsyncEvent(key, _cookies[key]);
|
|
316
|
-
delete _cookies[key];
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
/**
|
|
322
|
-
* This function creates performance loggers that can be used to collect and log
|
|
323
|
-
* various performance data such as timespans, points and extras.
|
|
324
|
-
* The loggers need to have minimal overhead since they're used in production.
|
|
325
|
-
*/
|
|
326
|
-
export default function createPerformanceLogger(): IPerformanceLogger {
|
|
327
|
-
return new PerformanceLogger();
|
|
328
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const Systrace = require('react-native/Libraries/Performance/Systrace'); // RNOH: patch
|
|
12
|
+
const infoLog = require('react-native/Libraries/Utilities/infoLog'); // RNOH: patch
|
|
13
|
+
|
|
14
|
+
export type Timespan = {
|
|
15
|
+
startTime: number,
|
|
16
|
+
endTime?: number,
|
|
17
|
+
totalTime?: number,
|
|
18
|
+
startExtras?: Extras,
|
|
19
|
+
endExtras?: Extras,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// Extra values should be serializable primitives
|
|
23
|
+
export type ExtraValue = number | string | boolean;
|
|
24
|
+
|
|
25
|
+
export type Extras = {[key: string]: ExtraValue};
|
|
26
|
+
|
|
27
|
+
export interface IPerformanceLogger {
|
|
28
|
+
addTimespan(
|
|
29
|
+
key: string,
|
|
30
|
+
startTime: number,
|
|
31
|
+
endTime: number,
|
|
32
|
+
startExtras?: Extras,
|
|
33
|
+
endExtras?: Extras,
|
|
34
|
+
): void;
|
|
35
|
+
append(logger: IPerformanceLogger): void;
|
|
36
|
+
clear(): void;
|
|
37
|
+
clearCompleted(): void;
|
|
38
|
+
close(): void;
|
|
39
|
+
currentTimestamp(): number;
|
|
40
|
+
getExtras(): $ReadOnly<{[key: string]: ?ExtraValue, ...}>;
|
|
41
|
+
getPoints(): $ReadOnly<{[key: string]: ?number, ...}>;
|
|
42
|
+
getPointExtras(): $ReadOnly<{[key: string]: ?Extras, ...}>;
|
|
43
|
+
getTimespans(): $ReadOnly<{[key: string]: ?Timespan, ...}>;
|
|
44
|
+
hasTimespan(key: string): boolean;
|
|
45
|
+
isClosed(): boolean;
|
|
46
|
+
logEverything(): void;
|
|
47
|
+
markPoint(key: string, timestamp?: number, extras?: Extras): void;
|
|
48
|
+
removeExtra(key: string): ?ExtraValue;
|
|
49
|
+
setExtra(key: string, value: ExtraValue): void;
|
|
50
|
+
startTimespan(key: string, timestamp?: number, extras?: Extras): void;
|
|
51
|
+
stopTimespan(key: string, timestamp?: number, extras?: Extras): void;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const _cookies: {[key: string]: number, ...} = {};
|
|
55
|
+
|
|
56
|
+
const PRINT_TO_CONSOLE: false = false; // Type as false to prevent accidentally committing `true`;
|
|
57
|
+
|
|
58
|
+
export const getCurrentTimestamp: () => number =
|
|
59
|
+
global.nativeQPLTimestamp ?? global.performance ? global.performance.now.bind(global.performance) : Date.now; // RNOH: patch
|
|
60
|
+
|
|
61
|
+
class PerformanceLogger implements IPerformanceLogger {
|
|
62
|
+
_timespans: {[key: string]: ?Timespan} = {};
|
|
63
|
+
_extras: {[key: string]: ?ExtraValue} = {};
|
|
64
|
+
_points: {[key: string]: ?number} = {};
|
|
65
|
+
_pointExtras: {[key: string]: ?Extras, ...} = {};
|
|
66
|
+
_closed: boolean = false;
|
|
67
|
+
|
|
68
|
+
addTimespan(
|
|
69
|
+
key: string,
|
|
70
|
+
startTime: number,
|
|
71
|
+
endTime: number,
|
|
72
|
+
startExtras?: Extras,
|
|
73
|
+
endExtras?: Extras,
|
|
74
|
+
) {
|
|
75
|
+
if (this._closed) {
|
|
76
|
+
if (PRINT_TO_CONSOLE && __DEV__) {
|
|
77
|
+
infoLog('PerformanceLogger: addTimespan - has closed ignoring: ', key);
|
|
78
|
+
}
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
if (this._timespans[key]) {
|
|
82
|
+
if (PRINT_TO_CONSOLE && __DEV__) {
|
|
83
|
+
infoLog(
|
|
84
|
+
'PerformanceLogger: Attempting to add a timespan that already exists ',
|
|
85
|
+
key,
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
this._timespans[key] = {
|
|
92
|
+
startTime,
|
|
93
|
+
endTime,
|
|
94
|
+
totalTime: endTime - (startTime || 0),
|
|
95
|
+
startExtras,
|
|
96
|
+
endExtras,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
append(performanceLogger: IPerformanceLogger) {
|
|
101
|
+
this._timespans = {
|
|
102
|
+
...performanceLogger.getTimespans(),
|
|
103
|
+
...this._timespans,
|
|
104
|
+
};
|
|
105
|
+
this._extras = {...performanceLogger.getExtras(), ...this._extras};
|
|
106
|
+
this._points = {...performanceLogger.getPoints(), ...this._points};
|
|
107
|
+
this._pointExtras = {
|
|
108
|
+
...performanceLogger.getPointExtras(),
|
|
109
|
+
...this._pointExtras,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
clear() {
|
|
114
|
+
this._timespans = {};
|
|
115
|
+
this._extras = {};
|
|
116
|
+
this._points = {};
|
|
117
|
+
if (PRINT_TO_CONSOLE) {
|
|
118
|
+
infoLog('PerformanceLogger.js', 'clear');
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
clearCompleted() {
|
|
123
|
+
for (const key in this._timespans) {
|
|
124
|
+
if (this._timespans[key]?.totalTime != null) {
|
|
125
|
+
delete this._timespans[key];
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
this._extras = {};
|
|
129
|
+
this._points = {};
|
|
130
|
+
if (PRINT_TO_CONSOLE) {
|
|
131
|
+
infoLog('PerformanceLogger.js', 'clearCompleted');
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
close() {
|
|
136
|
+
this._closed = true;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
currentTimestamp(): number {
|
|
140
|
+
return getCurrentTimestamp();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
getExtras(): {[key: string]: ?ExtraValue} {
|
|
144
|
+
return this._extras;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
getPoints(): {[key: string]: ?number} {
|
|
148
|
+
return this._points;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
getPointExtras(): {[key: string]: ?Extras} {
|
|
152
|
+
return this._pointExtras;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
getTimespans(): {[key: string]: ?Timespan} {
|
|
156
|
+
return this._timespans;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
hasTimespan(key: string): boolean {
|
|
160
|
+
return !!this._timespans[key];
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
isClosed(): boolean {
|
|
164
|
+
return this._closed;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
logEverything() {
|
|
168
|
+
if (PRINT_TO_CONSOLE) {
|
|
169
|
+
// log timespans
|
|
170
|
+
for (const key in this._timespans) {
|
|
171
|
+
if (this._timespans[key]?.totalTime != null) {
|
|
172
|
+
infoLog(key + ': ' + this._timespans[key].totalTime + 'ms');
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// log extras
|
|
177
|
+
infoLog(this._extras);
|
|
178
|
+
|
|
179
|
+
// log points
|
|
180
|
+
for (const key in this._points) {
|
|
181
|
+
if (this._points[key] != null) {
|
|
182
|
+
infoLog(key + ': ' + this._points[key] + 'ms');
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
markPoint(
|
|
189
|
+
key: string,
|
|
190
|
+
timestamp?: number = getCurrentTimestamp(),
|
|
191
|
+
extras?: Extras,
|
|
192
|
+
) {
|
|
193
|
+
if (this._closed) {
|
|
194
|
+
if (PRINT_TO_CONSOLE && __DEV__) {
|
|
195
|
+
infoLog('PerformanceLogger: markPoint - has closed ignoring: ', key);
|
|
196
|
+
}
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
if (this._points[key] != null) {
|
|
200
|
+
if (PRINT_TO_CONSOLE && __DEV__) {
|
|
201
|
+
infoLog(
|
|
202
|
+
'PerformanceLogger: Attempting to mark a point that has been already logged ',
|
|
203
|
+
key,
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
this._points[key] = timestamp;
|
|
209
|
+
if (extras) {
|
|
210
|
+
this._pointExtras[key] = extras;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
removeExtra(key: string): ?ExtraValue {
|
|
215
|
+
const value = this._extras[key];
|
|
216
|
+
delete this._extras[key];
|
|
217
|
+
return value;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
setExtra(key: string, value: ExtraValue) {
|
|
221
|
+
if (this._closed) {
|
|
222
|
+
if (PRINT_TO_CONSOLE && __DEV__) {
|
|
223
|
+
infoLog('PerformanceLogger: setExtra - has closed ignoring: ', key);
|
|
224
|
+
}
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (this._extras.hasOwnProperty(key)) {
|
|
229
|
+
if (PRINT_TO_CONSOLE && __DEV__) {
|
|
230
|
+
infoLog(
|
|
231
|
+
'PerformanceLogger: Attempting to set an extra that already exists ',
|
|
232
|
+
{key, currentValue: this._extras[key], attemptedValue: value},
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
this._extras[key] = value;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
startTimespan(
|
|
241
|
+
key: string,
|
|
242
|
+
timestamp?: number = getCurrentTimestamp(),
|
|
243
|
+
extras?: Extras,
|
|
244
|
+
) {
|
|
245
|
+
if (this._closed) {
|
|
246
|
+
if (PRINT_TO_CONSOLE && __DEV__) {
|
|
247
|
+
infoLog(
|
|
248
|
+
'PerformanceLogger: startTimespan - has closed ignoring: ',
|
|
249
|
+
key,
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (this._timespans[key]) {
|
|
256
|
+
if (PRINT_TO_CONSOLE && __DEV__) {
|
|
257
|
+
infoLog(
|
|
258
|
+
'PerformanceLogger: Attempting to start a timespan that already exists ',
|
|
259
|
+
key,
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
this._timespans[key] = {
|
|
266
|
+
startTime: timestamp,
|
|
267
|
+
startExtras: extras,
|
|
268
|
+
};
|
|
269
|
+
_cookies[key] = Systrace.beginAsyncEvent(key);
|
|
270
|
+
if (PRINT_TO_CONSOLE) {
|
|
271
|
+
infoLog('PerformanceLogger.js', 'start: ' + key);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
stopTimespan(
|
|
276
|
+
key: string,
|
|
277
|
+
timestamp?: number = getCurrentTimestamp(),
|
|
278
|
+
extras?: Extras,
|
|
279
|
+
) {
|
|
280
|
+
if (this._closed) {
|
|
281
|
+
if (PRINT_TO_CONSOLE && __DEV__) {
|
|
282
|
+
infoLog('PerformanceLogger: stopTimespan - has closed ignoring: ', key);
|
|
283
|
+
}
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const timespan = this._timespans[key];
|
|
288
|
+
if (!timespan || timespan.startTime == null) {
|
|
289
|
+
if (PRINT_TO_CONSOLE && __DEV__) {
|
|
290
|
+
infoLog(
|
|
291
|
+
'PerformanceLogger: Attempting to end a timespan that has not started ',
|
|
292
|
+
key,
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
if (timespan.endTime != null) {
|
|
298
|
+
if (PRINT_TO_CONSOLE && __DEV__) {
|
|
299
|
+
infoLog(
|
|
300
|
+
'PerformanceLogger: Attempting to end a timespan that has already ended ',
|
|
301
|
+
key,
|
|
302
|
+
);
|
|
303
|
+
}
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
timespan.endExtras = extras;
|
|
308
|
+
timespan.endTime = timestamp;
|
|
309
|
+
timespan.totalTime = timespan.endTime - (timespan.startTime || 0);
|
|
310
|
+
if (PRINT_TO_CONSOLE) {
|
|
311
|
+
infoLog('PerformanceLogger.js', 'end: ' + key);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (_cookies[key] != null) {
|
|
315
|
+
Systrace.endAsyncEvent(key, _cookies[key]);
|
|
316
|
+
delete _cookies[key];
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* This function creates performance loggers that can be used to collect and log
|
|
323
|
+
* various performance data such as timespans, points and extras.
|
|
324
|
+
* The loggers need to have minimal overhead since they're used in production.
|
|
325
|
+
*/
|
|
326
|
+
export default function createPerformanceLogger(): IPerformanceLogger {
|
|
327
|
+
return new PerformanceLogger();
|
|
328
|
+
}
|