#include "chrome/common/profiler/main_thread_stack_sampling_profiler.h"
#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/threading/platform_thread.h"
#include "chrome/common/profiler/process_type.h"
#include "components/metrics/call_stacks/call_stack_profile_builder.h"
#include "components/metrics/call_stacks/call_stack_profile_metrics_provider.h"
#include "components/sampling_profiler/process_type.h"
#include "components/sampling_profiler/thread_profiler.h"
#include "content/public/common/content_switches.h"
namespace {
std::unique_ptr<sampling_profiler::ThreadProfiler> CreateThreadProfiler(
const sampling_profiler::ProfilerProcessType process) {
if (process == sampling_profiler::ProfilerProcessType::kBrowser) {
metrics::CallStackProfileBuilder::SetBrowserProcessReceiverCallback(
base::BindRepeating(
&metrics::CallStackProfileMetricsProvider::ReceiveProfile));
return sampling_profiler::ThreadProfiler::CreateAndStartOnMainThread();
}
return nullptr;
}
}
MainThreadStackSamplingProfiler::MainThreadStackSamplingProfiler() {
const sampling_profiler::ProfilerProcessType process =
GetProfilerProcessType(*base::CommandLine::ForCurrentProcess());
sampling_profiler_ = CreateThreadProfiler(process);
}
MainThreadStackSamplingProfiler::~MainThreadStackSamplingProfiler() = default;