2016-05-14 00:15:03 +00:00
|
|
|
// Copyright 2004-present Facebook. All Rights Reserved.
|
|
|
|
|
|
|
|
#ifdef WITH_JSC_EXTRA_TRACING
|
|
|
|
|
|
|
|
#include "JSCLegacyTracing.h"
|
|
|
|
|
|
|
|
#include <fbsystrace.h>
|
2016-11-22 14:05:36 +00:00
|
|
|
#include <JavaScriptCore/API/JSProfilerPrivate.h>
|
2016-11-01 18:38:43 +00:00
|
|
|
#include <jschelpers/JSCHelpers.h>
|
2016-11-18 14:25:24 +00:00
|
|
|
#include <jschelpers/Value.h>
|
2016-11-01 18:38:43 +00:00
|
|
|
|
2016-05-14 00:15:03 +00:00
|
|
|
#include "JSCTracing.h"
|
|
|
|
|
|
|
|
static const char *ENABLED_FBSYSTRACE_PROFILE_NAME = "__fbsystrace__";
|
|
|
|
|
2016-11-18 14:25:24 +00:00
|
|
|
using namespace facebook::react;
|
|
|
|
|
2016-05-14 00:15:03 +00:00
|
|
|
static JSValueRef nativeTraceBeginLegacy(
|
|
|
|
JSContextRef ctx,
|
|
|
|
JSObjectRef function,
|
|
|
|
JSObjectRef thisObject,
|
|
|
|
size_t argumentCount,
|
|
|
|
const JSValueRef arguments[],
|
|
|
|
JSValueRef* exception) {
|
|
|
|
if (FBSYSTRACE_LIKELY(argumentCount >= 1)) {
|
2016-11-18 14:25:24 +00:00
|
|
|
uint64_t tag = tracingTagFromJSValue(ctx, arguments[0], exception);
|
2016-05-14 00:15:03 +00:00
|
|
|
if (!fbsystrace_is_tracing(tag)) {
|
2016-11-18 14:25:24 +00:00
|
|
|
return Value::makeUndefined(ctx);
|
2016-05-14 00:15:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-18 14:25:29 +00:00
|
|
|
String title(ctx, ENABLED_FBSYSTRACE_PROFILE_NAME);
|
2016-05-14 00:15:03 +00:00
|
|
|
#if WITH_REACT_INTERNAL_SETTINGS
|
|
|
|
JSStartProfiling(ctx, title, true);
|
|
|
|
#else
|
|
|
|
JSStartProfiling(ctx, title);
|
|
|
|
#endif
|
|
|
|
|
2016-11-18 14:25:24 +00:00
|
|
|
return Value::makeUndefined(ctx);
|
2016-05-14 00:15:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static JSValueRef nativeTraceEndLegacy(
|
|
|
|
JSContextRef ctx,
|
|
|
|
JSObjectRef function,
|
|
|
|
JSObjectRef thisObject,
|
|
|
|
size_t argumentCount,
|
|
|
|
const JSValueRef arguments[],
|
|
|
|
JSValueRef* exception) {
|
|
|
|
if (FBSYSTRACE_LIKELY(argumentCount >= 1)) {
|
2016-11-18 14:25:24 +00:00
|
|
|
uint64_t tag = tracingTagFromJSValue(ctx, arguments[0], exception);
|
2016-05-14 00:15:03 +00:00
|
|
|
if (!fbsystrace_is_tracing(tag)) {
|
2016-11-18 14:25:24 +00:00
|
|
|
return Value::makeUndefined(ctx);
|
2016-05-14 00:15:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-18 14:25:29 +00:00
|
|
|
String title(ctx, ENABLED_FBSYSTRACE_PROFILE_NAME);
|
2016-05-14 00:15:03 +00:00
|
|
|
JSEndProfiling(ctx, title);
|
|
|
|
|
2016-11-18 14:25:24 +00:00
|
|
|
return Value::makeUndefined(ctx);
|
2016-05-14 00:15:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace react {
|
|
|
|
|
|
|
|
void addNativeTracingLegacyHooks(JSGlobalContextRef ctx) {
|
|
|
|
installGlobalFunction(ctx, "nativeTraceBeginLegacy", nativeTraceBeginLegacy);
|
|
|
|
installGlobalFunction(ctx, "nativeTraceEndLegacy", nativeTraceEndLegacy);
|
|
|
|
}
|
|
|
|
|
|
|
|
} }
|
|
|
|
|
|
|
|
#endif
|