Show warning when native module for performance marks and measures is not available

Summary:
We're currently showing warnings when we call `performanceObserver.observe` and the native module for performance observers isn't available, but we don't do the same for `performance.mark`, `performance.measure`, etc.

This adds the warning in those cases.

Changelog: [internal]

Reviewed By: rshest

Differential Revision: D41872270

fbshipit-source-id: d720580b930550f27c827a58243579c42a4f6da9
This commit is contained in:
Rubén Norte 2022-12-09 12:15:42 -08:00 коммит произвёл Facebook GitHub Bot
Родитель 4328259f66
Коммит 120e87b86e
1 изменённых файлов: 39 добавлений и 11 удалений

Просмотреть файл

@ -10,6 +10,7 @@
import type {HighResTimeStamp} from './PerformanceObserver';
import warnOnce from '../Utilities/warnOnce';
import NativePerformance from './NativePerformance';
import {PerformanceEntry} from './PerformanceObserver';
@ -72,6 +73,13 @@ export class PerformanceMeasure extends PerformanceEntry {
}
}
function warnNoNativePerformance() {
warnOnce(
'missing-native-performance',
'Missing native implementation of Performance',
);
}
/**
* Partial implementation of the Performance interface for RN,
* corresponding to the standard in
@ -83,12 +91,23 @@ export default class Performance {
markOptions?: PerformanceMarkOptions,
): PerformanceMark {
const mark = new PerformanceMark(markName, markOptions);
NativePerformance?.mark?.(markName, mark.startTime, mark.duration);
if (NativePerformance?.mark) {
NativePerformance.mark(markName, mark.startTime, mark.duration);
} else {
warnNoNativePerformance();
}
return mark;
}
clearMarks(markName?: string): void {
NativePerformance?.clearMarks?.(markName);
if (!NativePerformance?.clearMarks) {
warnNoNativePerformance();
return;
}
NativePerformance.clearMarks(markName);
}
measure(
@ -144,20 +163,29 @@ export default class Performance {
const measure = new PerformanceMeasure(measureName, options);
NativePerformance?.measure?.(
measureName,
startTime,
endTime,
duration,
startMarkName,
endMarkName,
);
if (NativePerformance?.measure) {
NativePerformance.measure(
measureName,
startTime,
endTime,
duration,
startMarkName,
endMarkName,
);
} else {
warnNoNativePerformance();
}
return measure;
}
clearMeasures(measureName?: string): void {
NativePerformance?.clearMeasures?.(measureName);
if (!NativePerformance?.clearMeasures) {
warnNoNativePerformance();
return;
}
NativePerformance.clearMeasures(measureName);
}
now(): HighResTimeStamp {