Add heap snapshot to fbandroid JSC
Reviewed By: michalgr Differential Revision: D3168026 fb-gh-sync-id: 123c9caa1ae7792cfa93590de4832b76c8178edb fbshipit-source-id: 123c9caa1ae7792cfa93590de4832b76c8178edb
This commit is contained in:
Родитель
8c1b773e4d
Коммит
f6d9a9097f
|
@ -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
|
||||
)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
}
|
||||
|
||||
} }
|
||||
|
|
Загрузка…
Ссылка в новой задаче