forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstack_sampler_android.cc
48 lines (39 loc) · 1.59 KB
/
stack_sampler_android.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/profiler/stack_sampler.h"
#include <pthread.h>
#include "base/check.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 {
std::unique_ptr<StackSampler> StackSampler::Create(
SamplingProfilerThreadToken thread_token,
ModuleCache* module_cache,
UnwindersFactory core_unwinders_factory,
RepeatingClosure record_sample_callback,
StackSamplerTestDelegate* test_delegate) {
auto thread_delegate = ThreadDelegatePosix::Create(thread_token);
if (!thread_delegate)
return nullptr;
return std::make_unique<StackSamplerImpl>(
std::make_unique<StackCopierSignal>(std::move(thread_delegate)),
std::move(core_unwinders_factory), module_cache,
std::move(record_sample_callback), test_delegate);
}
size_t StackSampler::GetStackBufferSize() {
size_t stack_size = PlatformThread::GetDefaultThreadStackSize();
pthread_attr_t attr;
if (stack_size == 0 && pthread_attr_init(&attr) == 0) {
if (pthread_attr_getstacksize(&attr, &stack_size) != 0)
stack_size = 0;
pthread_attr_destroy(&attr);
}
// 1MB is default thread limit set by Android at art/runtime/thread_pool.h.
constexpr size_t kDefaultStackLimit = 1 << 20;
return stack_size > 0 ? stack_size : kDefaultStackLimit;
}
} // namespace base