diff --git a/tools/profiler/core/platform.cpp b/tools/profiler/core/platform.cpp index fbe7b2be20a3..43ff351d485d 100644 --- a/tools/profiler/core/platform.cpp +++ b/tools/profiler/core/platform.cpp @@ -1538,6 +1538,19 @@ void ProfilingStackOwner::DumpStackAndCrash() const { // The name of the main thread. static const char* const kMainThreadName = "GeckoMain"; +// Add the marker to the given buffer with the given information. +// This is a unified insertion point for all the markers. +template +static void StoreMarker(Buffer& aBuffer, int aThreadId, const char* aMarkerName, + JS::ProfilingCategoryPair aCategoryPair, + const ProfilerMarkerPayload* aPayload, + const mozilla::TimeStamp& aTime) { + aBuffer.PutObjects(ProfileBufferEntry::Kind::MarkerData, aThreadId, + WrapProfileBufferUnownedCString(aMarkerName), + static_cast(aCategoryPair), aPayload, + (aTime - CorePS::ProcessStartTime()).ToMilliseconds()); +} + //////////////////////////////////////////////////////////////////////// // BEGIN sampling/unwinding code @@ -4989,11 +5002,8 @@ static void racy_profiler_add_marker(const char* aMarkerName, TimeStamp origin = (aPayload && !aPayload->GetStartTime().IsNull()) ? aPayload->GetStartTime() : TimeStamp::NowUnfuzzed(); - TimeDuration delta = origin - CorePS::ProcessStartTime(); - CorePS::CoreBuffer().PutObjects( - ProfileBufferEntry::Kind::MarkerData, racyRegisteredThread->ThreadId(), - WrapProfileBufferUnownedCString(aMarkerName), - static_cast(aCategoryPair), aPayload, delta.ToMilliseconds()); + StoreMarker(CorePS::CoreBuffer(), racyRegisteredThread->ThreadId(), + aMarkerName, aCategoryPair, aPayload, origin); } void profiler_add_marker(const char* aMarkerName, @@ -5111,11 +5121,8 @@ static void maybelocked_profiler_add_marker_for_thread( TimeStamp origin = (!aPayload.GetStartTime().IsNull()) ? aPayload.GetStartTime() : TimeStamp::NowUnfuzzed(); - TimeDuration delta = origin - CorePS::ProcessStartTime(); - CorePS::CoreBuffer().PutObjects( - ProfileBufferEntry::Kind::MarkerData, aThreadId, - WrapProfileBufferUnownedCString(aMarkerName), - static_cast(aCategoryPair), &aPayload, delta.ToMilliseconds()); + StoreMarker(CorePS::CoreBuffer(), aThreadId, aMarkerName, aCategoryPair, + &aPayload, origin); } void profiler_add_marker_for_thread(int aThreadId,