| 6 |
| 7 | #include <pthread.h> |
| 8 |
| 9 | #include "base/profiler/stack_copier_signal.h" |
| 10 | #include "base/profiler/stack_sampler_impl.h" |
| 11 | #include "base/profiler/thread_delegate_posix.h" |
| 12 | #include "base/profiler/unwinder.h" |
| 13 | #include "base/threading/platform_thread.h" |
| 14 |
| 15 | namespace base { |
| 16 |
| 17 | std::unique_ptr<StackSampler> StackSampler::Create( |
| 18 | SamplingProfilerThreadToken thread_token, |
| 19 | ModuleCache* module_cache, |
| 20 | StackSamplerTestDelegate* test_delegate, |
| 21 | std::unique_ptr<Unwinder> native_unwinder) { |
| 22 | return std::make_unique<StackSamplerImpl>( |
| 23 | std::make_unique<StackCopierSignal>( |
| 24 | std::make_unique<ThreadDelegatePosix>(thread_token)), |
| 25 | std::move(native_unwinder), module_cache, test_delegate); |
| 26 | } |
| 27 |
| 28 | size_t StackSampler::GetStackBufferSize() { |
| 29 | size_t stack_size = PlatformThread::GetDefaultThreadStackSize(); |
| 30 |
| 31 | pthread_attr_t attr; |
| 32 | if (stack_size == 0 && pthread_attr_init(&attr) == 0) { |
| 33 | if (pthread_attr_getstacksize(&attr, &stack_size) != 0) |
| 34 | stack_size = 0; |
| 35 | pthread_attr_destroy(&attr); |
| 36 | } |
| 37 |
| 38 | // 1MB is default thread limit set by Android at art/runtime/thread_pool.h. |
| 39 | constexpr size_t kDefaultStackLimit = 1 << 20; |
| 40 | return stack_size > 0 ? stack_size : kDefaultStackLimit; |
| 41 | } |
| 42 |
| 43 | } // namespace base |
| 44 |