Add fbsystrace markers using the legacyprofiler
Reviewed By: astreet Differential Revision: D2728033 fb-gh-sync-id: 264d40930b8fec0262cbea36529bd8b11efcc58e
This commit is contained in:
parent
d138403c2e
commit
7f710f9050
|
@ -20,8 +20,9 @@ type RelayProfiler = {
|
|||
|
||||
var GLOBAL = GLOBAL || this;
|
||||
var TRACE_TAG_REACT_APPS = 1 << 17;
|
||||
var TRACE_TAG_JSC_CALLS = 1 << 27;
|
||||
|
||||
var _enabled;
|
||||
var _enabled = false;
|
||||
var _asyncCookie = 0;
|
||||
var _ReactPerf = null;
|
||||
function ReactPerf() {
|
||||
|
@ -33,6 +34,13 @@ function ReactPerf() {
|
|||
|
||||
var BridgeProfiling = {
|
||||
setEnabled(enabled: boolean) {
|
||||
if (_enabled !== enabled) {
|
||||
if (enabled) {
|
||||
global.nativeTraceBeginLegacy && global.nativeTraceBeginLegacy(TRACE_TAG_JSC_CALLS);
|
||||
} else {
|
||||
global.nativeTraceEndLegacy && global.nativeTraceEndLegacy(TRACE_TAG_JSC_CALLS);
|
||||
}
|
||||
}
|
||||
_enabled = enabled;
|
||||
|
||||
ReactPerf().enableMeasure = enabled;
|
||||
|
|
|
@ -195,7 +195,11 @@ bool JSCExecutor::supportsProfiling() {
|
|||
void JSCExecutor::startProfiler(const std::string &titleString) {
|
||||
#ifdef WITH_JSC_EXTRA_TRACING
|
||||
JSStringRef title = JSStringCreateWithUTF8CString(titleString.c_str());
|
||||
#if WITH_JSC_INTERNAL
|
||||
JSStartProfiling(m_context, title, false);
|
||||
#else
|
||||
JSStartProfiling(m_context, title);
|
||||
#endif
|
||||
JSStringRelease(title);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -26,7 +26,11 @@ static JSValueRef nativeProfilerStart(
|
|||
}
|
||||
|
||||
JSStringRef title = JSValueToStringCopy(ctx, arguments[0], exception);
|
||||
#if WITH_JSC_INTERNAL
|
||||
JSStartProfiling(ctx, title, false);
|
||||
#else
|
||||
JSStartProfiling(ctx, title);
|
||||
#endif
|
||||
JSStringRelease(title);
|
||||
return JSValueMakeUndefined(ctx);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <algorithm>
|
||||
#include <JavaScriptCore/JavaScript.h>
|
||||
#include <JavaScriptCore/API/JSProfilerPrivate.h>
|
||||
#include <fbsystrace.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
@ -9,6 +10,8 @@
|
|||
|
||||
using std::min;
|
||||
|
||||
static const char *ENABLED_FBSYSTRACE_PROFILE_NAME = "__fbsystrace__";
|
||||
|
||||
static uint64_t tagFromJSValue(
|
||||
JSContextRef ctx,
|
||||
JSValueRef value,
|
||||
|
@ -409,12 +412,74 @@ static JSValueRef nativeTraceCounter(
|
|||
return JSValueMakeUndefined(ctx);
|
||||
}
|
||||
|
||||
static JSValueRef nativeTraceBeginLegacy(
|
||||
JSContextRef ctx,
|
||||
JSObjectRef function,
|
||||
JSObjectRef thisObject,
|
||||
size_t argumentCount,
|
||||
const JSValueRef arguments[],
|
||||
JSValueRef* exception) {
|
||||
if (FBSYSTRACE_UNLIKELY(argumentCount < 1)) {
|
||||
if (exception) {
|
||||
*exception = facebook::react::makeJSCException(
|
||||
ctx,
|
||||
"nativeTraceBeginLegacy: requires TAG Argument");
|
||||
}
|
||||
return JSValueMakeUndefined(ctx);
|
||||
}
|
||||
|
||||
uint64_t tag = tagFromJSValue(ctx, arguments[0], exception);
|
||||
if (!fbsystrace_is_tracing(tag)) {
|
||||
return JSValueMakeUndefined(ctx);
|
||||
}
|
||||
|
||||
JSStringRef title = JSStringCreateWithUTF8CString(ENABLED_FBSYSTRACE_PROFILE_NAME);
|
||||
#if WITH_JSC_INTERNAL
|
||||
JSStartProfiling(ctx, title, true);
|
||||
#else
|
||||
JSStartProfiling(ctx, title);
|
||||
#endif
|
||||
JSStringRelease(title);
|
||||
|
||||
return JSValueMakeUndefined(ctx);
|
||||
}
|
||||
|
||||
static JSValueRef nativeTraceEndLegacy(
|
||||
JSContextRef ctx,
|
||||
JSObjectRef function,
|
||||
JSObjectRef thisObject,
|
||||
size_t argumentCount,
|
||||
const JSValueRef arguments[],
|
||||
JSValueRef* exception) {
|
||||
if (FBSYSTRACE_UNLIKELY(argumentCount < 1)) {
|
||||
if (exception) {
|
||||
*exception = facebook::react::makeJSCException(
|
||||
ctx,
|
||||
"nativeTraceBeginLegacy: requires TAG Argument");
|
||||
}
|
||||
return JSValueMakeUndefined(ctx);
|
||||
}
|
||||
|
||||
uint64_t tag = tagFromJSValue(ctx, arguments[0], exception);
|
||||
if (!fbsystrace_is_tracing(tag)) {
|
||||
return JSValueMakeUndefined(ctx);
|
||||
}
|
||||
|
||||
JSStringRef title = JSStringCreateWithUTF8CString(ENABLED_FBSYSTRACE_PROFILE_NAME);
|
||||
JSEndProfiling(ctx, title);
|
||||
JSStringRelease(title);
|
||||
|
||||
return JSValueMakeUndefined(ctx);
|
||||
}
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
void addNativeTracingHooks(JSGlobalContextRef ctx) {
|
||||
installGlobalFunction(ctx, "nativeTraceBeginSection", nativeTraceBeginSection);
|
||||
installGlobalFunction(ctx, "nativeTraceEndSection", nativeTraceEndSection);
|
||||
installGlobalFunction(ctx, "nativeTraceBeginLegacy", nativeTraceBeginLegacy);
|
||||
installGlobalFunction(ctx, "nativeTraceEndLegacy", nativeTraceEndLegacy);
|
||||
installGlobalFunction(ctx, "nativeTraceBeginAsyncSection", nativeTraceBeginAsyncSection);
|
||||
installGlobalFunction(ctx, "nativeTraceEndAsyncSection", nativeTraceEndAsyncSection);
|
||||
installGlobalFunction(ctx, "nativeTraceAsyncSectionStage", nativeTraceAsyncSectionStage);
|
||||
|
|
Loading…
Reference in New Issue