diff --git a/mozglue/baseprofiler/core/ProfileBuffer.cpp b/mozglue/baseprofiler/core/ProfileBuffer.cpp index a1fedfc414ae..dd5504274bf1 100644 --- a/mozglue/baseprofiler/core/ProfileBuffer.cpp +++ b/mozglue/baseprofiler/core/ProfileBuffer.cpp @@ -161,12 +161,18 @@ void ProfileBuffer::CollectOverheadStats(TimeDuration aSamplingTime, mCountersUs.Count(countersUs); mThreadsUs.Count(threadsUs); - // Record details in buffer. - AddEntry(ProfileBufferEntry::ProfilerOverheadTime(timeUs)); - AddEntry(ProfileBufferEntry::ProfilerOverheadDuration(lockingUs)); - AddEntry(ProfileBufferEntry::ProfilerOverheadDuration(cleaningUs)); - AddEntry(ProfileBufferEntry::ProfilerOverheadDuration(countersUs)); - AddEntry(ProfileBufferEntry::ProfilerOverheadDuration(threadsUs)); + // Record details in buffer, if requested. + static const bool sRecordSamplingOverhead = []() { + const char* recordOverheads = getenv("MOZ_PROFILER_RECORD_OVERHEADS"); + return recordOverheads && recordOverheads[0] != '\0'; + }(); + if (sRecordSamplingOverhead) { + AddEntry(ProfileBufferEntry::ProfilerOverheadTime(timeUs)); + AddEntry(ProfileBufferEntry::ProfilerOverheadDuration(lockingUs)); + AddEntry(ProfileBufferEntry::ProfilerOverheadDuration(cleaningUs)); + AddEntry(ProfileBufferEntry::ProfilerOverheadDuration(countersUs)); + AddEntry(ProfileBufferEntry::ProfilerOverheadDuration(threadsUs)); + } } ProfilerBufferInfo ProfileBuffer::GetProfilerBufferInfo() const { diff --git a/tools/profiler/core/ProfileBuffer.cpp b/tools/profiler/core/ProfileBuffer.cpp index b1ed19d91e12..e7638ddecc43 100644 --- a/tools/profiler/core/ProfileBuffer.cpp +++ b/tools/profiler/core/ProfileBuffer.cpp @@ -156,11 +156,17 @@ void ProfileBuffer::CollectOverheadStats(double aSamplingTimeMs, mCountersUs.Count(counters); mThreadsUs.Count(threads); - AddEntry(ProfileBufferEntry::ProfilerOverheadTime(aSamplingTimeMs)); - AddEntry(ProfileBufferEntry::ProfilerOverheadDuration(locking)); - AddEntry(ProfileBufferEntry::ProfilerOverheadDuration(cleaning)); - AddEntry(ProfileBufferEntry::ProfilerOverheadDuration(counters)); - AddEntry(ProfileBufferEntry::ProfilerOverheadDuration(threads)); + static const bool sRecordSamplingOverhead = []() { + const char* recordOverheads = getenv("MOZ_PROFILER_RECORD_OVERHEADS"); + return recordOverheads && recordOverheads[0] != '\0'; + }(); + if (sRecordSamplingOverhead) { + AddEntry(ProfileBufferEntry::ProfilerOverheadTime(aSamplingTimeMs)); + AddEntry(ProfileBufferEntry::ProfilerOverheadDuration(locking)); + AddEntry(ProfileBufferEntry::ProfilerOverheadDuration(cleaning)); + AddEntry(ProfileBufferEntry::ProfilerOverheadDuration(counters)); + AddEntry(ProfileBufferEntry::ProfilerOverheadDuration(threads)); + } } ProfilerBufferInfo ProfileBuffer::GetProfilerBufferInfo() const {