From 1cf3bc392aa281a593980263337608c3bbb35443 Mon Sep 17 00:00:00 2001 From: Gerald Squelart Date: Mon, 23 Aug 2021 22:23:34 +0000 Subject: [PATCH] Bug 1726657 - Only record sampling overheads if MOZ_PROFILER_RECORD_OVERHEADS is set - r=florian Sampling overheads are very rarely useful, but they occupy some space during profiling, but also a lot of space in the final JSON profile. So now they will only be recorded if the environment variable "MOZ_PROFILER_RECORD_OVERHEADS" is set to any non-empty value. Differential Revision: https://phabricator.services.mozilla.com/D123303 --- mozglue/baseprofiler/core/ProfileBuffer.cpp | 18 ++++++++++++------ tools/profiler/core/ProfileBuffer.cpp | 16 +++++++++++----- 2 files changed, 23 insertions(+), 11 deletions(-) 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 {