Revert D14186694: [RN] Use global or scoped performance loggers everywhere
Differential Revision: D14186694 Original commit changeset: 062c76eea8fc fbshipit-source-id: 6d99b94d21da6df4375e342fdecceeebf05959d5
This commit is contained in:
Родитель
136666e2e7
Коммит
efd28bdc84
|
@ -44,12 +44,12 @@ if (__DEV__) {
|
|||
require('setUpDeveloperTools');
|
||||
}
|
||||
|
||||
const GlobalPerformanceLogger = require('GlobalPerformanceLogger');
|
||||
// We could just call GlobalPerformanceLogger.markPoint at the top of the file,
|
||||
// but then we'd be excluding the time it took to require the logger.
|
||||
const PerformanceLogger = require('GlobalPerformanceLogger');
|
||||
// We could just call PerformanceLogger.markPoint at the top of the file,
|
||||
// but then we'd be excluding the time it took to require PerformanceLogger.
|
||||
// Instead, we just use Date.now and backdate the timestamp.
|
||||
GlobalPerformanceLogger.markPoint(
|
||||
PerformanceLogger.markPoint(
|
||||
'initializeCore_start',
|
||||
GlobalPerformanceLogger.currentTimestamp() - (Date.now() - start),
|
||||
PerformanceLogger.currentTimestamp() - (Date.now() - start),
|
||||
);
|
||||
GlobalPerformanceLogger.markPoint('initializeCore_end');
|
||||
PerformanceLogger.markPoint('initializeCore_end');
|
||||
|
|
|
@ -30,7 +30,7 @@ BatchedBridge.registerLazyCallableModule('RCTDeviceEventEmitter', () =>
|
|||
BatchedBridge.registerLazyCallableModule('RCTNativeAppEventEmitter', () =>
|
||||
require('RCTNativeAppEventEmitter'),
|
||||
);
|
||||
BatchedBridge.registerLazyCallableModule('GlobalPerformanceLogger', () =>
|
||||
BatchedBridge.registerLazyCallableModule('PerformanceLogger', () =>
|
||||
require('GlobalPerformanceLogger'),
|
||||
);
|
||||
BatchedBridge.registerLazyCallableModule('JSDevSupportModule', () =>
|
||||
|
|
|
@ -10,21 +10,15 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
const PerformanceLoggerContext = require('PerformanceLoggerContext');
|
||||
const GlobalPerformanceLogger = require('GlobalPerformanceLogger');
|
||||
const PerformanceLogger = require('GlobalPerformanceLogger');
|
||||
const React = require('React');
|
||||
const StyleSheet = require('StyleSheet');
|
||||
const Text = require('Text');
|
||||
const View = require('View');
|
||||
|
||||
class PerformanceOverlay extends React.Component<{}> {
|
||||
static contextType = PerformanceLoggerContext;
|
||||
render() {
|
||||
const scopedPerformanceLogger = this.context;
|
||||
const perfLogs = {
|
||||
...scopedPerformanceLogger.getTimespans(),
|
||||
...GlobalPerformanceLogger.getTimespans(),
|
||||
};
|
||||
const perfLogs = PerformanceLogger.getTimespans();
|
||||
const items = [];
|
||||
|
||||
for (const key in perfLogs) {
|
||||
|
|
|
@ -11,14 +11,5 @@
|
|||
|
||||
const createPerformanceLogger = require('createPerformanceLogger');
|
||||
|
||||
/**
|
||||
* This is a global shared instance of IPerformanceLogger that is created with
|
||||
* createPerformanceLogger().
|
||||
* Any metric that you log with this logger will be attached to *all* in-flight
|
||||
* TTI/TTRC events so you should use it carefully. If you want to log something
|
||||
* from your React component you should use PerformanceLoggerContext instead.
|
||||
* This logger should be used only for global stuff like load_bundle events.
|
||||
*/
|
||||
const GlobalPerformanceLogger = createPerformanceLogger();
|
||||
|
||||
module.exports = GlobalPerformanceLogger;
|
||||
|
|
|
@ -14,14 +14,7 @@ import * as React from 'react';
|
|||
import GlobalPerformanceLogger from 'GlobalPerformanceLogger';
|
||||
import type {IPerformanceLogger} from 'createPerformanceLogger';
|
||||
|
||||
/**
|
||||
* This is a React Context that provides a scoped instance of IPerformanceLogger.
|
||||
* We wrap every <AppContainer /> with a Provider for this context so the logger
|
||||
* should be available everywhere in your components.
|
||||
* See React docs about using Context: https://reactjs.org/docs/context.html
|
||||
*/
|
||||
const PerformanceLoggerContext: React.Context<
|
||||
IPerformanceLogger,
|
||||
> = React.createContext(GlobalPerformanceLogger);
|
||||
|
||||
module.exports = PerformanceLoggerContext;
|
||||
export default PerformanceLoggerContext;
|
||||
|
|
|
@ -42,7 +42,6 @@ export type IPerformanceLogger = {
|
|||
markPoint(string, number | void): void,
|
||||
getPoints(): {[key: string]: number},
|
||||
logPoints(): void,
|
||||
logEverything(): void,
|
||||
};
|
||||
|
||||
const _cookies: {[key: string]: number} = {};
|
||||
|
@ -243,12 +242,6 @@ function createPerformanceLogger(): IPerformanceLogger {
|
|||
infoLog(key + ': ' + this._points[key] + 'ms');
|
||||
}
|
||||
},
|
||||
|
||||
logEverything() {
|
||||
this.logTimespans();
|
||||
this.logExtras();
|
||||
this.logPoints();
|
||||
},
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
/**
|
||||
* 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';
|
||||
|
||||
const React = require('React');
|
||||
const PerformanceLoggerContext = require('PerformanceLoggerContext');
|
||||
import type {IPerformanceLogger} from 'createPerformanceLogger';
|
||||
|
||||
export type PerformanceLoggerContextProps = {
|
||||
scopedPerformanceLogger: IPerformanceLogger,
|
||||
};
|
||||
|
||||
/**
|
||||
* If you already have one React Context on your component, you can't use
|
||||
* PerformanceLoggerContext without a consumer for it. This function helps to
|
||||
* do that. Here's how to use it:
|
||||
* 1) Intersect Props of your component with PerformanceLoggerContextProps.
|
||||
* 2) Call this function with Props and RequiredProps of your component.
|
||||
* You can figure out RequiredProps as $Diff<Props, DefaultProps>.
|
||||
*/
|
||||
function withPerformanceLoggerContext<
|
||||
TProps: PerformanceLoggerContextProps,
|
||||
TRequiredProps: PerformanceLoggerContextProps,
|
||||
>(
|
||||
Component: React.ComponentType<TProps>,
|
||||
): React.ComponentType<$Diff<TRequiredProps, PerformanceLoggerContextProps>> {
|
||||
return class WrappedComponent extends React.Component<
|
||||
$Diff<TProps, PerformanceLoggerContextProps>,
|
||||
> {
|
||||
render() {
|
||||
return (
|
||||
<PerformanceLoggerContext.Consumer>
|
||||
{scopedPerformanceLogger => (
|
||||
<Component
|
||||
{...this.props}
|
||||
scopedPerformanceLogger={scopedPerformanceLogger}
|
||||
/>
|
||||
)}
|
||||
</PerformanceLoggerContext.Consumer>
|
||||
);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = withPerformanceLoggerContext;
|
Загрузка…
Ссылка в новой задаче