Commit 515f341a authored by erikchen's avatar erikchen Committed by Commit Bot

Fix a bug in sampling algorithm for OOP HP.

The previous algorithm would overcount small allocations that immediately follow
a very large allocation. See
https://bugs.chromium.org/p/chromium/issues/detail?id=810748#c6 for more
details.

The new algorithm samples small allocations as before, but now always records
large allocations.

Bug: 810748
Change-Id: Ic6f23db49825a07e9e7320addd9ff1d465d0a967
Reviewed-on: https://chromium-review.googlesource.com/919461
Commit-Queue: Erik Chen <erikchen@chromium.org>
Reviewed-by: default avatarAlbert J. Wong <ajwong@chromium.org>
Cr-Commit-Position: refs/heads/master@{#536781}
parent 03518213
......@@ -53,6 +53,9 @@ bool g_include_thread_names = false;
// Whether to sample allocations.
bool g_sample_allocations = false;
// Sampling rate describes the probability of sampling small allocations.
// Probability = MIN((size of allocation) / g_sampling_rate, 1).
uint32_t g_sampling_rate = 0;
// Prime since this is used like a hash table. Numbers of this magnitude seemed
......@@ -687,11 +690,19 @@ void AllocatorShimLogAlloc(AllocatorType type,
if (!send_buffers)
return;
if (g_sample_allocations) {
// Sample allocations smaller than g_sampling_rate. Always record larger
// allocations. [There's no point in sampling larger allocations since we
// want to record them with probability 1. Just do that.]
if (g_sample_allocations && LIKELY(sz < g_sampling_rate)) {
ShimState* shim_state = GetShimState();
// Update the sampling interval, if necessary. This also handles the case
// where the sampling interval has not yet been initialized.
//
// interval_to_next_sample is actually an underflowing counter that
// triggers a sample. Incrementing by GetNextSampleInterval() provides a
// poisson process sampling of allocations with probability = (sz /
// g_sampling_rate).
if (shim_state->interval_to_next_sample <= 0) {
shim_state->interval_to_next_sample +=
GetNextSampleInterval(g_sampling_rate);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment