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 {
static std::unique_ptr<StackSampler> Create(
SamplingProfilerThreadToken thread_token,
ModuleCache* module_cache,
StackSamplerTestDelegate* test_delegate);
StackSamplerTestDelegate* test_delegate,
std::unique_ptr<Unwinder> native_unwinder = nullptr);
// Gets the required size of the stack buffer.
static size_t GetStackBufferSize();
......
......@@ -6,10 +6,10 @@
#include <pthread.h>
#include "base/profiler/native_unwinder_android.h"
#include "base/profiler/stack_copier_signal.h"
#include "base/profiler/stack_sampler_impl.h"
#include "base/profiler/thread_delegate_posix.h"
#include "base/profiler/unwinder.h"
#include "base/threading/platform_thread.h"
namespace base {
......@@ -17,11 +17,12 @@ namespace base {
std::unique_ptr<StackSampler> StackSampler::Create(
SamplingProfilerThreadToken thread_token,
ModuleCache* module_cache,
StackSamplerTestDelegate* test_delegate) {
StackSamplerTestDelegate* test_delegate,
std::unique_ptr<Unwinder> native_unwinder) {
return std::make_unique<StackSamplerImpl>(
std::make_unique<StackCopierSignal>(
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() {
......
......@@ -13,7 +13,8 @@ namespace base {
std::unique_ptr<StackSampler> StackSampler::Create(
SamplingProfilerThreadToken thread_token,
ModuleCache* module_cache,
StackSamplerTestDelegate* test_delegate) {
StackSamplerTestDelegate* test_delegate,
std::unique_ptr<Unwinder> native_unwinder) {
return nullptr;
}
......
......@@ -15,7 +15,9 @@ namespace base {
std::unique_ptr<StackSampler> StackSampler::Create(
SamplingProfilerThreadToken thread_token,
ModuleCache* module_cache,
StackSamplerTestDelegate* test_delegate) {
StackSamplerTestDelegate* test_delegate,
std::unique_ptr<Unwinder> native_unwinder) {
DCHECK(!native_unwinder);
return std::make_unique<StackSamplerImpl>(
std::make_unique<StackCopierSuspend>(
std::make_unique<SuspendableThreadDelegateMac>(thread_token)),
......
......@@ -14,7 +14,8 @@ namespace base {
std::unique_ptr<StackSampler> StackSampler::Create(
SamplingProfilerThreadToken thread_token,
ModuleCache* module_cache,
StackSamplerTestDelegate* test_delegate) {
StackSamplerTestDelegate* test_delegate,
std::unique_ptr<Unwinder> native_unwinder) {
return nullptr;
}
......
......@@ -16,7 +16,9 @@ namespace base {
std::unique_ptr<StackSampler> StackSampler::Create(
SamplingProfilerThreadToken thread_token,
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)
return std::make_unique<StackSamplerImpl>(
std::make_unique<StackCopierSuspend>(
......
......@@ -694,27 +694,22 @@ StackSamplingProfiler::StackSamplingProfiler(
const SamplingParams& params,
std::unique_ptr<ProfileBuilder> profile_builder,
StackSamplerTestDelegate* test_delegate)
: StackSamplingProfiler(thread_token,
params,
std::move(profile_builder),
nullptr,
test_delegate) {}
: StackSamplingProfiler(params, std::move(profile_builder), nullptr) {
sampler_ = StackSampler::Create(
thread_token, profile_builder_->GetModuleCache(), test_delegate);
}
StackSamplingProfiler::StackSamplingProfiler(
SamplingProfilerThreadToken thread_token,
const SamplingParams& params,
std::unique_ptr<ProfileBuilder> profile_builder,
std::unique_ptr<StackSampler> sampler,
StackSamplerTestDelegate* test_delegate)
: thread_token_(thread_token),
params_(params),
std::unique_ptr<StackSampler> sampler)
: params_(params),
profile_builder_(std::move(profile_builder)),
sampler_(std::move(sampler)),
// The event starts "signaled" so code knows it's safe to start thread
// and "manual" so that it can be waited in multiple places.
profiling_inactive_(kResetPolicy, WaitableEvent::InitialState::SIGNALED),
profiler_id_(kNullProfilerId),
test_delegate_(test_delegate) {
profiler_id_(kNullProfilerId) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cpu_profiler"),
"StackSamplingProfiler::StackSamplingProfiler");
DCHECK(profile_builder_);
......@@ -751,10 +746,8 @@ void StackSamplingProfiler::Start() {
// already.
DCHECK(profile_builder_);
if (!sampler_)
sampler_ = StackSampler::Create(
thread_token_, profile_builder_->GetModuleCache(), test_delegate_);
// |sampler_| will be null if sampling isn't supported on the current
// platform.
if (!sampler_)
return;
......
......@@ -95,11 +95,9 @@ class BASE_EXPORT StackSamplingProfiler {
// Same as above function, with custom |sampler| implementation. The sampler
// on Android is not implemented in base.
StackSamplingProfiler(SamplingProfilerThreadToken thread_token,
const SamplingParams& params,
StackSamplingProfiler(const SamplingParams& params,
std::unique_ptr<ProfileBuilder> profile_builder,
std::unique_ptr<StackSampler> sampler,
StackSamplerTestDelegate* test_delegate = nullptr);
std::unique_ptr<StackSampler> sampler);
// Stops any profiling currently taking place before destroying the profiler.
// This will block until profile_builder_'s OnProfileCompleted function has
......@@ -202,9 +200,6 @@ class BASE_EXPORT StackSamplingProfiler {
// will be an internal "null" value when no collection has been started.
int profiler_id_;
// Stored until it can be passed to the StackSampler created in Start().
StackSamplerTestDelegate* const test_delegate_;
DISALLOW_COPY_AND_ASSIGN(StackSamplingProfiler);
};
......
......@@ -571,7 +571,7 @@ void TracingSamplerProfiler::StartTracing(
#if BUILDFLAG(CAN_UNWIND_WITH_CFI_TABLE) && defined(OFFICIAL_BUILD)
auto* module_cache = profile_builder->GetModuleCache();
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_,
module_cache));
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