diff --git a/Libraries/Performance/SamplingProfiler.js b/Libraries/Performance/SamplingProfiler.js index 75982f51b..de8c2c0ac 100644 --- a/Libraries/Performance/SamplingProfiler.js +++ b/Libraries/Performance/SamplingProfiler.js @@ -11,10 +11,10 @@ */ 'use strict'; -var SamplingProfiler = { +const SamplingProfiler = { poke: function (token: number): void { - var error = null; - var result = null; + let error = null; + let result = null; try { result = global.pokeSamplingProfiler(); if (result === null) { @@ -27,8 +27,9 @@ var SamplingProfiler = { 'Error occured when restarting Sampling Profiler: ' + e.toString()); error = e.toString(); } - require('NativeModules').JSCSamplingProfiler.operationComplete( - token, result, error); + + const {JSCSamplingProfiler} = require('NativeModules'); + JSCSamplingProfiler.operationComplete(token, result, error); }, }; diff --git a/React/React.xcodeproj/project.pbxproj b/React/React.xcodeproj/project.pbxproj index 1162bb572..6a94c8d54 100644 --- a/React/React.xcodeproj/project.pbxproj +++ b/React/React.xcodeproj/project.pbxproj @@ -979,6 +979,10 @@ 3DE4F8681DF85D8E00B9E5A0 /* YGEnums.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 130A77031DF767AF001F9587 /* YGEnums.h */; }; 3DE4F8691DF85D8E00B9E5A0 /* YGMacros.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 130A77041DF767AF001F9587 /* YGMacros.h */; }; 3DE4F86A1DF85D8E00B9E5A0 /* Yoga.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = 130A77081DF767AF001F9587 /* Yoga.h */; }; + 3DF1BE821F26576400068F1A /* JSCTracing.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3DF1BE801F26576400068F1A /* JSCTracing.cpp */; }; + 3DF1BE831F26576400068F1A /* JSCTracing.h in Headers */ = {isa = PBXBuildFile; fileRef = 3DF1BE811F26576400068F1A /* JSCTracing.h */; }; + 3DF1BE841F26577000068F1A /* JSCTracing.h in Headers */ = {isa = PBXBuildFile; fileRef = 3DF1BE811F26576400068F1A /* JSCTracing.h */; }; + 3DF1BE851F26577300068F1A /* JSCTracing.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3DF1BE801F26576400068F1A /* JSCTracing.cpp */; }; 3DFE0D161DF8574D00459392 /* YGEnums.h in Headers */ = {isa = PBXBuildFile; fileRef = 130A77031DF767AF001F9587 /* YGEnums.h */; }; 3DFE0D171DF8574D00459392 /* YGMacros.h in Headers */ = {isa = PBXBuildFile; fileRef = 130A77041DF767AF001F9587 /* YGMacros.h */; }; 3DFE0D181DF8574D00459392 /* YGNodeList.h in Headers */ = {isa = PBXBuildFile; fileRef = 130A77061DF767AF001F9587 /* YGNodeList.h */; }; @@ -1929,6 +1933,8 @@ 3D92B10D1E0369AD0018521A /* Value.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Value.h; sourceTree = ""; }; 3DB910701C74B21600838BBE /* RCTWebSocketObserverProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTWebSocketObserverProtocol.h; sourceTree = ""; }; 3DCC92BA1E94458B00EF89A8 /* YGEnums.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = YGEnums.c; sourceTree = ""; }; + 3DF1BE801F26576400068F1A /* JSCTracing.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCTracing.cpp; sourceTree = ""; }; + 3DF1BE811F26576400068F1A /* JSCTracing.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSCTracing.h; sourceTree = ""; }; 3EDCA8A21D3591E700450C31 /* RCTErrorCustomizer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTErrorCustomizer.h; sourceTree = ""; }; 3EDCA8A31D3591E700450C31 /* RCTErrorInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTErrorInfo.h; sourceTree = ""; }; 3EDCA8A41D3591E700450C31 /* RCTErrorInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTErrorInfo.m; sourceTree = ""; }; @@ -2633,13 +2639,12 @@ 3D92B0A71E03699D0018521A /* CxxModule.h */, 3D92B0A81E03699D0018521A /* CxxNativeModule.cpp */, 3D92B0A91E03699D0018521A /* CxxNativeModule.h */, - 3D92B0AB1E03699D0018521A /* JSExecutor.h */, 3D92B0AE1E03699D0018521A /* Instance.cpp */, 3D92B0AF1E03699D0018521A /* Instance.h */, 3D92B0B01E03699D0018521A /* JsArgumentHelpers-inl.h */, 3D92B0B11E03699D0018521A /* JsArgumentHelpers.h */, - 3D7454781E54757500E74ADD /* JSBigString.h */, 27B958731E57587D0096647A /* JSBigString.cpp */, + 3D7454781E54757500E74ADD /* JSBigString.h */, AC70D2EB1DE48A22002E6351 /* JSBundleType.cpp */, 3D3CD8F51DE5FB2300167DC4 /* JSBundleType.h */, 3D92B0B21E03699D0018521A /* JSCExecutor.cpp */, @@ -2654,8 +2659,11 @@ 3D92B0BD1E03699D0018521A /* JSCPerfStats.h */, 3D92B0BE1E03699D0018521A /* JSCSamplingProfiler.cpp */, 3D92B0BF1E03699D0018521A /* JSCSamplingProfiler.h */, + 3DF1BE801F26576400068F1A /* JSCTracing.cpp */, + 3DF1BE811F26576400068F1A /* JSCTracing.h */, 3D92B0C21E03699D0018521A /* JSCUtils.cpp */, 3D92B0C31E03699D0018521A /* JSCUtils.h */, + 3D92B0AB1E03699D0018521A /* JSExecutor.h */, 3D92B0C61E03699D0018521A /* JSIndexedRAMBundle.cpp */, 3D92B0C71E03699D0018521A /* JSIndexedRAMBundle.h */, 3D92B0C81E03699D0018521A /* JSModulesUnbundle.h */, @@ -2795,6 +2803,7 @@ 3D302F661DF828F800D6DDAE /* RCTFPSGraph.h in Headers */, 3D302F681DF828F800D6DDAE /* RCTMacros.h in Headers */, 3D302F691DF828F800D6DDAE /* RCTProfile.h in Headers */, + 3DF1BE841F26577000068F1A /* JSCTracing.h in Headers */, 3D302F6A1DF828F800D6DDAE /* RCTActivityIndicatorView.h in Headers */, 3D302F6B1DF828F800D6DDAE /* RCTActivityIndicatorViewManager.h in Headers */, 3D7BFD301EA8E3FA008DFB7A /* RCTSRWebSocket.h in Headers */, @@ -3096,6 +3105,7 @@ 3D80DA6B1DF820620028D040 /* RCTFont.h in Headers */, 3D80DA701DF820620028D040 /* RCTModalHostView.h in Headers */, 3D80DA711DF820620028D040 /* RCTModalHostViewController.h in Headers */, + 3DF1BE831F26576400068F1A /* JSCTracing.h in Headers */, 3D80DA721DF820620028D040 /* RCTModalHostViewManager.h in Headers */, 13134C9C1E296B2A00B9F3CB /* RCTCxxModule.h in Headers */, 3D80DA731DF820620028D040 /* RCTNavigator.h in Headers */, @@ -3613,6 +3623,7 @@ 130E3D8B1E6A083900ACE484 /* RCTDevSettings.mm in Sources */, 2D3B5ED81D9B098A00451313 /* RCTNavigatorManager.m in Sources */, 2D3B5E951D9B087C00451313 /* RCTAssert.m in Sources */, + 3DF1BE851F26577300068F1A /* JSCTracing.cpp in Sources */, 2D3B5EB61D9B091400451313 /* RCTExceptionsManager.m in Sources */, 2D3B5EEB1D9B09D000451313 /* RCTTabBarItem.m in Sources */, 2D3B5ED41D9B097D00451313 /* RCTModalHostView.m in Sources */, @@ -3873,6 +3884,7 @@ 13B080051A6947C200A75B9A /* RCTScrollView.m in Sources */, A2440AA31DF8D854006E7BFC /* RCTReloadCommand.m in Sources */, 19F0AD731F1DE7C400E4949F /* RCTShadowView+Hierarchy.m in Sources */, + 3DF1BE821F26576400068F1A /* JSCTracing.cpp in Sources */, 6577348F1EE8354A00A0E9EA /* RCTInspector.mm in Sources */, E9B20B7B1B500126007A2DA7 /* RCTAccessibilityManager.m in Sources */, 13A0C2891B74F71200B29F6F /* RCTDevLoadingView.m in Sources */, diff --git a/ReactCommon/cxxreact/BUCK b/ReactCommon/cxxreact/BUCK index c5f162688..35a7b6ce7 100644 --- a/ReactCommon/cxxreact/BUCK +++ b/ReactCommon/cxxreact/BUCK @@ -120,7 +120,6 @@ rn_xplat_cxx_library( fbandroid_preprocessor_flags = [ "-DWITH_JSC_EXTRA_TRACING=1", "-DWITH_JSC_MEMORY_PRESSURE=1", - "-DWITH_REACT_INTERNAL_SETTINGS=1", "-DWITH_FB_MEMORY_PROFILING=1", ], fbandroid_visibility = [ diff --git a/ReactCommon/cxxreact/JSCExecutor.cpp b/ReactCommon/cxxreact/JSCExecutor.cpp index d8b06fd86..826120595 100644 --- a/ReactCommon/cxxreact/JSCExecutor.cpp +++ b/ReactCommon/cxxreact/JSCExecutor.cpp @@ -4,64 +4,45 @@ #include #include +#include #include #include #include -#include -#include -#include -#include -#include -#include #include #include +#include +#include +#include +#include +#include +#include #include #include #include "JSBigString.h" #include "JSBundleType.h" -#include "Platform.h" -#include "SystraceSection.h" +#include "JSCLegacyTracing.h" +#include "JSCMemory.h" #include "JSCNativeModules.h" +#include "JSCPerfStats.h" #include "JSCSamplingProfiler.h" +#include "JSCTracing.h" #include "JSCUtils.h" #include "JSModulesUnbundle.h" #include "ModuleRegistry.h" +#include "Platform.h" #include "RecoverableError.h" +#include "SystraceSection.h" -#ifdef WITH_INSPECTOR -#include -#endif - -#if defined(WITH_JSC_EXTRA_TRACING) || (DEBUG && defined(WITH_FBSYSTRACE)) -#include "JSCTracing.h" -#endif - -#ifdef WITH_JSC_EXTRA_TRACING -#include "JSCLegacyTracing.h" -#endif - -#if !defined(__APPLE__) && defined(WITH_JSC_EXTRA_TRACING) -#include -#endif - -#ifdef WITH_JSC_MEMORY_PRESSURE +#if defined(WITH_JSC_MEMORY_PRESSURE) #include #endif -#ifdef WITH_FB_MEMORY_PROFILING -#include "JSCMemory.h" -#endif - #if defined(WITH_FB_JSC_TUNING) && defined(__ANDROID__) #include #endif -#ifdef JSC_HAS_PERF_STATS_API -#include "JSCPerfStats.h" -#endif - namespace facebook { namespace react { @@ -173,15 +154,17 @@ void JSCExecutor::setContextName(const std::string& name) { JSC_JSGlobalContextSetName(m_context, jsName); } -#ifdef WITH_INSPECTOR static bool canUseInspector(JSContextRef context) { +#ifdef WITH_INSPECTOR #if defined(__APPLE__) return isCustomJSCPtr(context); // WITH_INSPECTOR && Apple #else return true; // WITH_INSPECTOR && Android #endif -} +#else + return false; // !WITH_INSPECTOR #endif +} void JSCExecutor::initOnJSVMThread() throw(JSException) { SystraceSection s("JSCExecutor::initOnJSVMThread"); @@ -216,13 +199,11 @@ void JSCExecutor::initOnJSVMThread() throw(JSException) { // Add a pointer to ourselves so we can retrieve it later in our hooks Object::getGlobalObject(m_context).setPrivate(this); -#ifdef WITH_INSPECTOR if (canUseInspector(m_context)) { const std::string ownerId = m_jscConfig.getDefault("OwnerIdentity", "main").getString(); IInspector* pInspector = JSC_JSInspectorGetInstance(true); pInspector->registerGlobalContext(ownerId, m_context); } -#endif installNativeHook<&JSCExecutor::nativeFlushQueueImmediate>("nativeFlushQueueImmediate"); installNativeHook<&JSCExecutor::nativeCallSyncHook>("nativeCallSyncHook"); @@ -234,29 +215,16 @@ void JSCExecutor::initOnJSVMThread() throw(JSException) { installGlobalFunction(m_context, "nativeInjectHMRUpdate", nativeInjectHMRUpdate); #endif - #if defined(WITH_JSC_EXTRA_TRACING) || (DEBUG && defined(WITH_FBSYSTRACE)) addNativeTracingHooks(m_context); - #endif - - #ifdef WITH_JSC_EXTRA_TRACING addNativeTracingLegacyHooks(m_context); - #endif + addJSCMemoryHooks(m_context); + addJSCPerfStatsHooks(m_context); JSCNativeHooks::installPerfHooks(m_context); - #if defined(__APPLE__) || defined(WITH_JSC_EXTRA_TRACING) if (JSC_JSSamplingProfilerEnabled(m_context)) { initSamplingProfilerOnMainJSCThread(m_context); } - #endif - - #ifdef WITH_FB_MEMORY_PROFILING - addNativeMemoryHooks(m_context); - #endif - - #ifdef JSC_HAS_PERF_STATS_API - addJSCPerfStatsHooks(m_context); - #endif } void JSCExecutor::terminateOnJSVMThread() { @@ -265,12 +233,10 @@ void JSCExecutor::terminateOnJSVMThread() { Object::getGlobalObject(context).setPrivate(nullptr); m_nativeModules.reset(); -#ifdef WITH_INSPECTOR if (canUseInspector(context)) { IInspector* pInspector = JSC_JSInspectorGetInstance(true); pInspector->unregisterGlobalContext(context); } -#endif JSC_JSGlobalContextRelease(context); } @@ -535,17 +501,17 @@ void JSCExecutor::setGlobalVariable(std::string propName, std::unique_ptr script) { -#if defined(WITH_FBJSCEXTENSIONS) + #if defined(WITH_FBJSCEXTENSIONS) const JSBigString* string = script.release(); auto jsString = JSStringCreateAdoptingExternal(string->c_str(), string->size(), (void*)string, [](void* s) { delete static_cast(s); }); return String::adopt(m_context, jsString); -#else + #else return script->isAscii() ? String::createExpectingAscii(m_context, script->c_str(), script->size()) : String(m_context, script->c_str()); -#endif + #endif } void* JSCExecutor::getJavaScriptContext() { @@ -585,9 +551,8 @@ JSValueRef JSCExecutor::getNativeModule(JSObjectRef object, JSStringRef property } JSValueRef JSCExecutor::nativeRequire( - size_t argumentCount, - const JSValueRef arguments[]) { - + size_t argumentCount, + const JSValueRef arguments[]) { if (argumentCount != 1) { throw std::invalid_argument("Got wrong number of args"); } diff --git a/ReactCommon/cxxreact/JSCLegacyTracing.cpp b/ReactCommon/cxxreact/JSCLegacyTracing.cpp index 5c5a1e6d7..e2783055c 100644 --- a/ReactCommon/cxxreact/JSCLegacyTracing.cpp +++ b/ReactCommon/cxxreact/JSCLegacyTracing.cpp @@ -1,20 +1,22 @@ // Copyright 2004-present Facebook. All Rights Reserved. -#ifdef WITH_JSC_EXTRA_TRACING - #include "JSCLegacyTracing.h" +#if defined(WITH_JSC_EXTRA_TRACING) + #include #include #include #include -#include "JSCTracing.h" - static const char *ENABLED_FBSYSTRACE_PROFILE_NAME = "__fbsystrace__"; using namespace facebook::react; +static int64_t int64FromJSValue(JSContextRef ctx, JSValueRef value, JSValueRef* exception) { + return static_cast(JSC_JSValueToNumber(ctx, value, exception)); +} + static JSValueRef nativeTraceBeginLegacy( JSContextRef ctx, JSObjectRef function, @@ -23,18 +25,13 @@ static JSValueRef nativeTraceBeginLegacy( const JSValueRef arguments[], JSValueRef* exception) { if (FBSYSTRACE_LIKELY(argumentCount >= 1)) { - uint64_t tag = tracingTagFromJSValue(ctx, arguments[0], exception); + uint64_t tag = int64FromJSValue(ctx, arguments[0], exception); if (!fbsystrace_is_tracing(tag)) { return Value::makeUndefined(ctx); } } - String title(ctx, ENABLED_FBSYSTRACE_PROFILE_NAME); - #if WITH_REACT_INTERNAL_SETTINGS - JSStartProfiling(ctx, title, true); - #else - JSStartProfiling(ctx, title); - #endif + JSStartProfiling(ctx, String(ctx, ENABLED_FBSYSTRACE_PROFILE_NAME), true); return Value::makeUndefined(ctx); } @@ -47,26 +44,27 @@ static JSValueRef nativeTraceEndLegacy( const JSValueRef arguments[], JSValueRef* exception) { if (FBSYSTRACE_LIKELY(argumentCount >= 1)) { - uint64_t tag = tracingTagFromJSValue(ctx, arguments[0], exception); + uint64_t tag = int64FromJSValue(ctx, arguments[0], exception); if (!fbsystrace_is_tracing(tag)) { return Value::makeUndefined(ctx); } } - String title(ctx, ENABLED_FBSYSTRACE_PROFILE_NAME); - JSEndProfiling(ctx, title); + JSEndProfiling(ctx, String(ctx, ENABLED_FBSYSTRACE_PROFILE_NAME)); return Value::makeUndefined(ctx); } +#endif + namespace facebook { namespace react { void addNativeTracingLegacyHooks(JSGlobalContextRef ctx) { +#if defined(WITH_JSC_EXTRA_TRACING) installGlobalFunction(ctx, "nativeTraceBeginLegacy", nativeTraceBeginLegacy); installGlobalFunction(ctx, "nativeTraceEndLegacy", nativeTraceEndLegacy); +#endif } } } - -#endif diff --git a/ReactCommon/cxxreact/JSCLegacyTracing.h b/ReactCommon/cxxreact/JSCLegacyTracing.h index 31863ddb9..2803c4302 100644 --- a/ReactCommon/cxxreact/JSCLegacyTracing.h +++ b/ReactCommon/cxxreact/JSCLegacyTracing.h @@ -2,8 +2,6 @@ #pragma once -#if defined(WITH_JSC_EXTRA_TRACING) - #include namespace facebook { @@ -12,5 +10,3 @@ namespace react { void addNativeTracingLegacyHooks(JSGlobalContextRef ctx); } } - -#endif diff --git a/ReactCommon/cxxreact/JSCMemory.cpp b/ReactCommon/cxxreact/JSCMemory.cpp index 825547c83..976c98114 100644 --- a/ReactCommon/cxxreact/JSCMemory.cpp +++ b/ReactCommon/cxxreact/JSCMemory.cpp @@ -20,16 +20,15 @@ static JSValueRef nativeCaptureHeap( const JSValueRef arguments[], JSValueRef* exception) { if (argumentCount < 1) { - if (exception) { - *exception = Value::makeError( - ctx, - "nativeCaptureHeap requires the path to save the capture"); - } - return Value::makeUndefined(ctx); + if (exception) { + *exception = Value::makeError( + ctx, + "nativeCaptureHeap requires the path to save the capture"); + } + return Value::makeUndefined(ctx); } - auto outputFilename = String::adopt( - ctx, JSValueToStringCopy(ctx, arguments[0], exception)); + auto outputFilename = Value(ctx, arguments[0]).toString(); JSCaptureHeap(ctx, outputFilename.str().c_str(), exception); return Value::makeUndefined(ctx); } @@ -39,11 +38,10 @@ static JSValueRef nativeCaptureHeap( namespace facebook { namespace react { -void addNativeMemoryHooks(JSGlobalContextRef ctx) { +void addJSCMemoryHooks(JSGlobalContextRef ctx) { #ifdef WITH_FB_MEMORY_PROFILING installGlobalFunction(ctx, "nativeCaptureHeap", nativeCaptureHeap); #endif // WITH_FB_MEMORY_PROFILING - } } } diff --git a/ReactCommon/cxxreact/JSCMemory.h b/ReactCommon/cxxreact/JSCMemory.h index 3d7a75191..899bba82b 100644 --- a/ReactCommon/cxxreact/JSCMemory.h +++ b/ReactCommon/cxxreact/JSCMemory.h @@ -7,6 +7,6 @@ namespace facebook { namespace react { -void addNativeMemoryHooks(JSGlobalContextRef ctx); +void addJSCMemoryHooks(JSGlobalContextRef ctx); } } diff --git a/ReactCommon/cxxreact/JSCPerfStats.cpp b/ReactCommon/cxxreact/JSCPerfStats.cpp index 1729cfd91..8f3e0d6b2 100644 --- a/ReactCommon/cxxreact/JSCPerfStats.cpp +++ b/ReactCommon/cxxreact/JSCPerfStats.cpp @@ -20,17 +20,16 @@ static JSValueRef nativeGetHeapStats( JSHeapStats heapStats = {0}; JSGetHeapStats(ctx, &heapStats); - auto result = facebook::react::Object::create(ctx); - result.setProperty("size", {ctx, Value::makeNumber(ctx, heapStats.size)}); - result.setProperty("extra_size", {ctx, Value::makeNumber(ctx, heapStats.extraSize)}); - result.setProperty("capacity", {ctx, Value::makeNumber(ctx, heapStats.capacity)}); - result.setProperty("object_count", {ctx, Value::makeNumber(ctx, heapStats.objectCount)}); - result.setProperty("object_size", {ctx, Value::makeNumber(ctx, heapStats.objectSizeAfterLastCollect)}); - result.setProperty("object_capacity", {ctx, Value::makeNumber(ctx, heapStats.objectCapacityAfterLastCollect)}); - result.setProperty("block_size", {ctx, Value::makeNumber(ctx, heapStats.blockSize)}); - result.setProperty("malloc_size", {ctx, Value::makeNumber(ctx, heapStats.mallocSize)}); - - return (JSObjectRef) result; + auto result = Object::create(ctx); + result.setProperty("size", Value::makeNumber(ctx, heapStats.size)); + result.setProperty("extra_size", Value::makeNumber(ctx, heapStats.extraSize)); + result.setProperty("capacity", Value::makeNumber(ctx, heapStats.capacity)); + result.setProperty("object_count", Value::makeNumber(ctx, heapStats.objectCount)); + result.setProperty("object_size", Value::makeNumber(ctx, heapStats.objectSizeAfterLastCollect)); + result.setProperty("object_capacity", Value::makeNumber(ctx, heapStats.objectCapacityAfterLastCollect)); + result.setProperty("block_size", Value::makeNumber(ctx, heapStats.blockSize)); + result.setProperty("malloc_size", Value::makeNumber(ctx, heapStats.mallocSize)); + return static_cast(result); } static JSValueRef nativeGetGCStats( @@ -43,15 +42,10 @@ static JSValueRef nativeGetGCStats( JSGCStats gcStats = {0}; JSGetGCStats(ctx, &gcStats); - auto result = facebook::react::Object::create(ctx); - result.setProperty( - "last_full_gc_length", - {ctx, Value::makeNumber(ctx, gcStats.lastFullGCLength)}); - result.setProperty( - "last_eden_gc_length", - {ctx, Value::makeNumber(ctx, gcStats.lastEdenGCLength)}); - - return (JSObjectRef) result; + auto result = Object::create(ctx); + result.setProperty("last_full_gc_length", Value::makeNumber(ctx, gcStats.lastFullGCLength)); + result.setProperty("last_eden_gc_length", Value::makeNumber(ctx, gcStats.lastEdenGCLength)); + return static_cast(result); } #endif diff --git a/ReactCommon/cxxreact/JSCSamplingProfiler.cpp b/ReactCommon/cxxreact/JSCSamplingProfiler.cpp index 300036dd0..813a19c68 100644 --- a/ReactCommon/cxxreact/JSCSamplingProfiler.cpp +++ b/ReactCommon/cxxreact/JSCSamplingProfiler.cpp @@ -2,18 +2,8 @@ #include "JSCSamplingProfiler.h" -#include -#include #include -#include -#ifndef __APPLE__ -#include -#endif - -namespace facebook { -namespace react { -namespace { static JSValueRef pokeSamplingProfiler( JSContextRef ctx, JSObjectRef function, @@ -23,7 +13,9 @@ static JSValueRef pokeSamplingProfiler( JSValueRef* exception) { return JSC_JSPokeSamplingProfiler(ctx); } -} + +namespace facebook { +namespace react { void initSamplingProfilerOnMainJSCThread(JSGlobalContextRef ctx) { JSC_JSStartSamplingProfilingOnMainJSCThread(ctx); @@ -33,5 +25,4 @@ void initSamplingProfilerOnMainJSCThread(JSGlobalContextRef ctx) { installGlobalFunction(ctx, "pokeSamplingProfiler", pokeSamplingProfiler); } -} -} +} } diff --git a/ReactCommon/cxxreact/JSCSamplingProfiler.h b/ReactCommon/cxxreact/JSCSamplingProfiler.h index 5705a3a5d..bed56cbc2 100644 --- a/ReactCommon/cxxreact/JSCSamplingProfiler.h +++ b/ReactCommon/cxxreact/JSCSamplingProfiler.h @@ -8,5 +8,5 @@ namespace facebook { namespace react { void initSamplingProfilerOnMainJSCThread(JSGlobalContextRef ctx); -} -} + +} } diff --git a/ReactCommon/cxxreact/JSCTracing.cpp b/ReactCommon/cxxreact/JSCTracing.cpp index f629ebd44..fb5d88146 100644 --- a/ReactCommon/cxxreact/JSCTracing.cpp +++ b/ReactCommon/cxxreact/JSCTracing.cpp @@ -1,13 +1,20 @@ // Copyright 2004-present Facebook. All Rights Reserved. -#if defined(WITH_JSC_EXTRA_TRACING) || DEBUG - #include "JSCTracing.h" +#if defined(WITH_FBSYSTRACE) && (defined(WITH_JSC_EXTRA_TRACING) || DEBUG) +#define USE_JSCTRACING 1 +#else +#define USE_JSCTRACING 0 +#endif + +#if USE_JSCTRACING + #include #include #include #include + #include #include #include @@ -15,13 +22,8 @@ using std::min; using namespace facebook::react; -static int64_t int64FromJSValue( - JSContextRef ctx, - JSValueRef value, - JSValueRef* exception) { - (void)exception; - int64_t num = (int64_t)JSC_JSValueToNumber(ctx, value, NULL); - return num; +static int64_t int64FromJSValue(JSContextRef ctx, JSValueRef value, JSValueRef* exception) { + return static_cast(JSC_JSValueToNumber(ctx, value, exception)); } static size_t copyTruncatedAsciiChars( @@ -94,7 +96,7 @@ static JSValueRef nativeTraceBeginSection( return Value::makeUndefined(ctx); } - uint64_t tag = facebook::react::tracingTagFromJSValue(ctx, arguments[0], exception); + uint64_t tag = int64FromJSValue(ctx, arguments[0], exception); if (!fbsystrace_is_tracing(tag)) { return Value::makeUndefined(ctx); } @@ -134,7 +136,7 @@ static JSValueRef nativeTraceEndSection( return Value::makeUndefined(ctx); } - uint64_t tag = facebook::react::tracingTagFromJSValue(ctx, arguments[0], exception); + uint64_t tag = int64FromJSValue(ctx, arguments[0], exception); if (!fbsystrace_is_tracing(tag)) { return Value::makeUndefined(ctx); } @@ -164,8 +166,6 @@ static JSValueRef beginOrEndAsync( bool isEnd, bool isFlow, JSContextRef ctx, - JSObjectRef function, - JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { @@ -178,7 +178,7 @@ static JSValueRef beginOrEndAsync( return Value::makeUndefined(ctx); } - uint64_t tag = facebook::react::tracingTagFromJSValue(ctx, arguments[0], exception); + uint64_t tag = int64FromJSValue(ctx, arguments[0], exception); if (!fbsystrace_is_tracing(tag)) { return Value::makeUndefined(ctx); } @@ -241,7 +241,7 @@ static JSValueRef stageAsync( return Value::makeUndefined(ctx); } - uint64_t tag = facebook::react::tracingTagFromJSValue(ctx, arguments[0], exception); + uint64_t tag = int64FromJSValue(ctx, arguments[0], exception); if (!fbsystrace_is_tracing(tag)) { return Value::makeUndefined(ctx); } @@ -272,15 +272,8 @@ static JSValueRef nativeTraceBeginAsyncSection( size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { - return beginOrEndAsync( - false /* isEnd */, - false /* isFlow */, - ctx, - function, - thisObject, - argumentCount, - arguments, - exception); + return beginOrEndAsync(false /* isEnd */, false /* isFlow */, + ctx, argumentCount, arguments, exception); } static JSValueRef nativeTraceEndAsyncSection( @@ -290,15 +283,8 @@ static JSValueRef nativeTraceEndAsyncSection( size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { - return beginOrEndAsync( - true /* isEnd */, - false /* isFlow */, - ctx, - function, - thisObject, - argumentCount, - arguments, - exception); + return beginOrEndAsync(true /* isEnd */, false /* isFlow */, + ctx, argumentCount, arguments, exception); } static JSValueRef nativeTraceAsyncSectionStage( @@ -325,15 +311,8 @@ static JSValueRef nativeTraceBeginAsyncFlow( size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { - return beginOrEndAsync( - false /* isEnd */, - true /* isFlow */, - ctx, - function, - thisObject, - argumentCount, - arguments, - exception); + return beginOrEndAsync(false /* isEnd */, true /* isFlow */, + ctx, argumentCount, arguments, exception); } static JSValueRef nativeTraceEndAsyncFlow( @@ -343,15 +322,8 @@ static JSValueRef nativeTraceEndAsyncFlow( size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { - return beginOrEndAsync( - true /* isEnd */, - true /* isFlow */, - ctx, - function, - thisObject, - argumentCount, - arguments, - exception); + return beginOrEndAsync(true /* isEnd */, true /* isFlow */, + ctx, argumentCount, arguments, exception); } static JSValueRef nativeTraceAsyncFlowStage( @@ -387,7 +359,7 @@ static JSValueRef nativeTraceCounter( return Value::makeUndefined(ctx); } - uint64_t tag = facebook::react::tracingTagFromJSValue(ctx, arguments[0], exception); + uint64_t tag = int64FromJSValue(ctx, arguments[0], exception); if (!fbsystrace_is_tracing(tag)) { return Value::makeUndefined(ctx); } @@ -403,20 +375,13 @@ static JSValueRef nativeTraceCounter( return Value::makeUndefined(ctx); } +#endif + namespace facebook { namespace react { -uint64_t tracingTagFromJSValue( - JSContextRef ctx, - JSValueRef value, - JSValueRef* exception) { - // XXX validate that this is a lossless conversion. - // XXX should we just have separate functions for bridge, infra, and apps, - // then drop this argument to save time? - return static_cast(Value(ctx, value).asNumber()); -} - void addNativeTracingHooks(JSGlobalContextRef ctx) { +#if USE_JSCTRACING installGlobalFunction(ctx, "nativeTraceBeginSection", nativeTraceBeginSection); installGlobalFunction(ctx, "nativeTraceEndSection", nativeTraceEndSection); installGlobalFunction(ctx, "nativeTraceBeginAsyncSection", nativeTraceBeginAsyncSection); @@ -426,8 +391,7 @@ void addNativeTracingHooks(JSGlobalContextRef ctx) { installGlobalFunction(ctx, "nativeTraceEndAsyncFlow", nativeTraceEndAsyncFlow); installGlobalFunction(ctx, "nativeTraceAsyncFlowStage", nativeTraceAsyncFlowStage); installGlobalFunction(ctx, "nativeTraceCounter", nativeTraceCounter); +#endif } } } - -#endif diff --git a/ReactCommon/cxxreact/JSCTracing.h b/ReactCommon/cxxreact/JSCTracing.h index 21753e7fb..63af9aa9d 100644 --- a/ReactCommon/cxxreact/JSCTracing.h +++ b/ReactCommon/cxxreact/JSCTracing.h @@ -2,17 +2,11 @@ #pragma once -#if defined(WITH_JSC_EXTRA_TRACING) || DEBUG - -#include #include namespace facebook { namespace react { -uint64_t tracingTagFromJSValue(JSContextRef ctx, JSValueRef value, JSValueRef* exception); void addNativeTracingHooks(JSGlobalContextRef ctx); } } - -#endif