Skip to content

Commit

Permalink
Bug 1924272 - Move GC-related profiler markers into the GCCC category…
Browse files Browse the repository at this point in the history
… r=jonco,tcampbell,profiler-reviewers,canaltinova

Differential Revision: https://phabricator.services.mozilla.com/D225436
  • Loading branch information
hotsphink committed Feb 26, 2025
1 parent 4025726 commit 6c2815e
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 20 deletions.
7 changes: 4 additions & 3 deletions js/public/ProfilingStack.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define js_ProfilingStack_h

#include "mozilla/Atomics.h"
#include "mozilla/BaseProfilerMarkersPrerequisites.h"

#include <stdint.h>

Expand Down Expand Up @@ -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

Expand Down
9 changes: 6 additions & 3 deletions js/src/gc/ParallelMarking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion js/src/shell/js.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
13 changes: 9 additions & 4 deletions js/src/vm/GeckoProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<mozilla::baseprofiler::ProfilingCategoryPair>(jsPair));
eventMarker_(category, event, details);
}
}

Expand Down Expand Up @@ -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);
}
Expand Down
11 changes: 8 additions & 3 deletions js/src/vm/GeckoProfiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stddef.h>
#include <stdint.h>
Expand Down Expand Up @@ -122,7 +124,7 @@ class GeckoProfilerRuntime {
MainThreadData<ProfileStringMap> 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);
Expand All @@ -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(); }

Expand Down
3 changes: 2 additions & 1 deletion mozglue/baseprofiler/core/platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,8 @@ ExtractBaseProfilerChunkManager() {

} // namespace detail

Atomic<uint32_t, MemoryOrdering::Relaxed> RacyFeatures::sActiveAndFeatures(0);
MFBT_DATA Atomic<uint32_t, MemoryOrdering::Relaxed>
RacyFeatures::sActiveAndFeatures(0);

/* static */
void RacyFeatures::SetActive(uint32_t aFeatures) {
Expand Down
2 changes: 1 addition & 1 deletion mozglue/baseprofiler/public/BaseProfilerState.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t, MemoryOrdering::Relaxed> sActiveAndFeatures;
MFBT_DATA static Atomic<uint32_t, MemoryOrdering::Relaxed> sActiveAndFeatures;
};

MFBT_API bool IsThreadBeingProfiled();
Expand Down
13 changes: 9 additions & 4 deletions tools/profiler/core/ProfilerThreadRegistrationData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 6c2815e

Please sign in to comment.