diff --git a/mozglue/baseprofiler/core/platform.cpp b/mozglue/baseprofiler/core/platform.cpp index 3cda00606587..e66137fbc95f 100644 --- a/mozglue/baseprofiler/core/platform.cpp +++ b/mozglue/baseprofiler/core/platform.cpp @@ -419,7 +419,7 @@ class CorePS { PS_GET_LOCKLESS(int, MainThreadId) // No PSLockRef is needed for this field because it's immutable. - PS_GET_LOCKLESS(TimeStamp, ProcessStartTime) + PS_GET_LOCKLESS(const TimeStamp&, ProcessStartTime) // No PSLockRef is needed for this field because it's thread-safe. PS_GET_LOCKLESS(ProfileChunkedBuffer&, CoreBuffer) @@ -568,6 +568,11 @@ class CorePS { CorePS* CorePS::sInstance = nullptr; +ProfileChunkedBuffer& profiler_get_core_buffer() { + MOZ_ASSERT(CorePS::Exists()); + return CorePS::CoreBuffer(); +} + class SamplerThread; static SamplerThread* NewSamplerThread(PSLockRef aLock, uint32_t aGeneration, diff --git a/mozglue/baseprofiler/public/BaseProfilerMarkersDetail.h b/mozglue/baseprofiler/public/BaseProfilerMarkersDetail.h index 914d35c89997..9c46dbbce339 100644 --- a/mozglue/baseprofiler/public/BaseProfilerMarkersDetail.h +++ b/mozglue/baseprofiler/public/BaseProfilerMarkersDetail.h @@ -22,6 +22,23 @@ # include +namespace mozilla::baseprofiler { +// Implemented in platform.cpp +MFBT_API ProfileChunkedBuffer& profiler_get_core_buffer(); +} // namespace mozilla::baseprofiler + +namespace mozilla::base_profiler_markers_detail { + +// Get the core buffer from the profiler, and cache it in a +// non-templated-function static reference. +inline ProfileChunkedBuffer& CachedBaseCoreBuffer() { + static ProfileChunkedBuffer& coreBuffer = + baseprofiler::profiler_get_core_buffer(); + return coreBuffer; +} + +} // namespace mozilla::base_profiler_markers_detail + namespace mozilla { // ---------------------------------------------------------------------------- diff --git a/tools/profiler/core/platform.cpp b/tools/profiler/core/platform.cpp index 28ac4fdca91a..77c2c7ae3397 100644 --- a/tools/profiler/core/platform.cpp +++ b/tools/profiler/core/platform.cpp @@ -695,6 +695,11 @@ class CorePS { CorePS* CorePS::sInstance = nullptr; +ProfileChunkedBuffer& profiler_get_core_buffer() { + MOZ_ASSERT(CorePS::Exists()); + return CorePS::CoreBuffer(); +} + class SamplerThread; static SamplerThread* NewSamplerThread(PSLockRef aLock, uint32_t aGeneration, diff --git a/tools/profiler/public/ProfilerMarkersDetail.h b/tools/profiler/public/ProfilerMarkersDetail.h index 832853e4bfe4..22396b5d2f64 100644 --- a/tools/profiler/public/ProfilerMarkersDetail.h +++ b/tools/profiler/public/ProfilerMarkersDetail.h @@ -23,6 +23,20 @@ // Header that specializes the (de)serializers for xpcom types. # include "mozilla/ProfileBufferEntrySerializationGeckoExtensions.h" +// Implemented in platform.cpp +mozilla::ProfileChunkedBuffer& profiler_get_core_buffer(); + +namespace profiler_markers_detail { + +// Get the core buffer from the profiler, and cache it in a +// non-templated-function static reference. +inline mozilla::ProfileChunkedBuffer& CachedCoreBuffer() { + static mozilla::ProfileChunkedBuffer& coreBuffer = profiler_get_core_buffer(); + return coreBuffer; +} + +} // namespace profiler_markers_detail + #endif // MOZ_GECKO_PROFILER #endif // ProfilerMarkersDetail_h