mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Migrate createPerformanceLogger to ESM and export getCurrentTimestamp
Summary: Changelog: [internal] Reviewed By: lunaleaps Differential Revision: D24476172 fbshipit-source-id: 5afa58935a6a3a8e1d2d0d0bb8b3b28840fc17f4
This commit is contained in:
committed by
Facebook GitHub Bot
parent
d238da71aa
commit
5c498e3d6b
@@ -10,12 +10,13 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
import createPerformanceLogger from '../../Utilities/createPerformanceLogger';
|
||||
|
||||
jest.unmock('../../Utilities/Platform');
|
||||
jest.mock('../../Utilities/GlobalPerformanceLogger');
|
||||
|
||||
const Platform = require('../../Utilities/Platform');
|
||||
const GlobalPerformanceLogger = require('../../Utilities/GlobalPerformanceLogger');
|
||||
const createPerformanceLogger = require('../../Utilities/createPerformanceLogger');
|
||||
let requestId = 1;
|
||||
|
||||
function setRequestId(id) {
|
||||
|
||||
@@ -18,9 +18,9 @@ const SceneTracker = require('../Utilities/SceneTracker');
|
||||
const infoLog = require('../Utilities/infoLog');
|
||||
const invariant = require('invariant');
|
||||
const renderApplication = require('./renderApplication');
|
||||
const createPerformanceLogger = require('../Utilities/createPerformanceLogger');
|
||||
import type {IPerformanceLogger} from '../Utilities/createPerformanceLogger';
|
||||
|
||||
import createPerformanceLogger from '../Utilities/createPerformanceLogger';
|
||||
import NativeHeadlessJsTaskSupport from './NativeHeadlessJsTaskSupport';
|
||||
import HeadlessJsTaskError from './HeadlessJsTaskError';
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
const createPerformanceLogger = require('./createPerformanceLogger');
|
||||
|
||||
import createPerformanceLogger from './createPerformanceLogger';
|
||||
import type {IPerformanceLogger} from './createPerformanceLogger';
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,8 +13,6 @@
|
||||
const Systrace = require('../Performance/Systrace');
|
||||
|
||||
const infoLog = require('./infoLog');
|
||||
const performanceNow: () => number =
|
||||
global.nativeQPLTimestamp ?? global.performance.now.bind(global.performance);
|
||||
|
||||
export type Timespan = {
|
||||
startTime: number,
|
||||
@@ -60,6 +58,9 @@ const _cookies: {[key: string]: number, ...} = {};
|
||||
|
||||
const PRINT_TO_CONSOLE: false = false; // Type as false to prevent accidentally committing `true`;
|
||||
|
||||
export const getCurrentTimestamp: () => number =
|
||||
global.nativeQPLTimestamp ?? global.performance.now.bind(global.performance);
|
||||
|
||||
class PerformanceLogger implements IPerformanceLogger {
|
||||
_timespans: {[key: string]: ?Timespan} = {};
|
||||
_extras: {[key: string]: ?ExtraValue} = {};
|
||||
@@ -139,7 +140,7 @@ class PerformanceLogger implements IPerformanceLogger {
|
||||
}
|
||||
|
||||
currentTimestamp() {
|
||||
return performanceNow();
|
||||
return getCurrentTimestamp();
|
||||
}
|
||||
|
||||
getExtras() {
|
||||
@@ -203,7 +204,7 @@ class PerformanceLogger implements IPerformanceLogger {
|
||||
}
|
||||
return;
|
||||
}
|
||||
this._points[key] = timestamp ?? performanceNow();
|
||||
this._points[key] = timestamp ?? getCurrentTimestamp();
|
||||
if (extras) {
|
||||
this._pointExtras[key] = extras;
|
||||
}
|
||||
@@ -257,7 +258,7 @@ class PerformanceLogger implements IPerformanceLogger {
|
||||
}
|
||||
|
||||
this._timespans[key] = {
|
||||
startTime: performanceNow(),
|
||||
startTime: getCurrentTimestamp(),
|
||||
startExtras: extras,
|
||||
};
|
||||
_cookies[key] = Systrace.beginAsyncEvent(key);
|
||||
@@ -295,7 +296,7 @@ class PerformanceLogger implements IPerformanceLogger {
|
||||
}
|
||||
|
||||
timespan.endExtras = extras;
|
||||
timespan.endTime = performanceNow();
|
||||
timespan.endTime = getCurrentTimestamp();
|
||||
timespan.totalTime = timespan.endTime - (timespan.startTime || 0);
|
||||
if (PRINT_TO_CONSOLE) {
|
||||
infoLog('PerformanceLogger.js', 'end: ' + key);
|
||||
@@ -313,8 +314,6 @@ class PerformanceLogger implements IPerformanceLogger {
|
||||
* various performance data such as timespans, points and extras.
|
||||
* The loggers need to have minimal overhead since they're used in production.
|
||||
*/
|
||||
function createPerformanceLogger(): IPerformanceLogger {
|
||||
export default function createPerformanceLogger(): IPerformanceLogger {
|
||||
return new PerformanceLogger();
|
||||
}
|
||||
|
||||
module.exports = createPerformanceLogger;
|
||||
|
||||
Reference in New Issue
Block a user