From 60640485e1a44c2ff8c77cc375c9fcb61f23c50a Mon Sep 17 00:00:00 2001 From: Alexey Lang Date: Thu, 28 Feb 2019 03:35:59 -0800 Subject: [PATCH] Introduce PerformanceLoggerContext and use it with renderApplication Reviewed By: sahrens Differential Revision: D14167646 fbshipit-source-id: 3f8dd27ba1c8866471e2af493c4cc0bc84706042 --- Libraries/ReactNative/AppRegistry.js | 11 ++++++++- Libraries/ReactNative/renderApplication.js | 24 ++++++++++++------- .../Utilities/PerformanceLoggerContext.js | 20 ++++++++++++++++ 3 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 Libraries/Utilities/PerformanceLoggerContext.js diff --git a/Libraries/ReactNative/AppRegistry.js b/Libraries/ReactNative/AppRegistry.js index 19483c98a..c401dec04 100644 --- a/Libraries/ReactNative/AppRegistry.js +++ b/Libraries/ReactNative/AppRegistry.js @@ -18,6 +18,8 @@ const SceneTracker = require('SceneTracker'); const infoLog = require('infoLog'); const invariant = require('invariant'); const renderApplication = require('renderApplication'); +const createPerformanceLogger = require('createPerformanceLogger'); +import type {IPerformanceLogger} from 'createPerformanceLogger'; type Task = (taskData: any) => Promise; type TaskProvider = () => Task; @@ -30,6 +32,7 @@ type TaskCancelProvider = () => TaskCanceller; export type ComponentProvider = () => React$ComponentType; export type ComponentProviderInstrumentationHook = ( component: ComponentProvider, + scopedPerformanceLogger: IPerformanceLogger, ) => React$ComponentType; export type AppConfig = { appKey: string, @@ -101,15 +104,21 @@ const AppRegistry = { componentProvider: ComponentProvider, section?: boolean, ): string { + let scopedPerformanceLogger = createPerformanceLogger(); runnables[appKey] = { componentProvider, run: appParameters => { renderApplication( - componentProviderInstrumentationHook(componentProvider), + componentProviderInstrumentationHook( + componentProvider, + scopedPerformanceLogger, + ), appParameters.initialProps, appParameters.rootTag, wrapperComponentProvider && wrapperComponentProvider(appParameters), appParameters.fabric, + false, + scopedPerformanceLogger, ); }, }; diff --git a/Libraries/ReactNative/renderApplication.js b/Libraries/ReactNative/renderApplication.js index ad3ec9944..3fa9deff7 100644 --- a/Libraries/ReactNative/renderApplication.js +++ b/Libraries/ReactNative/renderApplication.js @@ -11,7 +11,9 @@ 'use strict'; const AppContainer = require('AppContainer'); -import PerformanceLogger from 'GlobalPerformanceLogger'; +import GlobalPerformanceLogger from 'GlobalPerformanceLogger'; +import type {IPerformanceLogger} from 'createPerformanceLogger'; +import PerformanceLoggerContext from 'PerformanceLoggerContext'; const React = require('React'); const ReactFabricIndicator = require('ReactFabricIndicator'); @@ -27,16 +29,20 @@ function renderApplication( WrapperComponent?: ?React.ComponentType<*>, fabric?: boolean, showFabricIndicator?: boolean, + scopedPerformanceLogger?: IPerformanceLogger, ) { invariant(rootTag, 'Expect to have a valid rootTag, instead got ', rootTag); let renderable = ( - - - {fabric === true && showFabricIndicator === true ? ( - - ) : null} - + + + + {fabric === true && showFabricIndicator === true ? ( + + ) : null} + + ); // If the root component is async, the user probably wants the initial render @@ -54,13 +60,13 @@ function renderApplication( renderable = {renderable}; } - PerformanceLogger.startTimespan('renderApplication_React_render'); + GlobalPerformanceLogger.startTimespan('renderApplication_React_render'); if (fabric) { require('ReactFabric').render(renderable, rootTag); } else { require('ReactNative').render(renderable, rootTag); } - PerformanceLogger.stopTimespan('renderApplication_React_render'); + GlobalPerformanceLogger.stopTimespan('renderApplication_React_render'); } module.exports = renderApplication; diff --git a/Libraries/Utilities/PerformanceLoggerContext.js b/Libraries/Utilities/PerformanceLoggerContext.js new file mode 100644 index 000000000..e00b61a74 --- /dev/null +++ b/Libraries/Utilities/PerformanceLoggerContext.js @@ -0,0 +1,20 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + * @format + */ + +'use strict'; + +import * as React from 'react'; +import GlobalPerformanceLogger from 'GlobalPerformanceLogger'; +import type {IPerformanceLogger} from 'createPerformanceLogger'; + +const PerformanceLoggerContext: React.Context< + IPerformanceLogger, +> = React.createContext(GlobalPerformanceLogger); +export default PerformanceLoggerContext;