chromium/base/sampling_heap_profiler/sampling_heap_profiler_unittest.cc

// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/sampling_heap_profiler/sampling_heap_profiler.h"

#include <stdlib.h>
#include <cinttypes>

#include "base/allocator/dispatcher/dispatcher.h"
#include "base/allocator/dispatcher/notification_data.h"
#include "base/allocator/dispatcher/subsystem.h"
#include "base/debug/alias.h"
#include "base/memory/raw_ptr.h"
#include "base/rand_util.h"
#include "base/sampling_heap_profiler/poisson_allocation_sampler.h"
#include "base/synchronization/waitable_event.h"
#include "base/threading/simple_thread.h"
#include "build/build_config.h"
#include "partition_alloc/shim/allocator_shim.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace base {

ScopedSuppressRandomnessForTesting;
AllocationNotificationData;
AllocationSubsystem;
FreeNotificationData;

class SamplingHeapProfilerTest : public ::testing::Test {};

class SamplesCollector : public PoissonAllocationSampler::SamplesObserver {};

TEST_F(SamplingHeapProfilerTest, SampleObserver) {}

TEST_F(SamplingHeapProfilerTest, SampleObserverMuted) {}

TEST_F(SamplingHeapProfilerTest, IntervalRandomizationSanity) {}

#if BUILDFLAG(IS_IOS)
// iOS devices generally have ~4GB of RAM with no swap and therefore need a
// lower allocation limit here.
const int kNumberOfAllocations = 1000;
#else
const int kNumberOfAllocations =;
#endif

NOINLINE void Allocate1() {}

NOINLINE void Allocate2() {}

NOINLINE void Allocate3() {}

class MyThread1 : public SimpleThread {};

class MyThread2 : public SimpleThread {};

void CheckAllocationPattern(void (*allocate_callback)()) {}

// Manual tests to check precision of the sampling profiler.
// Yes, they do leak lots of memory.

TEST_F(SamplingHeapProfilerTest, DISABLED_ParallelLargeSmallStats) {}

TEST_F(SamplingHeapProfilerTest, DISABLED_SequentialLargeSmallStats) {}

// Platform TLS: alloc+free[ns]: 22.184  alloc[ns]: 8.910  free[ns]: 13.274
// thread_local: alloc+free[ns]: 18.353  alloc[ns]: 5.021  free[ns]: 13.331
// TODO(crbug.com/40145097) Disabled on Mac
#if BUILDFLAG(IS_MAC)
#define MAYBE_MANUAL_SamplerMicroBenchmark
#else
#define MAYBE_MANUAL_SamplerMicroBenchmark
#endif
TEST_F(SamplingHeapProfilerTest, MAYBE_MANUAL_SamplerMicroBenchmark) {}

class StartStopThread : public SimpleThread {};

TEST_F(SamplingHeapProfilerTest, StartStop) {}

// TODO(crbug.com/40711998): Test is crashing on Mac.
#if BUILDFLAG(IS_MAC)
#define MAYBE_ConcurrentStartStop
#else
#define MAYBE_ConcurrentStartStop
#endif
TEST_F(SamplingHeapProfilerTest, MAYBE_ConcurrentStartStop) {}

TEST_F(SamplingHeapProfilerTest, HookedAllocatorMuted) {}

}  // namespace base