diff --git a/js/public/ProfilingStack.h b/js/public/ProfilingStack.h index b9b96c27dc1bb4..08cf2394285627 100644 --- a/js/public/ProfilingStack.h +++ b/js/public/ProfilingStack.h @@ -8,6 +8,7 @@ #define js_ProfilingStack_h #include "mozilla/Atomics.h" +#include "mozilla/BaseProfilerMarkersPrerequisites.h" #include @@ -362,9 +363,9 @@ JS_PUBLIC_API void SetContextProfilingStack(JSContext* cx, JS_PUBLIC_API void EnableContextProfilingStack(JSContext* cx, bool enabled); -JS_PUBLIC_API void RegisterContextProfilingEventMarker(JSContext* cx, - void (*fn)(const char*, - const char*)); +JS_PUBLIC_API void RegisterContextProfilingEventMarker( + JSContext* cx, + void (*fn)(mozilla::MarkerCategory, const char*, const char*)); } // namespace js diff --git a/js/src/gc/ParallelMarking.cpp b/js/src/gc/ParallelMarking.cpp index 8045edf1cd4fef..e4eecc0105f4dc 100644 --- a/js/src/gc/ParallelMarking.cpp +++ b/js/src/gc/ParallelMarking.cpp @@ -213,7 +213,8 @@ bool ParallelMarkTask::requestWork(AutoLockHelperThreadState& lock) { void ParallelMarkTask::waitUntilResumed(AutoLockHelperThreadState& lock) { GeckoProfilerRuntime& profiler = gc->rt->geckoProfiler(); if (profiler.enabled()) { - profiler.markEvent("Parallel marking wait start", ""); + profiler.markEvent("Parallel marking wait start", "", + JS::ProfilingCategoryPair::GCCC); } pm->addTaskToWaitingList(this, lock); @@ -232,7 +233,8 @@ void ParallelMarkTask::waitUntilResumed(AutoLockHelperThreadState& lock) { MOZ_ASSERT(!pm->isTaskInWaitingList(this, lock)); if (profiler.enabled()) { - profiler.markEvent("Parallel marking wait end", ""); + profiler.markEvent("Parallel marking wait end", "", + JS::ProfilingCategoryPair::GCCC); } } @@ -333,7 +335,8 @@ void ParallelMarker::donateWorkFrom(GCMarker* src) { GeckoProfilerRuntime& profiler = gc->rt->geckoProfiler(); if (profiler.enabled()) { - profiler.markEvent("Parallel marking donated work", ""); + profiler.markEvent("Parallel marking donated work", "", + JS::ProfilingCategoryPair::GCCC); } // Resume waiting task. diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index 54f1ded2cd9675..772630ca0fd7b0 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -7628,7 +7628,8 @@ static bool WithSourceHook(JSContext* cx, unsigned argc, Value* vp) { return result; } -static void PrintProfilerEvents_Callback(const char* msg, const char* details) { +static void PrintProfilerEvents_Callback(mozilla::MarkerCategory, + const char* msg, const char* details) { fprintf(stderr, "PROFILER EVENT: %s %s\n", msg, details); } diff --git a/js/src/vm/GeckoProfiler.cpp b/js/src/vm/GeckoProfiler.cpp index 328e3c73ce122a..d68fb5b51c790f 100644 --- a/js/src/vm/GeckoProfiler.cpp +++ b/js/src/vm/GeckoProfiler.cpp @@ -40,7 +40,8 @@ void GeckoProfilerThread::setProfilingStack(ProfilingStack* profilingStack, profilingStackIfEnabled_ = enabled ? profilingStack : nullptr; } -void GeckoProfilerRuntime::setEventMarker(void (*fn)(const char*, +void GeckoProfilerRuntime::setEventMarker(void (*fn)(mozilla::MarkerCategory, + const char*, const char*)) { eventMarker_ = fn; } @@ -180,11 +181,14 @@ void GeckoProfilerRuntime::onScriptFinalized(BaseScript* script) { } } -void GeckoProfilerRuntime::markEvent(const char* event, const char* details) { +void GeckoProfilerRuntime::markEvent(const char* event, const char* details, + JS::ProfilingCategoryPair jsPair) { MOZ_ASSERT(enabled()); if (eventMarker_) { JS::AutoSuppressGCAnalysis nogc; - eventMarker_(event, details); + mozilla::MarkerCategory category( + static_cast(jsPair)); + eventMarker_(category, event, details); } } @@ -485,7 +489,8 @@ JS_PUBLIC_API void js::EnableContextProfilingStack(JSContext* cx, } JS_PUBLIC_API void js::RegisterContextProfilingEventMarker( - JSContext* cx, void (*fn)(const char*, const char*)) { + JSContext* cx, + void (*fn)(mozilla::MarkerCategory, const char*, const char*)) { MOZ_ASSERT(cx->runtime()->geckoProfiler().enabled()); cx->runtime()->geckoProfiler().setEventMarker(fn); } diff --git a/js/src/vm/GeckoProfiler.h b/js/src/vm/GeckoProfiler.h index bf04cc4e4f845f..9431042390f4aa 100644 --- a/js/src/vm/GeckoProfiler.h +++ b/js/src/vm/GeckoProfiler.h @@ -8,7 +8,9 @@ #define vm_GeckoProfiler_h #include "mozilla/Attributes.h" +#include "mozilla/BaseProfilerMarkersPrerequisites.h" #include "mozilla/DebugOnly.h" +#include "mozilla/TimeStamp.h" #include #include @@ -122,7 +124,7 @@ class GeckoProfilerRuntime { MainThreadData strings_; bool slowAssertions; uint32_t enabled_; - void (*eventMarker_)(const char*, const char*); + void (*eventMarker_)(mozilla::MarkerCategory, const char*, const char*); public: explicit GeckoProfilerRuntime(JSRuntime* rt); @@ -133,14 +135,17 @@ class GeckoProfilerRuntime { void enableSlowAssertions(bool enabled) { slowAssertions = enabled; } bool slowAssertionsEnabled() { return slowAssertions; } - void setEventMarker(void (*fn)(const char*, const char*)); + void setEventMarker(void (*fn)(mozilla::MarkerCategory, const char*, + const char*)); static JS::UniqueChars allocProfileString(JSContext* cx, BaseScript* script); const char* profileString(JSContext* cx, BaseScript* script); void onScriptFinalized(BaseScript* script); - void markEvent(const char* event, const char* details); + void markEvent( + const char* event, const char* details, + JS::ProfilingCategoryPair jsPair = JS::ProfilingCategoryPair::JS); ProfileStringMap& strings() { return strings_.ref(); } diff --git a/mozglue/baseprofiler/core/platform.cpp b/mozglue/baseprofiler/core/platform.cpp index d562785876294a..c3855a76ebc9be 100644 --- a/mozglue/baseprofiler/core/platform.cpp +++ b/mozglue/baseprofiler/core/platform.cpp @@ -1050,7 +1050,8 @@ ExtractBaseProfilerChunkManager() { } // namespace detail -Atomic RacyFeatures::sActiveAndFeatures(0); +MFBT_DATA Atomic + RacyFeatures::sActiveAndFeatures(0); /* static */ void RacyFeatures::SetActive(uint32_t aFeatures) { diff --git a/mozglue/baseprofiler/public/BaseProfilerState.h b/mozglue/baseprofiler/public/BaseProfilerState.h index 349c95b800e5e8..6031805061ef7e 100644 --- a/mozglue/baseprofiler/public/BaseProfilerState.h +++ b/mozglue/baseprofiler/public/BaseProfilerState.h @@ -340,7 +340,7 @@ class RacyFeatures { // We combine the active bit with the feature bits so they can be read or // written in a single atomic operation. // TODO: Could this be MFBT_DATA for better inlining optimization? - static Atomic sActiveAndFeatures; + MFBT_DATA static Atomic sActiveAndFeatures; }; MFBT_API bool IsThreadBeingProfiled(); diff --git a/tools/profiler/core/ProfilerThreadRegistrationData.cpp b/tools/profiler/core/ProfilerThreadRegistrationData.cpp index 09ceac2e34e8b0..2a3454417f223e 100644 --- a/tools/profiler/core/ProfilerThreadRegistrationData.cpp +++ b/tools/profiler/core/ProfilerThreadRegistrationData.cpp @@ -76,11 +76,16 @@ ThreadRegistrationData::ThreadRegistrationData(const char* aName, // This is a simplified version of profiler_add_marker that can be easily passed // into the JS engine. -static void profiler_add_js_marker(const char* aMarkerName, +static void profiler_add_js_marker(mozilla::MarkerCategory aCategory, + const char* aMarkerName, const char* aMarkerText) { - PROFILER_MARKER_TEXT( - mozilla::ProfilerString8View::WrapNullTerminatedString(aMarkerName), JS, - {}, mozilla::ProfilerString8View::WrapNullTerminatedString(aMarkerText)); +#ifdef MOZ_GECKO_PROFILER + AUTO_PROFILER_STATS(js_marker); + profiler_add_marker( + mozilla::ProfilerString8View::WrapNullTerminatedString(aMarkerName), + aCategory, {}, ::geckoprofiler::markers::TextMarker{}, + mozilla::ProfilerString8View::WrapNullTerminatedString(aMarkerText)); +#endif } static void profiler_add_js_allocation_marker(JS::RecordAllocationInfo&& info) {