#include "chrome/common/profiler/thread_profiler.h"
#include <string>
#include <utility>
#include <vector>
#include "base/android/library_loader/anchor_functions.h"
#include "base/command_line.h"
#include "base/functional/bind.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/message_loop/work_id_provider.h"
#include "base/process/process.h"
#include "base/profiler/process_type.h"
#include "base/profiler/profiler_buildflags.h"
#include "base/profiler/sample_metadata.h"
#include "base/profiler/sampling_profiler_thread_token.h"
#include "base/rand_util.h"
#include "base/task/single_thread_task_runner.h"
#include "base/threading/platform_thread.h"
#include "base/threading/sequence_local_storage_slot.h"
#include "build/build_config.h"
#include "chrome/common/profiler/process_type.h"
#include "chrome/common/profiler/thread_profiler_configuration.h"
#include "chrome/common/profiler/unwind_util.h"
#include "components/metrics/call_stacks/call_stack_profile_builder.h"
#include "components/metrics/call_stacks/call_stack_profile_metrics_provider.h"
#include "content/public/common/content_switches.h"
#include "sandbox/policy/sandbox.h"
#if BUILDFLAG(IS_ANDROID) && BUILDFLAG(ENABLE_ARM_CFI_TABLE)
#include "chrome/android/modules/stack_unwinder/public/module.h"
#endif
#if BUILDFLAG(IS_MAC)
#include "base/process/port_provider_mac.h"
#endif
CallStackProfileBuilder;
CallStackProfileParams;
StackSamplingProfiler;
namespace {
ThreadProfiler* g_main_thread_instance = …;
constexpr double kFractionOfExecutionTimeToSample = …;
bool IsCurrentProcessBackgrounded() { … }
const base::RepeatingClosure GetApplyPerSampleMetadataCallback(
base::ProfilerProcessType process) { … }
}
PeriodicSamplingScheduler::PeriodicSamplingScheduler(
base::TimeDelta sampling_duration,
double fraction_of_execution_time_to_sample,
base::TimeTicks start_time)
: … { … }
PeriodicSamplingScheduler::~PeriodicSamplingScheduler() = default;
base::TimeDelta PeriodicSamplingScheduler::GetTimeToNextCollection() { … }
double PeriodicSamplingScheduler::RandDouble() const { … }
base::TimeTicks PeriodicSamplingScheduler::Now() const { … }
class ThreadProfiler::WorkIdRecorder : public metrics::WorkIdRecorder { … };
ThreadProfiler::~ThreadProfiler() { … }
std::unique_ptr<ThreadProfiler> ThreadProfiler::CreateAndStartOnMainThread() { … }
void ThreadProfiler::SetMainThreadTaskRunner(
scoped_refptr<base::SingleThreadTaskRunner> task_runner) { … }
void ThreadProfiler::SetAuxUnwinderFactory(
const base::RepeatingCallback<std::unique_ptr<base::Unwinder>()>& factory) { … }
void ThreadProfiler::StartOnChildThread(base::ProfilerThreadType thread) { … }
bool ThreadProfiler::ShouldCollectProfilesForChildProcess() { … }
ThreadProfiler::ThreadProfiler(
base::ProfilerThreadType thread,
scoped_refptr<base::SingleThreadTaskRunner> owning_thread_task_runner)
: … { … }
void ThreadProfiler::OnPeriodicCollectionCompleted(
scoped_refptr<base::SingleThreadTaskRunner> owning_thread_task_runner,
base::WeakPtr<ThreadProfiler> thread_profiler) { … }
void ThreadProfiler::SetMainThreadTaskRunnerImpl(
scoped_refptr<base::SingleThreadTaskRunner> task_runner) { … }
void ThreadProfiler::ScheduleNextPeriodicCollection() { … }
void ThreadProfiler::StartPeriodicSamplingCollection() { … }