diff --git a/Libraries/JavaScriptAppEngine/Initialization/InitializeJavaScriptAppEngine.js b/Libraries/JavaScriptAppEngine/Initialization/InitializeJavaScriptAppEngine.js index 5275a2f4f..54b954dc0 100644 --- a/Libraries/JavaScriptAppEngine/Initialization/InitializeJavaScriptAppEngine.js +++ b/Libraries/JavaScriptAppEngine/Initialization/InitializeJavaScriptAppEngine.js @@ -131,8 +131,8 @@ function setUpWebSockets() { } function setupProfile() { - console.profile = console.profile || GLOBAL.consoleProfile || function () {}; - console.profileEnd = console.profileEnd || GLOBAL.consoleProfileEnd || function () {}; + console.profile = console.profile || GLOBAL.nativeTraceBeginSection || function () {}; + console.profileEnd = console.profileEnd || GLOBAL.nativeTraceEndSection || function () {}; require('BridgeProfiling').swizzleReactPerf(); } diff --git a/Libraries/Utilities/BridgeProfiling.js b/Libraries/Utilities/BridgeProfiling.js index 7f6b8860c..94ff3b3c6 100644 --- a/Libraries/Utilities/BridgeProfiling.js +++ b/Libraries/Utilities/BridgeProfiling.js @@ -12,26 +12,20 @@ 'use strict'; var GLOBAL = GLOBAL || this; +var TRACE_TAG_REACT_APPS = 1 << 17; var BridgeProfiling = { - profile(profileName?: any, args?: any) { + profile(profileName?: any) { if (GLOBAL.__BridgeProfilingIsProfiling) { - if (args) { - try { - args = JSON.stringify(args); - } catch(err) { - args = err.message; - } - } profileName = typeof profileName === 'function' ? profileName() : profileName; - console.profile(profileName, args); + console.profile(TRACE_TAG_REACT_APPS, profileName); } }, profileEnd() { if (GLOBAL.__BridgeProfilingIsProfiling) { - console.profileEnd(); + console.profileEnd(TRACE_TAG_REACT_APPS); } }, @@ -39,7 +33,7 @@ var BridgeProfiling = { var ReactPerf = require('ReactPerf'); var originalMeasure = ReactPerf.measure; ReactPerf.measure = function (objName, fnName, func) { - func = originalMeasure.call(ReactPerf, objName, fnName, func); + func = originalMeasure.apply(ReactPerf, arguments); return function (component) { if (GLOBAL.__BridgeProfilingIsProfiling) { var name = this._instance && this._instance.constructor && diff --git a/React/Executors/RCTContextExecutor.m b/React/Executors/RCTContextExecutor.m index e002d4b54..8b051fa67 100644 --- a/React/Executors/RCTContextExecutor.m +++ b/React/Executors/RCTContextExecutor.m @@ -136,38 +136,6 @@ static JSValueRef RCTNoop(JSContextRef context, __unused JSObjectRef object, __u return JSValueMakeUndefined(context); } -#if RCT_DEV - -static JSValueRef RCTConsoleProfile(JSContextRef context, __unused JSObjectRef object, __unused JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], __unused JSValueRef *exception) -{ - static int profileCounter = 1; - NSString *profileName; - - if (argumentCount > 0) { - profileName = RCTJSValueToNSString(context, arguments[0]); - } else { - profileName = [NSString stringWithFormat:@"Profile %d", profileCounter++]; - } - - id profileInfo = (id)kCFNull; - if (argumentCount > 1 && !JSValueIsUndefined(context, arguments[1])) { - profileInfo = @[RCTJSValueToNSString(context, arguments[1])]; - } - - RCTProfileBeginEvent(0, profileName, profileInfo); - - return JSValueMakeUndefined(context); -} - -static JSValueRef RCTConsoleProfileEnd(JSContextRef context, __unused JSObjectRef object, __unused JSObjectRef thisObject, __unused size_t argumentCount, __unused const JSValueRef arguments[], __unused JSValueRef *exception) -{ - RCTProfileEndEvent(0, @"console", nil); - - return JSValueMakeUndefined(context); -} - -#endif - static NSString *RCTJSValueToNSString(JSContextRef context, JSValueRef value) { JSStringRef JSString = JSValueToStringCopy(context, value, NULL); @@ -193,6 +161,51 @@ static NSError *RCTNSErrorFromJSError(JSContextRef context, JSValueRef jsError) return [NSError errorWithDomain:@"JS" code:1 userInfo:@{NSLocalizedDescriptionKey: errorMessage, NSLocalizedFailureReasonErrorKey: details}]; } +#if RCT_DEV + +static JSValueRef RCTNativeTraceBeginSection(JSContextRef context, __unused JSObjectRef object, __unused JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], __unused JSValueRef *exception) +{ + static int profileCounter = 1; + NSString *profileName; + double tag = 0; + + if (argumentCount > 0) { + if (JSValueIsNumber(context, arguments[0])) { + tag = JSValueToNumber(context, arguments[0], NULL); + } else { + profileName = RCTJSValueToNSString(context, arguments[0]); + } + } else { + profileName = [NSString stringWithFormat:@"Profile %d", profileCounter++]; + } + + if (argumentCount > 1 && JSValueIsString(context, arguments[1])) { + profileName = RCTJSValueToNSString(context, arguments[1]); + } + + if (profileName) { + RCTProfileBeginEvent(tag, profileName, nil); + } + + return JSValueMakeUndefined(context); +} + +static JSValueRef RCTNativeTraceEndSection(JSContextRef context, __unused JSObjectRef object, __unused JSObjectRef thisObject, __unused size_t argumentCount, __unused const JSValueRef arguments[], __unused JSValueRef *exception) +{ + if (argumentCount > 0) { + JSValueRef *error = NULL; + double tag = JSValueToNumber(context, arguments[0], error); + + if (error == NULL) { + RCTProfileEndEvent((uint64_t)tag, @"console", nil); + } + } + + return JSValueMakeUndefined(context); +} + +#endif + + (void)runRunLoopThread { @autoreleasepool { @@ -266,8 +279,8 @@ static NSError *RCTNSErrorFromJSError(JSContextRef context, JSValueRef jsError) [strongSelf _addNativeHook:RCTNativeLoggingHook withName:"nativeLoggingHook"]; [strongSelf _addNativeHook:RCTNoop withName:"noop"]; #if RCT_DEV - [strongSelf _addNativeHook:RCTConsoleProfile withName:"consoleProfile"]; - [strongSelf _addNativeHook:RCTConsoleProfileEnd withName:"consoleProfileEnd"]; + [strongSelf _addNativeHook:RCTNativeTraceBeginSection withName:"nativeTraceBeginSection"]; + [strongSelf _addNativeHook:RCTNativeTraceEndSection withName:"nativeTraceEndSection"]; #if RCT_JSC_PROFILER void *JSCProfiler = dlopen(RCT_JSC_PROFILER_DYLIB, RTLD_NOW);