[go: nahoru, domu]

blob: 98d16a5bcf031649fcdbd8f19b87dc01cc7e86f3 [file] [log] [blame]
Charlie Andrews63dbdf62019-07-30 20:55:491// Copyright 2019 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "base/profiler/stack_sampler.h"
6
7#include <pthread.h>
8
9#include "base/profiler/native_unwinder_android.h"
Mike Wittmanfe998b32019-09-06 21:35:2210#include "base/profiler/stack_copier_signal.h"
Charlie Andrews63dbdf62019-07-30 20:55:4911#include "base/profiler/stack_sampler_impl.h"
Mike Wittman18349782019-10-22 17:11:2212#include "base/profiler/thread_delegate_posix.h"
Charlie Andrews63dbdf62019-07-30 20:55:4913#include "base/threading/platform_thread.h"
14
15namespace base {
16
17std::unique_ptr<StackSampler> StackSampler::Create(
18 PlatformThreadId thread_id,
19 ModuleCache* module_cache,
20 StackSamplerTestDelegate* test_delegate) {
21 return std::make_unique<StackSamplerImpl>(
Mike Wittmana31d7d442019-09-09 20:54:4822 std::make_unique<StackCopierSignal>(
Mike Wittman18349782019-10-22 17:11:2223 std::make_unique<ThreadDelegatePosix>(thread_id)),
Charlie Andrews63dbdf62019-07-30 20:55:4924 std::make_unique<NativeUnwinderAndroid>(), module_cache, test_delegate);
25}
26
27size_t StackSampler::GetStackBufferSize() {
28 size_t stack_size = PlatformThread::GetDefaultThreadStackSize();
29
30 pthread_attr_t attr;
31 if (stack_size == 0 && pthread_attr_init(&attr) == 0) {
32 if (pthread_attr_getstacksize(&attr, &stack_size) != 0)
33 stack_size = 0;
34 pthread_attr_destroy(&attr);
35 }
36
37 // 1MB is default thread limit set by Android at art/runtime/thread_pool.h.
38 constexpr size_t kDefaultStackLimit = 1 << 20;
39 return stack_size > 0 ? stack_size : kDefaultStackLimit;
40}
41
42} // namespace base