Commit 3bc9c6f2 authored by Etienne Pierre-doray's avatar Etienne Pierre-doray Committed by Commit Bot

[Clank SSM]: Inject Unwinder in StackSampler.

Add Unwinder as optional param in StackSampler that's used if present.
This is necessary for follow up NativeUnwinderAndroid that doesn't have
a default constructor.

Late creation of StackSampler in StackSamplingProfiler is also removed
because this won't be possible with NativeUnwinderAndroid. Instead, StackSampler
is always created in constructor or injected.

Bug: 989102
Change-Id: Ib90416659f28d7139baed8d7adba62836337b13e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2095372
Commit-Queue: Etienne Pierre-Doray <etiennep@chromium.org>
Reviewed-by: default avataroysteine <oysteine@chromium.org>
Reviewed-by: default avatarMike Wittman <wittman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#755046}
parent 207da34f
...@@ -33,7 +33,8 @@ class BASE_EXPORT StackSampler { ...@@ -33,7 +33,8 @@ class BASE_EXPORT StackSampler {
static std::unique_ptr<StackSampler> Create( static std::unique_ptr<StackSampler> Create(
SamplingProfilerThreadToken thread_token, SamplingProfilerThreadToken thread_token,
ModuleCache* module_cache, ModuleCache* module_cache,
StackSamplerTestDelegate* test_delegate); StackSamplerTestDelegate* test_delegate,
std::unique_ptr<Unwinder> native_unwinder = nullptr);
// Gets the required size of the stack buffer. // Gets the required size of the stack buffer.
static size_t GetStackBufferSize(); static size_t GetStackBufferSize();
......
...@@ -6,10 +6,10 @@ ...@@ -6,10 +6,10 @@
#include <pthread.h> #include <pthread.h>
#include "base/profiler/native_unwinder_android.h"
#include "base/profiler/stack_copier_signal.h" #include "base/profiler/stack_copier_signal.h"
#include "base/profiler/stack_sampler_impl.h" #include "base/profiler/stack_sampler_impl.h"
#include "base/profiler/thread_delegate_posix.h" #include "base/profiler/thread_delegate_posix.h"
#include "base/profiler/unwinder.h"
#include "base/threading/platform_thread.h" #include "base/threading/platform_thread.h"
namespace base { namespace base {
...@@ -17,11 +17,12 @@ namespace base { ...@@ -17,11 +17,12 @@ namespace base {
std::unique_ptr<StackSampler> StackSampler::Create( std::unique_ptr<StackSampler> StackSampler::Create(
SamplingProfilerThreadToken thread_token, SamplingProfilerThreadToken thread_token,
ModuleCache* module_cache, ModuleCache* module_cache,
StackSamplerTestDelegate* test_delegate) { StackSamplerTestDelegate* test_delegate,
std::unique_ptr<Unwinder> native_unwinder) {
return std::make_unique<StackSamplerImpl>( return std::make_unique<StackSamplerImpl>(
std::make_unique<StackCopierSignal>( std::make_unique<StackCopierSignal>(
std::make_unique<ThreadDelegatePosix>(thread_token)), std::make_unique<ThreadDelegatePosix>(thread_token)),
std::make_unique<NativeUnwinderAndroid>(), module_cache, test_delegate); std::move(native_unwinder), module_cache, test_delegate);
} }
size_t StackSampler::GetStackBufferSize() { size_t StackSampler::GetStackBufferSize() {
......
...@@ -13,7 +13,8 @@ namespace base { ...@@ -13,7 +13,8 @@ namespace base {
std::unique_ptr<StackSampler> StackSampler::Create( std::unique_ptr<StackSampler> StackSampler::Create(
SamplingProfilerThreadToken thread_token, SamplingProfilerThreadToken thread_token,
ModuleCache* module_cache, ModuleCache* module_cache,
StackSamplerTestDelegate* test_delegate) { StackSamplerTestDelegate* test_delegate,
std::unique_ptr<Unwinder> native_unwinder) {
return nullptr; return nullptr;
} }
......
...@@ -15,7 +15,9 @@ namespace base { ...@@ -15,7 +15,9 @@ namespace base {
std::unique_ptr<StackSampler> StackSampler::Create( std::unique_ptr<StackSampler> StackSampler::Create(
SamplingProfilerThreadToken thread_token, SamplingProfilerThreadToken thread_token,
ModuleCache* module_cache, ModuleCache* module_cache,
StackSamplerTestDelegate* test_delegate) { StackSamplerTestDelegate* test_delegate,
std::unique_ptr<Unwinder> native_unwinder) {
DCHECK(!native_unwinder);
return std::make_unique<StackSamplerImpl>( return std::make_unique<StackSamplerImpl>(
std::make_unique<StackCopierSuspend>( std::make_unique<StackCopierSuspend>(
std::make_unique<SuspendableThreadDelegateMac>(thread_token)), std::make_unique<SuspendableThreadDelegateMac>(thread_token)),
......
...@@ -14,7 +14,8 @@ namespace base { ...@@ -14,7 +14,8 @@ namespace base {
std::unique_ptr<StackSampler> StackSampler::Create( std::unique_ptr<StackSampler> StackSampler::Create(
SamplingProfilerThreadToken thread_token, SamplingProfilerThreadToken thread_token,
ModuleCache* module_cache, ModuleCache* module_cache,
StackSamplerTestDelegate* test_delegate) { StackSamplerTestDelegate* test_delegate,
std::unique_ptr<Unwinder> native_unwinder) {
return nullptr; return nullptr;
} }
......
...@@ -16,7 +16,9 @@ namespace base { ...@@ -16,7 +16,9 @@ namespace base {
std::unique_ptr<StackSampler> StackSampler::Create( std::unique_ptr<StackSampler> StackSampler::Create(
SamplingProfilerThreadToken thread_token, SamplingProfilerThreadToken thread_token,
ModuleCache* module_cache, ModuleCache* module_cache,
StackSamplerTestDelegate* test_delegate) { StackSamplerTestDelegate* test_delegate,
std::unique_ptr<Unwinder> native_unwinder) {
DCHECK(!native_unwinder);
#if defined(ARCH_CPU_X86_64) || defined(ARCH_CPU_ARM64) #if defined(ARCH_CPU_X86_64) || defined(ARCH_CPU_ARM64)
return std::make_unique<StackSamplerImpl>( return std::make_unique<StackSamplerImpl>(
std::make_unique<StackCopierSuspend>( std::make_unique<StackCopierSuspend>(
......
...@@ -694,27 +694,22 @@ StackSamplingProfiler::StackSamplingProfiler( ...@@ -694,27 +694,22 @@ StackSamplingProfiler::StackSamplingProfiler(
const SamplingParams& params, const SamplingParams& params,
std::unique_ptr<ProfileBuilder> profile_builder, std::unique_ptr<ProfileBuilder> profile_builder,
StackSamplerTestDelegate* test_delegate) StackSamplerTestDelegate* test_delegate)
: StackSamplingProfiler(thread_token, : StackSamplingProfiler(params, std::move(profile_builder), nullptr) {
params, sampler_ = StackSampler::Create(
std::move(profile_builder), thread_token, profile_builder_->GetModuleCache(), test_delegate);
nullptr, }
test_delegate) {}
StackSamplingProfiler::StackSamplingProfiler( StackSamplingProfiler::StackSamplingProfiler(
SamplingProfilerThreadToken thread_token,
const SamplingParams& params, const SamplingParams& params,
std::unique_ptr<ProfileBuilder> profile_builder, std::unique_ptr<ProfileBuilder> profile_builder,
std::unique_ptr<StackSampler> sampler, std::unique_ptr<StackSampler> sampler)
StackSamplerTestDelegate* test_delegate) : params_(params),
: thread_token_(thread_token),
params_(params),
profile_builder_(std::move(profile_builder)), profile_builder_(std::move(profile_builder)),
sampler_(std::move(sampler)), sampler_(std::move(sampler)),
// The event starts "signaled" so code knows it's safe to start thread // The event starts "signaled" so code knows it's safe to start thread
// and "manual" so that it can be waited in multiple places. // and "manual" so that it can be waited in multiple places.
profiling_inactive_(kResetPolicy, WaitableEvent::InitialState::SIGNALED), profiling_inactive_(kResetPolicy, WaitableEvent::InitialState::SIGNALED),
profiler_id_(kNullProfilerId), profiler_id_(kNullProfilerId) {
test_delegate_(test_delegate) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cpu_profiler"), TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cpu_profiler"),
"StackSamplingProfiler::StackSamplingProfiler"); "StackSamplingProfiler::StackSamplingProfiler");
DCHECK(profile_builder_); DCHECK(profile_builder_);
...@@ -751,10 +746,8 @@ void StackSamplingProfiler::Start() { ...@@ -751,10 +746,8 @@ void StackSamplingProfiler::Start() {
// already. // already.
DCHECK(profile_builder_); DCHECK(profile_builder_);
if (!sampler_) // |sampler_| will be null if sampling isn't supported on the current
sampler_ = StackSampler::Create( // platform.
thread_token_, profile_builder_->GetModuleCache(), test_delegate_);
if (!sampler_) if (!sampler_)
return; return;
......
...@@ -95,11 +95,9 @@ class BASE_EXPORT StackSamplingProfiler { ...@@ -95,11 +95,9 @@ class BASE_EXPORT StackSamplingProfiler {
// Same as above function, with custom |sampler| implementation. The sampler // Same as above function, with custom |sampler| implementation. The sampler
// on Android is not implemented in base. // on Android is not implemented in base.
StackSamplingProfiler(SamplingProfilerThreadToken thread_token, StackSamplingProfiler(const SamplingParams& params,
const SamplingParams& params,
std::unique_ptr<ProfileBuilder> profile_builder, std::unique_ptr<ProfileBuilder> profile_builder,
std::unique_ptr<StackSampler> sampler, std::unique_ptr<StackSampler> sampler);
StackSamplerTestDelegate* test_delegate = nullptr);
// Stops any profiling currently taking place before destroying the profiler. // Stops any profiling currently taking place before destroying the profiler.
// This will block until profile_builder_'s OnProfileCompleted function has // This will block until profile_builder_'s OnProfileCompleted function has
...@@ -202,9 +200,6 @@ class BASE_EXPORT StackSamplingProfiler { ...@@ -202,9 +200,6 @@ class BASE_EXPORT StackSamplingProfiler {
// will be an internal "null" value when no collection has been started. // will be an internal "null" value when no collection has been started.
int profiler_id_; int profiler_id_;
// Stored until it can be passed to the StackSampler created in Start().
StackSamplerTestDelegate* const test_delegate_;
DISALLOW_COPY_AND_ASSIGN(StackSamplingProfiler); DISALLOW_COPY_AND_ASSIGN(StackSamplingProfiler);
}; };
......
...@@ -571,7 +571,7 @@ void TracingSamplerProfiler::StartTracing( ...@@ -571,7 +571,7 @@ void TracingSamplerProfiler::StartTracing(
#if BUILDFLAG(CAN_UNWIND_WITH_CFI_TABLE) && defined(OFFICIAL_BUILD) #if BUILDFLAG(CAN_UNWIND_WITH_CFI_TABLE) && defined(OFFICIAL_BUILD)
auto* module_cache = profile_builder->GetModuleCache(); auto* module_cache = profile_builder->GetModuleCache();
profiler_ = std::make_unique<base::StackSamplingProfiler>( profiler_ = std::make_unique<base::StackSamplingProfiler>(
sampled_thread_token_, params, std::move(profile_builder), params, std::move(profile_builder),
std::make_unique<StackSamplerAndroid>(sampled_thread_token_, std::make_unique<StackSamplerAndroid>(sampled_thread_token_,
module_cache)); module_cache));
profiler_->Start(); profiler_->Start();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment