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:
Tadeu Zagallo 2015-12-11 03:49:15 -08:00 committed by facebook-github-bot-7
parent 44cbec28bd
commit 3549ff049c
10 changed files with 53 additions and 54 deletions

View File

@ -19,10 +19,10 @@ const BatchedBridge = new MessageQueue(
// TODO: Move these around to solve the cycle in a cleaner way.
const BridgeProfiling = require('BridgeProfiling');
const Systrace = require('Systrace');
const JSTimersExecution = require('JSTimersExecution');
BatchedBridge.registerCallableModule('BridgeProfiling', BridgeProfiling);
BatchedBridge.registerCallableModule('Systrace', Systrace);
BatchedBridge.registerCallableModule('JSTimersExecution', JSTimersExecution);
// Wire up the batched bridge on the global object so that we can call into it.

View File

@ -165,8 +165,8 @@ function setUpWebSockets() {
function setUpProfile() {
if (__DEV__) {
var BridgeProfiling = require('BridgeProfiling');
BridgeProfiling.swizzleReactPerf();
var Systrace = require('Systrace');
Systrace.swizzleReactPerf();
}
}

View File

@ -14,7 +14,7 @@ var invariant = require('invariant');
var keyMirror = require('keyMirror');
var performanceNow = require('performanceNow');
var warning = require('warning');
var BridgeProfiling = require('BridgeProfiling');
var Systrace = require('Systrace');
/**
* 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).
*/
callImmediatesPass: function() {
BridgeProfiling.profile('JSTimersExecution.callImmediatesPass()');
Systrace.beginEvent('JSTimersExecution.callImmediatesPass()');
// The main reason to extract a single pass is so that we can track
// in the system trace
@ -128,7 +128,7 @@ var JSTimersExecution = {
}
}
BridgeProfiling.profileEnd();
Systrace.endEvent();
return JSTimersExecution.immediates.length > 0;
},

View File

@ -13,7 +13,7 @@
'use strict';
let BridgeProfiling = require('BridgeProfiling');
let Systrace = require('Systrace');
let ErrorUtils = require('ErrorUtils');
let JSTimersExecution = require('JSTimersExecution');
@ -114,9 +114,9 @@ class MessageQueue {
*/
__callImmediates() {
BridgeProfiling.profile('JSTimersExecution.callImmediates()');
Systrace.beginEvent('JSTimersExecution.callImmediates()');
guard(() => JSTimersExecution.callImmediates());
BridgeProfiling.profileEnd();
Systrace.endEvent();
}
__nativeCall(module, method, params, onFail, onSucc) {
@ -154,7 +154,7 @@ class MessageQueue {
method = this._methodTable[module][method];
module = this._moduleTable[module];
}
BridgeProfiling.profile(() => `${module}.${method}(${stringifySafe(args)})`);
Systrace.beginEvent(() => `${module}.${method}(${stringifySafe(args)})`);
if (__DEV__ && SPY_MODE) {
console.log('N->JS : ' + module + '.' + method + '(' + JSON.stringify(args) + ')');
}
@ -165,11 +165,11 @@ class MessageQueue {
module
);
moduleMethods[method].apply(moduleMethods, args);
BridgeProfiling.profileEnd();
Systrace.endEvent();
}
__invokeCallback(cbID, args) {
BridgeProfiling.profile(
Systrace.beginEvent(
() => `MessageQueue.invokeCallback(${cbID}, ${stringifySafe(args)})`);
this._lastFlush = new Date().getTime();
let callback = this._callbacks[cbID];
@ -188,7 +188,7 @@ class MessageQueue {
this._callbacks[cbID & ~1] = null;
this._callbacks[cbID | 1] = null;
callback.apply(null, args);
BridgeProfiling.profileEnd();
Systrace.endEvent();
}
/**
@ -244,7 +244,7 @@ class MessageQueue {
this._genLookup(config, moduleID, moduleTable, methodTable);
});
}
_genLookup(config, moduleID, moduleTable, methodTable) {
if (!config) {
return;
@ -287,15 +287,15 @@ class MessageQueue {
module[methodName] = this._genMethod(moduleID, methodID, methodType);
});
Object.assign(module, constants);
if (!constants && !methods && !asyncMethods) {
module.moduleID = moduleID;
}
this.RemoteModules[moduleName] = module;
return module;
}
_genMethod(module, method, type) {
let fn = null;
let self = this;

View File

@ -6,7 +6,7 @@
* 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.
*
* @providesModule BridgeProfiling
* @providesModule Systrace
* @flow
*/
'use strict';
@ -32,7 +32,7 @@ function ReactPerf() {
return _ReactPerf;
}
var BridgeProfiling = {
var Systrace = {
setEnabled(enabled: boolean) {
if (_enabled !== 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) {
profileName = typeof profileName === 'function' ?
profileName() : profileName;
@ -57,18 +57,18 @@ var BridgeProfiling = {
}
},
profileEnd() {
endEvent() {
if (_enabled) {
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
* 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;
if (_enabled) {
_asyncCookie++;
@ -79,7 +79,7 @@ var BridgeProfiling = {
return cookie;
},
profileAsyncEnd(profileName?: any, cookie?: any) {
endAsyncEvent(profileName?: any, cookie?: any) {
if (_enabled) {
profileName = typeof profileName === 'function' ?
profileName() : profileName;
@ -94,15 +94,15 @@ var BridgeProfiling = {
}
var name = objName === 'ReactCompositeComponent' && this.getName() || '';
BridgeProfiling.profile(`${objName}.${fnName}(${name})`);
Systrace.beginEvent(`${objName}.${fnName}(${name})`);
var ret = func.apply(this, arguments);
BridgeProfiling.profileEnd();
Systrace.endEvent();
return ret;
};
},
swizzleReactPerf() {
ReactPerf().injection.injectMeasure(BridgeProfiling.reactPerfMeasure);
ReactPerf().injection.injectMeasure(Systrace.reactPerfMeasure);
},
/**
@ -111,9 +111,9 @@ var BridgeProfiling = {
**/
attachToRelayProfiler(relayProfiler: RelayProfiler) {
relayProfiler.attachProfileHandler('*', (name) => {
var cookie = BridgeProfiling.profileAsync(name);
var cookie = Systrace.beginAsyncEvent(name);
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
if you want to find traces which spend too much time in JSON. */
swizzleJSON() {
BridgeProfiling.measureMethods(JSON, 'JSON', [
Systrace.measureMethods(JSON, 'JSON', [
'parse',
'stringify'
]);
@ -129,7 +129,7 @@ var BridgeProfiling = {
/**
* 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 objectName
@ -141,7 +141,7 @@ var BridgeProfiling = {
}
methodNames.forEach(methodName => {
object[methodName] = BridgeProfiling.measure(
object[methodName] = Systrace.measure(
objectName,
methodName,
object[methodName]
@ -151,7 +151,7 @@ var BridgeProfiling = {
/**
* 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 fnName
@ -169,14 +169,14 @@ var BridgeProfiling = {
return func.apply(this, arguments);
}
BridgeProfiling.profile(profileName);
Systrace.beginEvent(profileName);
var ret = func.apply(this, arguments);
BridgeProfiling.profileEnd();
Systrace.endEvent();
return ret;
};
},
};
BridgeProfiling.setEnabled(global.__RCTProfileIsProfiling || false);
Systrace.setEnabled(global.__RCTProfileIsProfiling || false);
module.exports = BridgeProfiling;
module.exports = Systrace;

View File

@ -418,7 +418,7 @@ static void RCTInstallJSCProfiler(RCTBridge *bridge, JSContextRef context)
[self executeBlockOnJavaScriptQueue:^{
BOOL enabled = [notification.name isEqualToString:RCTProfileDidStartProfiling];
// 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);
JSEvaluateScript(_context.ctx, scriptJSRef, NULL, NULL, 0, NULL);
JSStringRelease(scriptJSRef);

View File

@ -13,7 +13,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.facebook.react.bridge.BridgeProfiling;
import com.facebook.react.bridge.JavaScriptModule;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
@ -95,7 +94,7 @@ import com.facebook.systrace.Systrace;
RCTEventEmitter.class,
RCTNativeAppEventEmitter.class,
AppRegistry.class,
BridgeProfiling.class,
com.facebook.react.bridge.Systrace.class,
DebugComponentOwnershipModule.RCTDebugComponentOwnership.class);
}

View File

@ -469,12 +469,12 @@ public class CatalystInstanceImpl implements CatalystInstance {
private class JSProfilerTraceListener implements TraceListener {
@Override
public void onTraceStarted() {
getJSModule(BridgeProfiling.class).setEnabled(true);
getJSModule(com.facebook.react.bridge.Systrace.class).setEnabled(true);
}
@Override
public void onTraceStopped() {
getJSModule(BridgeProfiling.class).setEnabled(false);
getJSModule(com.facebook.react.bridge.Systrace.class).setEnabled(false);
}
}

View File

@ -5,10 +5,10 @@ package com.facebook.react.bridge;
import com.facebook.proguard.annotations.DoNotStrip;
/**
* Interface to the JavaScript BridgeProfiling Module
* Interface to the JavaScript Systrace Module
*/
@DoNotStrip
public interface BridgeProfiling extends JavaScriptModule{
public interface Systrace extends JavaScriptModule{
@DoNotStrip
void setEnabled(boolean enabled);
}

View File

@ -54,13 +54,13 @@
// require cycles inside the factory from causing an infinite require loop.
mod.isInitialized = true;
__DEV__ && BridgeProfiling().profile('JS_require_' + id);
__DEV__ && Systrace().beginEvent('JS_require_' + id);
// keep args in sync with with defineModuleCode in
// packager/react-packager/src/Resolver/index.js
mod.factory.call(global, global, require, mod.module, mod.module.exports);
__DEV__ && BridgeProfiling().profileEnd();
__DEV__ && Systrace().endEvent();
} catch (e) {
mod.hasError = true;
mod.isInitialized = false;
@ -70,14 +70,14 @@
return mod.module.exports;
}
const BridgeProfiling = __DEV__ && (() => {
var _BridgeProfiling;
const Systrace = __DEV__ && (() => {
var _Systrace;
try {
_BridgeProfiling = require('BridgeProfiling');
_Systrace = require('Systrace');
} catch(e) {}
return _BridgeProfiling && _BridgeProfiling.profile ?
_BridgeProfiling : { profile: () => {}, profileEnd: () => {} };
return _Systrace && _Systrace.beginEvent ?
_Systrace : { beginEvent: () => {}, endEvent: () => {} };
});
global.__d = define;