#include "components/heap_profiling/multi_process/test_driver.h"
#include <memory>
#include <optional>
#include <string>
#include "base/command_line.h"
#include "base/containers/contains.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/json/json_reader.h"
#include "base/process/process_handle.h"
#include "base/run_loop.h"
#include "base/sampling_heap_profiler/poisson_allocation_sampler.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.h"
#include "base/threading/platform_thread.h"
#include "base/trace_event/heap_profiler.h"
#include "base/values.h"
#include "build/build_config.h"
#include "components/heap_profiling/multi_process/supervisor.h"
#include "components/services/heap_profiling/public/cpp/controller.h"
#include "components/services/heap_profiling/public/cpp/profiling_client.h"
#include "components/services/heap_profiling/public/cpp/settings.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/tracing_controller.h"
#include "partition_alloc/partition_root.h"
namespace heap_profiling {
namespace {
constexpr const char kTestCategory[] = …;
const char kMallocEvent[] = …;
const char kMallocTypeTag[] = …;
const char kMallocVariadicTypeTag[] = …;
const char kPAEvent[] = …;
const char kVariadicEvent[] = …;
const char kThreadName[] = …;
constexpr int kMallocAllocSize = …;
constexpr int kMallocAllocCount = …;
constexpr int kVariadicAllocCount = …;
constexpr int kSampleRate = …;
constexpr int kPartitionAllocSize = …;
constexpr int kPartitionAllocCount = …;
static const char* kPartitionAllocTypeName = …;
bool RenderersAreBeingProfiled(
const std::vector<base::ProcessId>& profiled_pids) { … }
int NumProcessesWithName(const base::Value::Dict& dump_json,
std::string name,
std::vector<int>* pids) { … }
const base::Value::Dict* FindArgDump(base::ProcessId pid,
const base::Value::Dict& dump_json,
const char* arg) { … }
constexpr uint64_t kNullParent = …;
struct Node { … };
NodeMap;
bool ParseTypes(const base::Value::Dict* heaps_v2, NodeMap* output) { … }
bool GetAllocatorSubarray(const base::Value::Dict* heaps_v2,
const char* allocator_name,
const char* subarray_name,
size_t expected_size,
const base::Value::List*& output) { … }
bool ValidateSamplingAllocations(const base::Value::Dict* heaps_v2,
const char* allocator_name,
int approximate_size,
int approximate_count,
const char* type_name) { … }
bool ValidateProcessMmaps(const base::Value::Dict* process_mmaps,
bool should_have_contents) { … }
void HandleOOM(size_t unused_size) { … }
}
TestDriver::TestDriver()
: … { … }
TestDriver::~TestDriver() { … }
bool TestDriver::RunTest(const Options& options) { … }
void TestDriver::GetHasStartedOnUIThread() { … }
void TestDriver::CheckOrStartProfilingOnUIThreadAndSignal() { … }
bool TestDriver::CheckOrStartProfilingOnUIThreadWithAsyncSignalling() { … }
bool TestDriver::CheckOrStartProfilingOnUIThreadWithNestedRunLoops() { … }
void TestDriver::MakeTestAllocations() { … }
void TestDriver::CollectResults(bool synchronous) { … }
void TestDriver::TraceFinished(base::OnceClosure closure,
bool success,
std::string trace_json) { … }
bool TestDriver::ValidateBrowserAllocations(
const base::Value::Dict& dump_json) { … }
bool TestDriver::ValidateRendererAllocations(
const base::Value::Dict& dump_json) { … }
bool TestDriver::ShouldProfileBrowser() { … }
bool TestDriver::ShouldProfileRenderer() { … }
bool TestDriver::ShouldIncludeNativeThreadNames() { … }
bool TestDriver::HasNativeFrames() { … }
void TestDriver::WaitForProfilingToStartForBrowserUIThread() { … }
void TestDriver::WaitForProfilingToStartForAllRenderersUIThread() { … }
void TestDriver::WaitForProfilingToStartForAllRenderersUIThreadAndSignal() { … }
void TestDriver::WaitForProfilingToStartForAllRenderersUIThreadCallback(
std::vector<base::ProcessId> results) { … }
}