forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJSCLegacyTracing.cpp
73 lines (57 loc) · 1.9 KB
/
JSCLegacyTracing.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright 2004-present Facebook. All Rights Reserved.
#ifdef WITH_JSC_EXTRA_TRACING
#include "JSCLegacyTracing.h"
#include <JavaScriptCore/JavaScript.h>
#include <JavaScriptCore/API/JSProfilerPrivate.h>
#include <fbsystrace.h>
#include "JSCHelpers.h"
#include "JSCTracing.h"
static const char *ENABLED_FBSYSTRACE_PROFILE_NAME = "__fbsystrace__";
static JSValueRef nativeTraceBeginLegacy(
JSContextRef ctx,
JSObjectRef function,
JSObjectRef thisObject,
size_t argumentCount,
const JSValueRef arguments[],
JSValueRef* exception) {
if (FBSYSTRACE_LIKELY(argumentCount >= 1)) {
uint64_t tag = facebook::react::tracingTagFromJSValue(ctx, arguments[0], exception);
if (!fbsystrace_is_tracing(tag)) {
return JSValueMakeUndefined(ctx);
}
}
JSStringRef title = JSStringCreateWithUTF8CString(ENABLED_FBSYSTRACE_PROFILE_NAME);
#if WITH_REACT_INTERNAL_SETTINGS
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_LIKELY(argumentCount >= 1)) {
uint64_t tag = facebook::react::tracingTagFromJSValue(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 addNativeTracingLegacyHooks(JSGlobalContextRef ctx) {
installGlobalFunction(ctx, "nativeTraceBeginLegacy", nativeTraceBeginLegacy);
installGlobalFunction(ctx, "nativeTraceEndLegacy", nativeTraceEndLegacy);
}
} }
#endif