#include "base/sampling_heap_profiler/poisson_allocation_sampler.h"
#include <atomic>
#include <cmath>
#include <memory>
#include <utility>
#include "base/allocator/dispatcher/reentry_guard.h"
#include "base/allocator/dispatcher/tls.h"
#include "base/check.h"
#include "base/compiler_specific.h"
#include "base/no_destructor.h"
#include "base/rand_util.h"
#include "base/ranges/algorithm.h"
#include "build/build_config.h"
#include "third_party/abseil-cpp/absl/base/attributes.h"
namespace base {
namespace {
ReentryGuard;
const size_t kDefaultSamplingIntervalBytes = …;
const intptr_t kAccumulatedBytesOffset = …;
bool g_deterministic = …;
ABSL_CONST_INIT std::atomic<LockFreeAddressHashSet*> g_sampled_addresses_set{ … };
ABSL_CONST_INIT std::atomic_size_t g_sampling_interval{ … };
struct ThreadLocalData { … };
ThreadLocalData* GetThreadLocalData() { … }
}
PoissonAllocationSampler::ScopedMuteThreadSamples::ScopedMuteThreadSamples() { … }
PoissonAllocationSampler::ScopedMuteThreadSamples::~ScopedMuteThreadSamples() { … }
bool PoissonAllocationSampler::ScopedMuteThreadSamples::IsMuted() { … }
PoissonAllocationSampler::ScopedSuppressRandomnessForTesting::
ScopedSuppressRandomnessForTesting() { … }
PoissonAllocationSampler::ScopedSuppressRandomnessForTesting::
~ScopedSuppressRandomnessForTesting() { … }
bool PoissonAllocationSampler::ScopedSuppressRandomnessForTesting::
IsSuppressed() { … }
PoissonAllocationSampler::ScopedMuteHookedSamplesForTesting::
ScopedMuteHookedSamplesForTesting() { … }
PoissonAllocationSampler::ScopedMuteHookedSamplesForTesting::
~ScopedMuteHookedSamplesForTesting() { … }
PoissonAllocationSampler::ScopedMuteHookedSamplesForTesting::
ScopedMuteHookedSamplesForTesting(ScopedMuteHookedSamplesForTesting&&) =
default;
PoissonAllocationSampler::ScopedMuteHookedSamplesForTesting&
PoissonAllocationSampler::ScopedMuteHookedSamplesForTesting::operator=(
ScopedMuteHookedSamplesForTesting&&) = default;
ABSL_CONST_INIT std::atomic<PoissonAllocationSampler::ProfilingStateFlagMask>
PoissonAllocationSampler::profiling_state_{ … };
PoissonAllocationSampler::PoissonAllocationSampler() { … }
void PoissonAllocationSampler::Init() { … }
void PoissonAllocationSampler::SetSamplingInterval(
size_t sampling_interval_bytes) { … }
size_t PoissonAllocationSampler::SamplingInterval() const { … }
size_t PoissonAllocationSampler::GetNextSampleInterval(size_t interval) { … }
void PoissonAllocationSampler::DoRecordAllocation(
const ProfilingStateFlagMask state,
void* address,
size_t size,
base::allocator::dispatcher::AllocationSubsystem type,
const char* context) { … }
void PoissonAllocationSampler::DoRecordFree(void* address) { … }
void PoissonAllocationSampler::BalanceAddressesHashSet() { … }
LockFreeAddressHashSet& PoissonAllocationSampler::sampled_addresses_set() { … }
PoissonAllocationSampler* PoissonAllocationSampler::Get() { … }
void PoissonAllocationSampler::SetProfilingStateFlag(ProfilingStateFlag flag) { … }
void PoissonAllocationSampler::ResetProfilingStateFlag(
ProfilingStateFlag flag) { … }
void PoissonAllocationSampler::AddSamplesObserver(SamplesObserver* observer) { … }
void PoissonAllocationSampler::RemoveSamplesObserver(
SamplesObserver* observer) { … }
}