#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "components/services/heap_profiling/public/cpp/profiling_client.h"
#include <string>
#include <unordered_set>
#include <utility>
#include <vector>
#include "base/debug/stack_trace.h"
#include "base/no_destructor.h"
#include "base/notreached.h"
#include "base/sampling_heap_profiler/poisson_allocation_sampler.h"
#include "base/sampling_heap_profiler/sampling_heap_profiler.h"
#include "base/trace_event/heap_profiler_allocation_context_tracker.h"
#include "base/trace_event/malloc_dump_provider.h"
#include "base/trace_event/memory_dump_manager.h"
#include "build/build_config.h"
#include "partition_alloc/buildflags.h"
#if !BUILDFLAG(IS_IOS)
#include "components/services/heap_profiling/public/cpp/heap_profiling_trace_source.h"
#endif
#if BUILDFLAG(IS_APPLE) && !PA_BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC) && \
PA_BUILDFLAG(USE_ALLOCATOR_SHIM)
#include "partition_alloc/shim/allocator_interception_apple.h"
#endif
AllocationSubsystem;
namespace heap_profiling {
ProfilingClient::ProfilingClient() = default;
ProfilingClient::~ProfilingClient() = default;
void ProfilingClient::BindToInterface(
mojo::PendingReceiver<mojom::ProfilingClient> receiver) { … }
#if BUILDFLAG(IS_APPLE) && !PA_BUILDFLAG(USE_PARTITION_ALLOC_AS_MALLOC) && \
PA_BUILDFLAG(USE_ALLOCATOR_SHIM)
void ShimNewMallocZonesAndReschedule(base::Time end_time,
base::TimeDelta delay) {
allocator_shim::ShimNewMallocZones();
if (base::Time::Now() > end_time) {
return;
}
base::TimeDelta next_delay = delay * 2;
base::SequencedTaskRunner::GetCurrentDefault()->PostDelayedTask(
FROM_HERE,
base::BindOnce(&ShimNewMallocZonesAndReschedule, end_time, next_delay),
delay);
}
#endif
void ProfilingClient::StartProfiling(mojom::ProfilingParamsPtr params,
StartProfilingCallback callback) { … }
namespace {
bool g_initialized_ = …;
base::Lock& GetOnInitAllocatorShimLock() { … }
base::OnceClosure& GetOnInitAllocatorShimCallback() { … }
scoped_refptr<base::TaskRunner>& GetOnInitAllocatorShimTaskRunner() { … }
bool g_include_thread_names = …;
void InitAllocationRecorder(mojom::ProfilingParamsPtr params) { … }
void AllocatorHooksHaveBeenInitialized() { … }
mojom::AllocatorType ConvertType(AllocationSubsystem type) { … }
}
void InitTLSSlot() { … }
bool SetOnInitAllocatorShimCallbackForTesting(
base::OnceClosure callback,
scoped_refptr<base::TaskRunner> task_runner) { … }
void ProfilingClient::StartProfilingInternal(mojom::ProfilingParamsPtr params,
StartProfilingCallback callback) { … }
void ProfilingClient::RetrieveHeapProfile(
RetrieveHeapProfileCallback callback) { … }
void ProfilingClient::AddHeapProfileToTrace(
AddHeapProfileToTraceCallback callback) { … }
}