2016-05-04 02:29:58 +00:00
|
|
|
// Copyright 2004-present Facebook. All Rights Reserved.
|
|
|
|
|
|
|
|
#ifdef WITH_JSC_EXTRA_TRACING
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <JavaScriptCore/API/JSProfilerPrivate.h>
|
|
|
|
#include <jsc_legacy_profiler.h>
|
2016-11-22 14:05:36 +00:00
|
|
|
#include <jschelpers/JavaScriptCore.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
|
|
|
#include "JSCLegacyProfiler.h"
|
|
|
|
|
2016-11-18 14:25:24 +00:00
|
|
|
using namespace facebook::react;
|
|
|
|
|
2016-05-04 02:29:58 +00:00
|
|
|
static JSValueRef nativeProfilerStart(
|
|
|
|
JSContextRef ctx,
|
|
|
|
JSObjectRef function,
|
|
|
|
JSObjectRef thisObject,
|
|
|
|
size_t argumentCount,
|
|
|
|
const JSValueRef arguments[],
|
|
|
|
JSValueRef* exception) {
|
|
|
|
if (argumentCount < 1) {
|
|
|
|
if (exception) {
|
2016-11-18 14:25:24 +00:00
|
|
|
*exception = Value::makeError(
|
2016-05-04 02:29:58 +00:00
|
|
|
ctx,
|
|
|
|
"nativeProfilerStart: requires at least 1 argument");
|
|
|
|
}
|
2016-11-18 14:25:24 +00:00
|
|
|
return Value::makeUndefined(ctx);
|
2016-05-04 02:29:58 +00:00
|
|
|
}
|
|
|
|
|
2016-11-18 14:25:29 +00:00
|
|
|
auto title = String::adopt(ctx, JSValueToStringCopy(ctx, arguments[0], exception));
|
2016-05-04 02:29:58 +00:00
|
|
|
#if WITH_REACT_INTERNAL_SETTINGS
|
|
|
|
JSStartProfiling(ctx, title, false);
|
|
|
|
#else
|
|
|
|
JSStartProfiling(ctx, title);
|
|
|
|
#endif
|
2016-11-18 14:25:24 +00:00
|
|
|
return Value::makeUndefined(ctx);
|
2016-05-04 02:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static JSValueRef nativeProfilerEnd(
|
|
|
|
JSContextRef ctx,
|
|
|
|
JSObjectRef function,
|
|
|
|
JSObjectRef thisObject,
|
|
|
|
size_t argumentCount,
|
|
|
|
const JSValueRef arguments[],
|
|
|
|
JSValueRef* exception) {
|
|
|
|
if (argumentCount < 1) {
|
|
|
|
if (exception) {
|
2016-11-18 14:25:24 +00:00
|
|
|
*exception = Value::makeError(
|
2016-05-04 02:29:58 +00:00
|
|
|
ctx,
|
|
|
|
"nativeProfilerEnd: requires at least 1 argument");
|
|
|
|
}
|
2016-11-18 14:25:24 +00:00
|
|
|
return Value::makeUndefined(ctx);
|
2016-05-04 02:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string writeLocation("/sdcard/");
|
|
|
|
if (argumentCount > 1) {
|
2016-11-18 14:25:29 +00:00
|
|
|
auto fileName = String::adopt(
|
2016-11-22 14:05:38 +00:00
|
|
|
ctx, JSC_JSValueToStringCopy(ctx, arguments[1], exception));
|
2016-11-18 14:25:29 +00:00
|
|
|
writeLocation += fileName.str();
|
2016-05-04 02:29:58 +00:00
|
|
|
} else {
|
|
|
|
writeLocation += "profile.json";
|
|
|
|
}
|
2016-11-18 14:25:29 +00:00
|
|
|
auto title = String::adopt(
|
2016-11-22 14:05:38 +00:00
|
|
|
ctx, JSC_JSValueToStringCopy(ctx, arguments[0], exception));
|
2016-05-04 02:29:58 +00:00
|
|
|
JSEndProfilingAndRender(ctx, title, writeLocation.c_str());
|
2016-11-18 14:25:24 +00:00
|
|
|
return Value::makeUndefined(ctx);
|
2016-05-04 02:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace react {
|
|
|
|
|
|
|
|
void stopAndOutputProfilingFile(
|
|
|
|
JSContextRef ctx,
|
|
|
|
JSStringRef title,
|
|
|
|
const char *filename) {
|
|
|
|
JSEndProfilingAndRender(ctx, title, filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
void addNativeProfilingHooks(JSGlobalContextRef ctx) {
|
2016-07-26 14:20:34 +00:00
|
|
|
// JSEnableByteCodeProfiling();
|
2016-05-04 02:29:58 +00:00
|
|
|
installGlobalFunction(ctx, "nativeProfilerStart", nativeProfilerStart);
|
|
|
|
installGlobalFunction(ctx, "nativeProfilerEnd", nativeProfilerEnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
} }
|
|
|
|
|
|
|
|
#endif
|