diff options
Diffstat (limited to 'chromium/base/sampling_heap_profiler')
-rw-r--r-- | chromium/base/sampling_heap_profiler/poisson_allocation_sampler.cc | 35 | ||||
-rw-r--r-- | chromium/base/sampling_heap_profiler/poisson_allocation_sampler.h | 4 |
2 files changed, 20 insertions, 19 deletions
diff --git a/chromium/base/sampling_heap_profiler/poisson_allocation_sampler.cc b/chromium/base/sampling_heap_profiler/poisson_allocation_sampler.cc index 6bee5c0e442..3d9d928f341 100644 --- a/chromium/base/sampling_heap_profiler/poisson_allocation_sampler.cc +++ b/chromium/base/sampling_heap_profiler/poisson_allocation_sampler.cc @@ -412,11 +412,11 @@ void PoissonAllocationSampler::RecordAlloc(void* address, return; if (UNLIKELY(!g_running.load(std::memory_order_relaxed))) { - // Sampling is in fact disabled. Put a large negative value into - // the accumulator. It needs to be large enough to have this code - // not trigger frequently, and small enough to eventually start collecting - // samples when the sampling is enabled. - g_accumulated_bytes_tls = -static_cast<intptr_t>(kWarmupInterval); + // Sampling is in fact disabled. Reset the state of the sampler. + // We do this check off the fast-path, because it's quite a rare state when + // allocation hooks are installed but the sampler is not running. + g_sampling_interval_initialized_tls = false; + g_accumulated_bytes_tls = 0; return; } @@ -433,6 +433,21 @@ void PoissonAllocationSampler::DoRecordAlloc(intptr_t accumulated_bytes, return; size_t mean_interval = g_sampling_interval.load(std::memory_order_relaxed); + + if (UNLIKELY(!g_sampling_interval_initialized_tls)) { + g_sampling_interval_initialized_tls = true; + // This is the very first allocation on the thread. It always makes it + // passing the condition at |RecordAlloc|, because g_accumulated_bytes_tls + // is initialized with zero due to TLS semantics. + // Generate proper sampling interval instance and make sure the allocation + // has indeed crossed the threshold before counting it as a sample. + accumulated_bytes -= GetNextSampleInterval(mean_interval); + if (accumulated_bytes < 0) { + g_accumulated_bytes_tls = accumulated_bytes; + return; + } + } + size_t samples = accumulated_bytes / mean_interval; accumulated_bytes %= mean_interval; @@ -443,16 +458,6 @@ void PoissonAllocationSampler::DoRecordAlloc(intptr_t accumulated_bytes, g_accumulated_bytes_tls = accumulated_bytes; - if (UNLIKELY(!g_sampling_interval_initialized_tls)) { - g_sampling_interval_initialized_tls = true; - // This is the very first allocation on the thread. It always produces an - // extra sample because g_accumulated_bytes_tls is initialized with zero - // due to TLS semantics. - // Make sure we don't count this extra sample. - if (!--samples) - return; - } - if (UNLIKELY(ScopedMuteThreadSamples::IsMuted())) return; diff --git a/chromium/base/sampling_heap_profiler/poisson_allocation_sampler.h b/chromium/base/sampling_heap_profiler/poisson_allocation_sampler.h index 6006bff19b6..116123940a6 100644 --- a/chromium/base/sampling_heap_profiler/poisson_allocation_sampler.h +++ b/chromium/base/sampling_heap_profiler/poisson_allocation_sampler.h @@ -35,10 +35,6 @@ class BASE_EXPORT PoissonAllocationSampler { public: enum AllocatorType : uint32_t { kMalloc, kPartitionAlloc, kBlinkGC }; - // When the sampler is just enabled it needs to see up to that amount - // of allocation sizes before it starts recording samples. - static constexpr size_t kWarmupInterval = 1 << 20; // 1MB. - class SamplesObserver { public: virtual ~SamplesObserver() = default; |