mirror of
https://github.com/status-im/react-native.git
synced 2025-01-28 10:14:49 +00:00
Rename BridgeProfiling to Systrace for consistency
Summary: public Rename the `BridgeProfiling` JS module to `Systrace`, since it's actually just an API to Systrace markers. This should make it clearer as we add more perf tooling. Reviewed By: jspahrsummers Differential Revision: D2734001 fb-gh-sync-id: 642848fa7340c545067f2a7cf5cef8af1c8a69a2
This commit is contained in:
parent
44cbec28bd
commit
3549ff049c
@ -19,10 +19,10 @@ const BatchedBridge = new MessageQueue(
|
|||||||
|
|
||||||
// TODO: Move these around to solve the cycle in a cleaner way.
|
// TODO: Move these around to solve the cycle in a cleaner way.
|
||||||
|
|
||||||
const BridgeProfiling = require('BridgeProfiling');
|
const Systrace = require('Systrace');
|
||||||
const JSTimersExecution = require('JSTimersExecution');
|
const JSTimersExecution = require('JSTimersExecution');
|
||||||
|
|
||||||
BatchedBridge.registerCallableModule('BridgeProfiling', BridgeProfiling);
|
BatchedBridge.registerCallableModule('Systrace', Systrace);
|
||||||
BatchedBridge.registerCallableModule('JSTimersExecution', JSTimersExecution);
|
BatchedBridge.registerCallableModule('JSTimersExecution', JSTimersExecution);
|
||||||
|
|
||||||
// Wire up the batched bridge on the global object so that we can call into it.
|
// Wire up the batched bridge on the global object so that we can call into it.
|
||||||
|
@ -165,8 +165,8 @@ function setUpWebSockets() {
|
|||||||
|
|
||||||
function setUpProfile() {
|
function setUpProfile() {
|
||||||
if (__DEV__) {
|
if (__DEV__) {
|
||||||
var BridgeProfiling = require('BridgeProfiling');
|
var Systrace = require('Systrace');
|
||||||
BridgeProfiling.swizzleReactPerf();
|
Systrace.swizzleReactPerf();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ var invariant = require('invariant');
|
|||||||
var keyMirror = require('keyMirror');
|
var keyMirror = require('keyMirror');
|
||||||
var performanceNow = require('performanceNow');
|
var performanceNow = require('performanceNow');
|
||||||
var warning = require('warning');
|
var warning = require('warning');
|
||||||
var BridgeProfiling = require('BridgeProfiling');
|
var Systrace = require('Systrace');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JS implementation of timer functions. Must be completely driven by an
|
* JS implementation of timer functions. Must be completely driven by an
|
||||||
@ -113,7 +113,7 @@ var JSTimersExecution = {
|
|||||||
* more immediates are queued up (can be used as a condition a while loop).
|
* more immediates are queued up (can be used as a condition a while loop).
|
||||||
*/
|
*/
|
||||||
callImmediatesPass: function() {
|
callImmediatesPass: function() {
|
||||||
BridgeProfiling.profile('JSTimersExecution.callImmediatesPass()');
|
Systrace.beginEvent('JSTimersExecution.callImmediatesPass()');
|
||||||
|
|
||||||
// The main reason to extract a single pass is so that we can track
|
// The main reason to extract a single pass is so that we can track
|
||||||
// in the system trace
|
// in the system trace
|
||||||
@ -128,7 +128,7 @@ var JSTimersExecution = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BridgeProfiling.profileEnd();
|
Systrace.endEvent();
|
||||||
|
|
||||||
return JSTimersExecution.immediates.length > 0;
|
return JSTimersExecution.immediates.length > 0;
|
||||||
},
|
},
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
let BridgeProfiling = require('BridgeProfiling');
|
let Systrace = require('Systrace');
|
||||||
let ErrorUtils = require('ErrorUtils');
|
let ErrorUtils = require('ErrorUtils');
|
||||||
let JSTimersExecution = require('JSTimersExecution');
|
let JSTimersExecution = require('JSTimersExecution');
|
||||||
|
|
||||||
@ -114,9 +114,9 @@ class MessageQueue {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
__callImmediates() {
|
__callImmediates() {
|
||||||
BridgeProfiling.profile('JSTimersExecution.callImmediates()');
|
Systrace.beginEvent('JSTimersExecution.callImmediates()');
|
||||||
guard(() => JSTimersExecution.callImmediates());
|
guard(() => JSTimersExecution.callImmediates());
|
||||||
BridgeProfiling.profileEnd();
|
Systrace.endEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
__nativeCall(module, method, params, onFail, onSucc) {
|
__nativeCall(module, method, params, onFail, onSucc) {
|
||||||
@ -154,7 +154,7 @@ class MessageQueue {
|
|||||||
method = this._methodTable[module][method];
|
method = this._methodTable[module][method];
|
||||||
module = this._moduleTable[module];
|
module = this._moduleTable[module];
|
||||||
}
|
}
|
||||||
BridgeProfiling.profile(() => `${module}.${method}(${stringifySafe(args)})`);
|
Systrace.beginEvent(() => `${module}.${method}(${stringifySafe(args)})`);
|
||||||
if (__DEV__ && SPY_MODE) {
|
if (__DEV__ && SPY_MODE) {
|
||||||
console.log('N->JS : ' + module + '.' + method + '(' + JSON.stringify(args) + ')');
|
console.log('N->JS : ' + module + '.' + method + '(' + JSON.stringify(args) + ')');
|
||||||
}
|
}
|
||||||
@ -165,11 +165,11 @@ class MessageQueue {
|
|||||||
module
|
module
|
||||||
);
|
);
|
||||||
moduleMethods[method].apply(moduleMethods, args);
|
moduleMethods[method].apply(moduleMethods, args);
|
||||||
BridgeProfiling.profileEnd();
|
Systrace.endEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
__invokeCallback(cbID, args) {
|
__invokeCallback(cbID, args) {
|
||||||
BridgeProfiling.profile(
|
Systrace.beginEvent(
|
||||||
() => `MessageQueue.invokeCallback(${cbID}, ${stringifySafe(args)})`);
|
() => `MessageQueue.invokeCallback(${cbID}, ${stringifySafe(args)})`);
|
||||||
this._lastFlush = new Date().getTime();
|
this._lastFlush = new Date().getTime();
|
||||||
let callback = this._callbacks[cbID];
|
let callback = this._callbacks[cbID];
|
||||||
@ -188,7 +188,7 @@ class MessageQueue {
|
|||||||
this._callbacks[cbID & ~1] = null;
|
this._callbacks[cbID & ~1] = null;
|
||||||
this._callbacks[cbID | 1] = null;
|
this._callbacks[cbID | 1] = null;
|
||||||
callback.apply(null, args);
|
callback.apply(null, args);
|
||||||
BridgeProfiling.profileEnd();
|
Systrace.endEvent();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
* LICENSE file in the root directory of this source tree. An additional grant
|
* LICENSE file in the root directory of this source tree. An additional grant
|
||||||
* of patent rights can be found in the PATENTS file in the same directory.
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
*
|
*
|
||||||
* @providesModule BridgeProfiling
|
* @providesModule Systrace
|
||||||
* @flow
|
* @flow
|
||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
@ -32,7 +32,7 @@ function ReactPerf() {
|
|||||||
return _ReactPerf;
|
return _ReactPerf;
|
||||||
}
|
}
|
||||||
|
|
||||||
var BridgeProfiling = {
|
var Systrace = {
|
||||||
setEnabled(enabled: boolean) {
|
setEnabled(enabled: boolean) {
|
||||||
if (_enabled !== enabled) {
|
if (_enabled !== enabled) {
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
@ -47,9 +47,9 @@ var BridgeProfiling = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* profile/profileEnd for starting and then ending a profile within the same call stack frame
|
* beginEvent/endEvent for starting and then ending a profile within the same call stack frame
|
||||||
**/
|
**/
|
||||||
profile(profileName?: any) {
|
beginEvent(profileName?: any) {
|
||||||
if (_enabled) {
|
if (_enabled) {
|
||||||
profileName = typeof profileName === 'function' ?
|
profileName = typeof profileName === 'function' ?
|
||||||
profileName() : profileName;
|
profileName() : profileName;
|
||||||
@ -57,18 +57,18 @@ var BridgeProfiling = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
profileEnd() {
|
endEvent() {
|
||||||
if (_enabled) {
|
if (_enabled) {
|
||||||
global.nativeTraceEndSection(TRACE_TAG_REACT_APPS);
|
global.nativeTraceEndSection(TRACE_TAG_REACT_APPS);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* profileAsync/profileAsyncEnd for starting and then ending a profile where the end can either
|
* beginAsyncEvent/endAsyncEvent for starting and then ending a profile where the end can either
|
||||||
* occur on another thread or out of the current stack frame, eg await
|
* occur on another thread or out of the current stack frame, eg await
|
||||||
* the returned cookie variable should be used as input into the asyncEnd call to end the profile
|
* the returned cookie variable should be used as input into the endAsyncEvent call to end the profile
|
||||||
**/
|
**/
|
||||||
profileAsync(profileName?: any): any {
|
beginAsyncEvent(profileName?: any): any {
|
||||||
var cookie = _asyncCookie;
|
var cookie = _asyncCookie;
|
||||||
if (_enabled) {
|
if (_enabled) {
|
||||||
_asyncCookie++;
|
_asyncCookie++;
|
||||||
@ -79,7 +79,7 @@ var BridgeProfiling = {
|
|||||||
return cookie;
|
return cookie;
|
||||||
},
|
},
|
||||||
|
|
||||||
profileAsyncEnd(profileName?: any, cookie?: any) {
|
endAsyncEvent(profileName?: any, cookie?: any) {
|
||||||
if (_enabled) {
|
if (_enabled) {
|
||||||
profileName = typeof profileName === 'function' ?
|
profileName = typeof profileName === 'function' ?
|
||||||
profileName() : profileName;
|
profileName() : profileName;
|
||||||
@ -94,15 +94,15 @@ var BridgeProfiling = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var name = objName === 'ReactCompositeComponent' && this.getName() || '';
|
var name = objName === 'ReactCompositeComponent' && this.getName() || '';
|
||||||
BridgeProfiling.profile(`${objName}.${fnName}(${name})`);
|
Systrace.beginEvent(`${objName}.${fnName}(${name})`);
|
||||||
var ret = func.apply(this, arguments);
|
var ret = func.apply(this, arguments);
|
||||||
BridgeProfiling.profileEnd();
|
Systrace.endEvent();
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
swizzleReactPerf() {
|
swizzleReactPerf() {
|
||||||
ReactPerf().injection.injectMeasure(BridgeProfiling.reactPerfMeasure);
|
ReactPerf().injection.injectMeasure(Systrace.reactPerfMeasure);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -111,9 +111,9 @@ var BridgeProfiling = {
|
|||||||
**/
|
**/
|
||||||
attachToRelayProfiler(relayProfiler: RelayProfiler) {
|
attachToRelayProfiler(relayProfiler: RelayProfiler) {
|
||||||
relayProfiler.attachProfileHandler('*', (name) => {
|
relayProfiler.attachProfileHandler('*', (name) => {
|
||||||
var cookie = BridgeProfiling.profileAsync(name);
|
var cookie = Systrace.beginAsyncEvent(name);
|
||||||
return () => {
|
return () => {
|
||||||
BridgeProfiling.profileAsyncEnd(name, cookie);
|
Systrace.endAsyncEvent(name, cookie);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -121,7 +121,7 @@ var BridgeProfiling = {
|
|||||||
/* This is not called by default due to perf overhead but it's useful
|
/* This is not called by default due to perf overhead but it's useful
|
||||||
if you want to find traces which spend too much time in JSON. */
|
if you want to find traces which spend too much time in JSON. */
|
||||||
swizzleJSON() {
|
swizzleJSON() {
|
||||||
BridgeProfiling.measureMethods(JSON, 'JSON', [
|
Systrace.measureMethods(JSON, 'JSON', [
|
||||||
'parse',
|
'parse',
|
||||||
'stringify'
|
'stringify'
|
||||||
]);
|
]);
|
||||||
@ -129,7 +129,7 @@ var BridgeProfiling = {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Measures multiple methods of a class. For example, you can do:
|
* Measures multiple methods of a class. For example, you can do:
|
||||||
* BridgeProfiling.measureMethods(JSON, 'JSON', ['parse', 'stringify']);
|
* Systrace.measureMethods(JSON, 'JSON', ['parse', 'stringify']);
|
||||||
*
|
*
|
||||||
* @param object
|
* @param object
|
||||||
* @param objectName
|
* @param objectName
|
||||||
@ -141,7 +141,7 @@ var BridgeProfiling = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
methodNames.forEach(methodName => {
|
methodNames.forEach(methodName => {
|
||||||
object[methodName] = BridgeProfiling.measure(
|
object[methodName] = Systrace.measure(
|
||||||
objectName,
|
objectName,
|
||||||
methodName,
|
methodName,
|
||||||
object[methodName]
|
object[methodName]
|
||||||
@ -151,7 +151,7 @@ var BridgeProfiling = {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an profiled version of the input function. For example, you can:
|
* Returns an profiled version of the input function. For example, you can:
|
||||||
* JSON.parse = BridgeProfiling.measure('JSON', 'parse', JSON.parse);
|
* JSON.parse = Systrace.measure('JSON', 'parse', JSON.parse);
|
||||||
*
|
*
|
||||||
* @param objName
|
* @param objName
|
||||||
* @param fnName
|
* @param fnName
|
||||||
@ -169,14 +169,14 @@ var BridgeProfiling = {
|
|||||||
return func.apply(this, arguments);
|
return func.apply(this, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
BridgeProfiling.profile(profileName);
|
Systrace.beginEvent(profileName);
|
||||||
var ret = func.apply(this, arguments);
|
var ret = func.apply(this, arguments);
|
||||||
BridgeProfiling.profileEnd();
|
Systrace.endEvent();
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
BridgeProfiling.setEnabled(global.__RCTProfileIsProfiling || false);
|
Systrace.setEnabled(global.__RCTProfileIsProfiling || false);
|
||||||
|
|
||||||
module.exports = BridgeProfiling;
|
module.exports = Systrace;
|
@ -418,7 +418,7 @@ static void RCTInstallJSCProfiler(RCTBridge *bridge, JSContextRef context)
|
|||||||
[self executeBlockOnJavaScriptQueue:^{
|
[self executeBlockOnJavaScriptQueue:^{
|
||||||
BOOL enabled = [notification.name isEqualToString:RCTProfileDidStartProfiling];
|
BOOL enabled = [notification.name isEqualToString:RCTProfileDidStartProfiling];
|
||||||
// TODO: Don't use require, go through the normal execution modes instead. #9317773
|
// TODO: Don't use require, go through the normal execution modes instead. #9317773
|
||||||
NSString *script = [NSString stringWithFormat:@"var p = require('BridgeProfiling') || {}; p.setEnabled && p.setEnabled(%@)", enabled ? @"true" : @"false"];
|
NSString *script = [NSString stringWithFormat:@"var p = require('Systrace') || {}; p.setEnabled && p.setEnabled(%@)", enabled ? @"true" : @"false"];
|
||||||
JSStringRef scriptJSRef = JSStringCreateWithUTF8CString(script.UTF8String);
|
JSStringRef scriptJSRef = JSStringCreateWithUTF8CString(script.UTF8String);
|
||||||
JSEvaluateScript(_context.ctx, scriptJSRef, NULL, NULL, 0, NULL);
|
JSEvaluateScript(_context.ctx, scriptJSRef, NULL, NULL, 0, NULL);
|
||||||
JSStringRelease(scriptJSRef);
|
JSStringRelease(scriptJSRef);
|
||||||
|
@ -13,7 +13,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.facebook.react.bridge.BridgeProfiling;
|
|
||||||
import com.facebook.react.bridge.JavaScriptModule;
|
import com.facebook.react.bridge.JavaScriptModule;
|
||||||
import com.facebook.react.bridge.NativeModule;
|
import com.facebook.react.bridge.NativeModule;
|
||||||
import com.facebook.react.bridge.ReactApplicationContext;
|
import com.facebook.react.bridge.ReactApplicationContext;
|
||||||
@ -95,7 +94,7 @@ import com.facebook.systrace.Systrace;
|
|||||||
RCTEventEmitter.class,
|
RCTEventEmitter.class,
|
||||||
RCTNativeAppEventEmitter.class,
|
RCTNativeAppEventEmitter.class,
|
||||||
AppRegistry.class,
|
AppRegistry.class,
|
||||||
BridgeProfiling.class,
|
com.facebook.react.bridge.Systrace.class,
|
||||||
DebugComponentOwnershipModule.RCTDebugComponentOwnership.class);
|
DebugComponentOwnershipModule.RCTDebugComponentOwnership.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -469,12 +469,12 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
|||||||
private class JSProfilerTraceListener implements TraceListener {
|
private class JSProfilerTraceListener implements TraceListener {
|
||||||
@Override
|
@Override
|
||||||
public void onTraceStarted() {
|
public void onTraceStarted() {
|
||||||
getJSModule(BridgeProfiling.class).setEnabled(true);
|
getJSModule(com.facebook.react.bridge.Systrace.class).setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTraceStopped() {
|
public void onTraceStopped() {
|
||||||
getJSModule(BridgeProfiling.class).setEnabled(false);
|
getJSModule(com.facebook.react.bridge.Systrace.class).setEnabled(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,10 +5,10 @@ package com.facebook.react.bridge;
|
|||||||
import com.facebook.proguard.annotations.DoNotStrip;
|
import com.facebook.proguard.annotations.DoNotStrip;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface to the JavaScript BridgeProfiling Module
|
* Interface to the JavaScript Systrace Module
|
||||||
*/
|
*/
|
||||||
@DoNotStrip
|
@DoNotStrip
|
||||||
public interface BridgeProfiling extends JavaScriptModule{
|
public interface Systrace extends JavaScriptModule{
|
||||||
@DoNotStrip
|
@DoNotStrip
|
||||||
void setEnabled(boolean enabled);
|
void setEnabled(boolean enabled);
|
||||||
}
|
}
|
@ -54,13 +54,13 @@
|
|||||||
// require cycles inside the factory from causing an infinite require loop.
|
// require cycles inside the factory from causing an infinite require loop.
|
||||||
mod.isInitialized = true;
|
mod.isInitialized = true;
|
||||||
|
|
||||||
__DEV__ && BridgeProfiling().profile('JS_require_' + id);
|
__DEV__ && Systrace().beginEvent('JS_require_' + id);
|
||||||
|
|
||||||
// keep args in sync with with defineModuleCode in
|
// keep args in sync with with defineModuleCode in
|
||||||
// packager/react-packager/src/Resolver/index.js
|
// packager/react-packager/src/Resolver/index.js
|
||||||
mod.factory.call(global, global, require, mod.module, mod.module.exports);
|
mod.factory.call(global, global, require, mod.module, mod.module.exports);
|
||||||
|
|
||||||
__DEV__ && BridgeProfiling().profileEnd();
|
__DEV__ && Systrace().endEvent();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
mod.hasError = true;
|
mod.hasError = true;
|
||||||
mod.isInitialized = false;
|
mod.isInitialized = false;
|
||||||
@ -70,14 +70,14 @@
|
|||||||
return mod.module.exports;
|
return mod.module.exports;
|
||||||
}
|
}
|
||||||
|
|
||||||
const BridgeProfiling = __DEV__ && (() => {
|
const Systrace = __DEV__ && (() => {
|
||||||
var _BridgeProfiling;
|
var _Systrace;
|
||||||
try {
|
try {
|
||||||
_BridgeProfiling = require('BridgeProfiling');
|
_Systrace = require('Systrace');
|
||||||
} catch(e) {}
|
} catch(e) {}
|
||||||
|
|
||||||
return _BridgeProfiling && _BridgeProfiling.profile ?
|
return _Systrace && _Systrace.beginEvent ?
|
||||||
_BridgeProfiling : { profile: () => {}, profileEnd: () => {} };
|
_Systrace : { beginEvent: () => {}, endEvent: () => {} };
|
||||||
});
|
});
|
||||||
|
|
||||||
global.__d = define;
|
global.__d = define;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user