diff --git a/ReactAndroid/src/main/jni/react/BUCK b/ReactAndroid/src/main/jni/react/BUCK index 58f3f2085c..e8908b8cb8 100644 --- a/ReactAndroid/src/main/jni/react/BUCK +++ b/ReactAndroid/src/main/jni/react/BUCK @@ -24,7 +24,9 @@ def react_library(**kwargs): react_native_target('jni/react/jni:jni'), ], deps = DEPS + JSC_DEPS, - preprocessor_flags = PREPROCESSOR_FLAGS, + preprocessor_flags = PREPROCESSOR_FLAGS + [ + '-DWITH_FB_MEMORY_PROFILING=1', + ], **kwargs ) diff --git a/ReactAndroid/src/main/jni/react/JSCMemory.cpp b/ReactAndroid/src/main/jni/react/JSCMemory.cpp index f0316bd2a4..4ca7d6ea53 100644 --- a/ReactAndroid/src/main/jni/react/JSCMemory.cpp +++ b/ReactAndroid/src/main/jni/react/JSCMemory.cpp @@ -10,74 +10,7 @@ #ifdef WITH_FB_MEMORY_PROFILING -static JSValueRef nativeEnableAllocationTag( - JSContextRef ctx, - JSObjectRef function, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef* exception) { - - if (argumentCount < 1) { - if (exception) { - *exception = facebook::react::makeJSCException( - ctx, - "nativeEnableAllocationTag requires a single boolean argument"); - } - return JSValueMakeUndefined(ctx); - } - - JSEnableAllocationTag(ctx, JSValueToBoolean(ctx, arguments[0])); - return JSValueMakeUndefined(ctx); -} - -static JSValueRef nativeAllocationPushTag( - JSContextRef ctx, - JSObjectRef function, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef* exception) { - std::string marker; - - if (argumentCount < 1) { - if (exception) { - *exception = facebook::react::makeJSCException( - ctx, - "nativeAllocationPushTag requires at least 1 argument"); - } - return JSValueMakeUndefined(ctx); - } - - JSStringRef tag = JSValueToStringCopy(ctx, arguments[0], exception); - JSPushAllocationTag(ctx, facebook::react::String::ref(tag).str().c_str()); - JSStringRelease(tag); - return JSValueMakeUndefined(ctx); -} - -static JSValueRef nativeAllocationPopTag( - JSContextRef ctx, - JSObjectRef function, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef* exception) { - JSPopAllocationTag(ctx); - return JSValueMakeUndefined(ctx); -} - -static JSValueRef nativeForceSyncGC( - JSContextRef ctx, - JSObjectRef function, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef* exception) { - JSSynchronousGarbageCollectForDebugging(ctx); - return JSValueMakeUndefined(ctx); -} - -static JSValueRef nativeCaptureStart( +static JSValueRef nativeCaptureHeap( JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, @@ -85,73 +18,31 @@ static JSValueRef nativeCaptureStart( const JSValueRef arguments[], JSValueRef* exception) { if (argumentCount < 1) { - if (exception) { - *exception = facebook::react::makeJSCException( - ctx, - "nativeCaptureStart requires at least 1 argument"); - } - return JSValueMakeUndefined(ctx); + if (exception) { + *exception = facebook::react::makeJSCException( + ctx, + "nativeCaptureHeap requires the path to save the capture"); + } + return JSValueMakeUndefined(ctx); } JSStringRef outputFilename = JSValueToStringCopy(ctx, arguments[0], exception); - std::string finalFilename = - std::string("/sdcard/") + - facebook::react::String::ref(outputFilename).str(); - JSHeapCaptureStart(ctx, finalFilename.c_str()); + std::string finalFilename = facebook::react::String::ref(outputFilename).str(); + JSCaptureHeap(ctx, finalFilename.c_str(), exception); JSStringRelease(outputFilename); return JSValueMakeUndefined(ctx); } -static JSValueRef nativeCaptureEnd( - JSContextRef ctx, - JSObjectRef function, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef* exception) { - JSHeapCaptureEnd(ctx); - return JSValueMakeUndefined(ctx); -} - -static JSValueRef nativeHeapDump( - JSContextRef ctx, - JSObjectRef function, - JSObjectRef thisObject, - size_t argumentCount, - const JSValueRef arguments[], - JSValueRef* exception) { - if (argumentCount < 1) { - if (exception) { - *exception = facebook::react::makeJSCException( - ctx, - "nativeHeapDump requires at least 1 argument"); - } - return JSValueMakeUndefined(ctx); - } - - JSStringRef outputFilename = JSValueToStringCopy(ctx, arguments[0], exception); - std::string finalFilename = - std::string("/sdcard/") + - facebook::react::String::ref(outputFilename).str(); - JSHeapDump(ctx, finalFilename.c_str()); - JSStringRelease(outputFilename); - return JSValueMakeUndefined(ctx); -} -#endif +#endif // WITH_FB_MEMORY_PROFILING namespace facebook { namespace react { void addNativeMemoryHooks(JSGlobalContextRef ctx) { #ifdef WITH_FB_MEMORY_PROFILING - installGlobalFunction(ctx, "nativeEnableAllocationTag", nativeEnableAllocationTag); - installGlobalFunction(ctx, "nativeAllocationPushTag", nativeAllocationPushTag); - installGlobalFunction(ctx, "nativeAllocationPopTag", nativeAllocationPopTag); - installGlobalFunction(ctx, "nativeForceSyncGC", nativeForceSyncGC); - installGlobalFunction(ctx, "nativeCaptureStart", nativeCaptureStart); - installGlobalFunction(ctx, "nativeCaptureEnd", nativeCaptureEnd); - installGlobalFunction(ctx, "nativeHeapDump", nativeHeapDump); -#endif + installGlobalFunction(ctx, "nativeCaptureHeap", nativeCaptureHeap); +#endif // WITH_FB_MEMORY_PROFILING + } } }