2018-09-11 22:27:47 +00:00
|
|
|
// Copyright (c) Facebook, Inc. and its affiliates.
|
2018-05-31 22:31:03 +00:00
|
|
|
|
|
|
|
// This source code is licensed under the MIT license found in the
|
|
|
|
// LICENSE file in the root directory of this source tree.
|
2016-05-04 02:29:58 +00:00
|
|
|
|
2016-11-22 14:05:36 +00:00
|
|
|
#include "JSCMemory.h"
|
2016-05-14 00:14:45 +00:00
|
|
|
|
|
|
|
#ifdef WITH_FB_MEMORY_PROFILING
|
|
|
|
|
2016-05-04 02:29:58 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <JavaScriptCore/API/JSProfilerPrivate.h>
|
2016-11-01 18:38:43 +00:00
|
|
|
#include <jschelpers/JSCHelpers.h>
|
|
|
|
#include <jschelpers/Value.h>
|
2016-05-04 02:29:58 +00:00
|
|
|
|
2016-11-18 14:25:24 +00:00
|
|
|
using namespace facebook::react;
|
|
|
|
|
2016-05-04 02:29:58 +00:00
|
|
|
static JSValueRef nativeCaptureHeap(
|
|
|
|
JSContextRef ctx,
|
|
|
|
JSObjectRef function,
|
|
|
|
JSObjectRef thisObject,
|
|
|
|
size_t argumentCount,
|
|
|
|
const JSValueRef arguments[],
|
|
|
|
JSValueRef* exception) {
|
|
|
|
if (argumentCount < 1) {
|
2017-07-25 11:45:08 +00:00
|
|
|
if (exception) {
|
|
|
|
*exception = Value::makeError(
|
|
|
|
ctx,
|
|
|
|
"nativeCaptureHeap requires the path to save the capture");
|
|
|
|
}
|
|
|
|
return Value::makeUndefined(ctx);
|
2016-05-04 02:29:58 +00:00
|
|
|
}
|
|
|
|
|
2017-07-25 11:45:08 +00:00
|
|
|
auto outputFilename = Value(ctx, arguments[0]).toString();
|
2016-11-18 14:25:29 +00:00
|
|
|
JSCaptureHeap(ctx, outputFilename.str().c_str(), exception);
|
2016-11-18 14:25:24 +00:00
|
|
|
return Value::makeUndefined(ctx);
|
2016-05-04 02:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // WITH_FB_MEMORY_PROFILING
|
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace react {
|
|
|
|
|
2017-07-25 11:45:08 +00:00
|
|
|
void addJSCMemoryHooks(JSGlobalContextRef ctx) {
|
2016-05-04 02:29:58 +00:00
|
|
|
#ifdef WITH_FB_MEMORY_PROFILING
|
|
|
|
installGlobalFunction(ctx, "nativeCaptureHeap", nativeCaptureHeap);
|
|
|
|
#endif // WITH_FB_MEMORY_PROFILING
|
|
|
|
}
|
|
|
|
|
|
|
|
} }
|