1 // Copyright 2019 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/profiler/stack_sampler.h"
9 #include "base/check.h"
10 #include "base/memory/ptr_util.h"
11 #include "base/profiler/stack_copier_signal.h"
12 #include "base/profiler/thread_delegate_posix.h"
13 #include "base/profiler/unwinder.h"
14 #include "base/threading/platform_thread.h"
18 std::unique_ptr<StackSampler> StackSampler::Create(
19 SamplingProfilerThreadToken thread_token,
20 ModuleCache* module_cache,
21 UnwindersFactory core_unwinders_factory,
22 RepeatingClosure record_sample_callback,
23 StackSamplerTestDelegate* test_delegate) {
24 auto thread_delegate = ThreadDelegatePosix::Create(thread_token);
27 return base::WrapUnique(new StackSampler(
28 std::make_unique<StackCopierSignal>(std::move(thread_delegate)),
29 std::move(core_unwinders_factory), module_cache,
30 std::move(record_sample_callback), test_delegate));
33 size_t StackSampler::GetStackBufferSize() {
34 size_t stack_size = PlatformThread::GetDefaultThreadStackSize();
37 if (stack_size == 0 && pthread_attr_init(&attr) == 0) {
38 if (pthread_attr_getstacksize(&attr, &stack_size) != 0)
40 pthread_attr_destroy(&attr);
43 // 1MB is default thread limit set by Android at art/runtime/thread_pool.h.
44 constexpr size_t kDefaultStackLimit = 1 << 20;
45 return stack_size > 0 ? stack_size : kDefaultStackLimit;