11// Copyright 2004-present Facebook. All Rights Reserved.
22
3- #ifdef WITH_JSC_EXTRA_TRACING
3+ #if defined(WITH_JSC_EXTRA_TRACING) || DEBUG
4+
5+ #include " JSCTracing.h"
46
57#include < algorithm>
68#include < JavaScriptCore/JavaScript.h>
7- #include < JavaScriptCore/API/JSProfilerPrivate.h>
89#include < fbsystrace.h>
910#include < sys/types.h>
1011#include < unistd.h>
1112#include " JSCHelpers.h"
1213
1314using std::min;
1415
15- static const char *ENABLED_FBSYSTRACE_PROFILE_NAME = " __fbsystrace__" ;
16-
17- static uint64_t tagFromJSValue (
18- JSContextRef ctx,
19- JSValueRef value,
20- JSValueRef* exception) {
21- // XXX validate that this is a lossless conversion.
22- // XXX should we just have separate functions for bridge, infra, and apps,
23- // then drop this argument to save time?
24- (void )exception;
25- uint64_t tag = (uint64_t ) JSValueToNumber (ctx, value, NULL );
26- return tag;
27- }
28-
2916static int64_t int64FromJSValue (
3017 JSContextRef ctx,
3118 JSValueRef value,
@@ -105,7 +92,7 @@ static JSValueRef nativeTraceBeginSection(
10592 return JSValueMakeUndefined (ctx);
10693 }
10794
108- uint64_t tag = tagFromJSValue (ctx, arguments[0 ], exception);
95+ uint64_t tag = facebook::react::tracingTagFromJSValue (ctx, arguments[0 ], exception);
10996 if (!fbsystrace_is_tracing (tag)) {
11097 return JSValueMakeUndefined (ctx);
11198 }
@@ -145,7 +132,7 @@ static JSValueRef nativeTraceEndSection(
145132 return JSValueMakeUndefined (ctx);
146133 }
147134
148- uint64_t tag = tagFromJSValue (ctx, arguments[0 ], exception);
135+ uint64_t tag = facebook::react::tracingTagFromJSValue (ctx, arguments[0 ], exception);
149136 if (!fbsystrace_is_tracing (tag)) {
150137 return JSValueMakeUndefined (ctx);
151138 }
@@ -189,7 +176,7 @@ static JSValueRef beginOrEndAsync(
189176 return JSValueMakeUndefined (ctx);
190177 }
191178
192- uint64_t tag = tagFromJSValue (ctx, arguments[0 ], exception);
179+ uint64_t tag = facebook::react::tracingTagFromJSValue (ctx, arguments[0 ], exception);
193180 if (!fbsystrace_is_tracing (tag)) {
194181 return JSValueMakeUndefined (ctx);
195182 }
@@ -252,7 +239,7 @@ static JSValueRef stageAsync(
252239 return JSValueMakeUndefined (ctx);
253240 }
254241
255- uint64_t tag = tagFromJSValue (ctx, arguments[0 ], exception);
242+ uint64_t tag = facebook::react::tracingTagFromJSValue (ctx, arguments[0 ], exception);
256243 if (!fbsystrace_is_tracing (tag)) {
257244 return JSValueMakeUndefined (ctx);
258245 }
@@ -398,7 +385,7 @@ static JSValueRef nativeTraceCounter(
398385 return JSValueMakeUndefined (ctx);
399386 }
400387
401- uint64_t tag = tagFromJSValue (ctx, arguments[0 ], exception);
388+ uint64_t tag = facebook::react::tracingTagFromJSValue (ctx, arguments[0 ], exception);
402389 if (!fbsystrace_is_tracing (tag)) {
403390 return JSValueMakeUndefined (ctx);
404391 }
@@ -414,60 +401,24 @@ static JSValueRef nativeTraceCounter(
414401 return JSValueMakeUndefined (ctx);
415402}
416403
417- static JSValueRef nativeTraceBeginLegacy (
418- JSContextRef ctx,
419- JSObjectRef function,
420- JSObjectRef thisObject,
421- size_t argumentCount,
422- const JSValueRef arguments[],
423- JSValueRef* exception) {
424- if (FBSYSTRACE_LIKELY (argumentCount >= 1 )) {
425- uint64_t tag = tagFromJSValue (ctx, arguments[0 ], exception);
426- if (!fbsystrace_is_tracing (tag)) {
427- return JSValueMakeUndefined (ctx);
428- }
429- }
430-
431- JSStringRef title = JSStringCreateWithUTF8CString (ENABLED_FBSYSTRACE_PROFILE_NAME);
432- #if WITH_REACT_INTERNAL_SETTINGS
433- JSStartProfiling (ctx, title, true );
434- #else
435- JSStartProfiling (ctx, title);
436- #endif
437- JSStringRelease (title);
438-
439- return JSValueMakeUndefined (ctx);
440- }
404+ namespace facebook {
405+ namespace react {
441406
442- static JSValueRef nativeTraceEndLegacy (
407+ uint64_t tracingTagFromJSValue (
443408 JSContextRef ctx,
444- JSObjectRef function,
445- JSObjectRef thisObject,
446- size_t argumentCount,
447- const JSValueRef arguments[],
409+ JSValueRef value,
448410 JSValueRef* exception) {
449- if (FBSYSTRACE_LIKELY (argumentCount >= 1 )) {
450- uint64_t tag = tagFromJSValue (ctx, arguments[0 ], exception);
451- if (!fbsystrace_is_tracing (tag)) {
452- return JSValueMakeUndefined (ctx);
453- }
454- }
455-
456- JSStringRef title = JSStringCreateWithUTF8CString (ENABLED_FBSYSTRACE_PROFILE_NAME);
457- JSEndProfiling (ctx, title);
458- JSStringRelease (title);
459-
460- return JSValueMakeUndefined (ctx);
411+ // XXX validate that this is a lossless conversion.
412+ // XXX should we just have separate functions for bridge, infra, and apps,
413+ // then drop this argument to save time?
414+ (void )exception;
415+ uint64_t tag = (uint64_t ) JSValueToNumber (ctx, value, NULL );
416+ return tag;
461417}
462418
463- namespace facebook {
464- namespace react {
465-
466419void addNativeTracingHooks (JSGlobalContextRef ctx) {
467420 installGlobalFunction (ctx, " nativeTraceBeginSection" , nativeTraceBeginSection);
468421 installGlobalFunction (ctx, " nativeTraceEndSection" , nativeTraceEndSection);
469- installGlobalFunction (ctx, " nativeTraceBeginLegacy" , nativeTraceBeginLegacy);
470- installGlobalFunction (ctx, " nativeTraceEndLegacy" , nativeTraceEndLegacy);
471422 installGlobalFunction (ctx, " nativeTraceBeginAsyncSection" , nativeTraceBeginAsyncSection);
472423 installGlobalFunction (ctx, " nativeTraceEndAsyncSection" , nativeTraceEndAsyncSection);
473424 installGlobalFunction (ctx, " nativeTraceAsyncSectionStage" , nativeTraceAsyncSectionStage);
0 commit comments