Skip to content

Commit

Permalink
[JSC] Add activeJSGlobalObjectSignpostIntervalCount
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=265003
rdar://118545511

Reviewed by Mark Lam.

Add activeJSGlobalObjectSignpostIntervalCount global variable, which offers counter of active JSGlobalObject signpost intervals.
This is really useful since we can know whether we are inside signpost interval or not quickly by checking this number.

* Source/JavaScriptCore/runtime/JSGlobalObject.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):

Canonical link: https://commits.webkit.org/270864@main
  • Loading branch information
Constellation committed Nov 17, 2023
1 parent ce5a85a commit d7ea41a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Source/JavaScriptCore/runtime/JSCJSValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ enum class SourceCodeRepresentation : uint8_t {
};

extern JS_EXPORT_PRIVATE const ASCIILiteral SymbolCoercionError;
#if HAVE(OS_SIGNPOST)
extern JS_EXPORT_PRIVATE std::atomic<unsigned> activeJSGlobalObjectSignpostIntervalCount;
#endif

class JSValue {
friend struct EncodedJSValueHashTraits;
Expand Down
4 changes: 4 additions & 0 deletions Source/JavaScriptCore/runtime/JSGlobalObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,8 @@ static String asSignpostString(JSGlobalObject* globalObject, JSValue v)
return v.toWTFString(globalObject);
}

std::atomic<unsigned> activeJSGlobalObjectSignpostIntervalCount { 0 };

JSC_DEFINE_HOST_FUNCTION(signpostStart, (JSGlobalObject* globalObject, CallFrame* callFrame))
{
VM& vm = globalObject->vm();
Expand All @@ -530,6 +532,7 @@ JSC_DEFINE_HOST_FUNCTION(signpostStart, (JSGlobalObject* globalObject, CallFrame
auto message = asSignpostString(globalObject, callFrame->argument(0));
RETURN_IF_EXCEPTION(scope, EncodedJSValue());

++activeJSGlobalObjectSignpostIntervalCount;
os_signpost_interval_begin(WTFSignpostLogHandle(), os_signpost_id_make_with_pointer(WTFSignpostLogHandle(), globalObject), "JSGlobalObject signpost", "%" PUBLIC_LOG_STRING, message.ascii().data());

return JSValue::encode(jsUndefined());
Expand All @@ -544,6 +547,7 @@ JSC_DEFINE_HOST_FUNCTION(signpostStop, (JSGlobalObject* globalObject, CallFrame*
RETURN_IF_EXCEPTION(scope, EncodedJSValue());

os_signpost_interval_end(WTFSignpostLogHandle(), os_signpost_id_make_with_pointer(WTFSignpostLogHandle(), globalObject), "JSGlobalObject signpost", "%" PUBLIC_LOG_STRING, message.ascii().data());
--activeJSGlobalObjectSignpostIntervalCount;

return JSValue::encode(jsUndefined());
}
Expand Down

0 comments on commit d7ea41a

Please sign in to comment.