mirror of
https://github.com/status-im/react-native.git
synced 2025-02-02 20:53:56 +00:00
Fix systrace profile handling for relay async calls
Reviewed By: astreet Differential Revision: D2700239 fb-gh-sync-id: eaa29d63ee4f7688dd70b0cdc12564a9d479f9ef
This commit is contained in:
parent
0a3694ce48
commit
b6f5c7fa04
@ -22,6 +22,7 @@ var GLOBAL = GLOBAL || this;
|
|||||||
var TRACE_TAG_REACT_APPS = 1 << 17;
|
var TRACE_TAG_REACT_APPS = 1 << 17;
|
||||||
|
|
||||||
var _enabled;
|
var _enabled;
|
||||||
|
var _asyncCookie = 0;
|
||||||
var _ReactPerf = null;
|
var _ReactPerf = null;
|
||||||
function ReactPerf() {
|
function ReactPerf() {
|
||||||
if (!_ReactPerf) {
|
if (!_ReactPerf) {
|
||||||
@ -37,6 +38,9 @@ var BridgeProfiling = {
|
|||||||
ReactPerf().enableMeasure = enabled;
|
ReactPerf().enableMeasure = enabled;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* profile/profileEnd for starting and then ending a profile within the same call stack frame
|
||||||
|
**/
|
||||||
profile(profileName?: any) {
|
profile(profileName?: any) {
|
||||||
if (_enabled) {
|
if (_enabled) {
|
||||||
profileName = typeof profileName === 'function' ?
|
profileName = typeof profileName === 'function' ?
|
||||||
@ -51,6 +55,30 @@ var BridgeProfiling = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* profileAsync/profileAsyncEnd 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
|
||||||
|
**/
|
||||||
|
profileAsync(profileName?: any): any {
|
||||||
|
var cookie = _asyncCookie;
|
||||||
|
if (_enabled) {
|
||||||
|
_asyncCookie++;
|
||||||
|
profileName = typeof profileName === 'function' ?
|
||||||
|
profileName() : profileName;
|
||||||
|
global.nativeTraceBeginAsyncSection(TRACE_TAG_REACT_APPS, profileName, cookie, 0);
|
||||||
|
}
|
||||||
|
return cookie;
|
||||||
|
},
|
||||||
|
|
||||||
|
profileAsyncEnd(profileName?: any, cookie?: any) {
|
||||||
|
if (_enabled) {
|
||||||
|
profileName = typeof profileName === 'function' ?
|
||||||
|
profileName() : profileName;
|
||||||
|
global.nativeTraceEndAsyncSection(TRACE_TAG_REACT_APPS, profileName, cookie, 0);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
reactPerfMeasure(objName: string, fnName: string, func: any): any {
|
reactPerfMeasure(objName: string, fnName: string, func: any): any {
|
||||||
return function (component) {
|
return function (component) {
|
||||||
if (!_enabled) {
|
if (!_enabled) {
|
||||||
@ -69,11 +97,15 @@ var BridgeProfiling = {
|
|||||||
ReactPerf().injection.injectMeasure(BridgeProfiling.reactPerfMeasure);
|
ReactPerf().injection.injectMeasure(BridgeProfiling.reactPerfMeasure);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Relay profiles use await calls, so likely occur out of current stack frame
|
||||||
|
* therefore async variant of profiling is used
|
||||||
|
**/
|
||||||
attachToRelayProfiler(relayProfiler: RelayProfiler) {
|
attachToRelayProfiler(relayProfiler: RelayProfiler) {
|
||||||
relayProfiler.attachProfileHandler('*', (name) => {
|
relayProfiler.attachProfileHandler('*', (name) => {
|
||||||
BridgeProfiling.profile(name);
|
var cookie = BridgeProfiling.profileAsync(name);
|
||||||
return () => {
|
return () => {
|
||||||
BridgeProfiling.profileEnd();
|
BridgeProfiling.profileAsyncEnd(name, cookie);
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user