Commit 63dbdf68 authored by Charlie Andrews's avatar Charlie Andrews Committed by Commit Bot

Fill in StackSampler static functions for Android

There are existing POSIX implementations for these methods in
stack_sampler_posix.cc. We now use stack_sampler_android.cc on Android
and stack_sampler_posix.cc on all other POSIX platforms.

Note that there's an existing StackSamplerAndroid that exists in the
tracing namespace. However, that implementation is only used for the
"cpu_profiler" tracing category, whereas this implementation will be
used for stack sampled metrics. Once this new Android profiler is
sufficiently complete, it will also be used for tracing.
This stack_sampler_android.cc defers to StackSamplerImpl for its core
logic (also used by the Windows and Mac sampling profiler
implementations), whereas tracing's stack_sampler_android doesn't use
StackSamplerImpl and implements its own core logic.

R=wittman@chromium.org,gab@chromium.org

Bug: 988574
Change-Id: Ia1f20a22ac1421ff02d4beecff4beb6b7a0e065f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1727230Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Reviewed-by: default avatarMike Wittman <wittman@chromium.org>
Commit-Queue: Charlie Andrews <charliea@chromium.org>
Cr-Commit-Position: refs/heads/master@{#682446}
parent a731c68f
...@@ -626,6 +626,7 @@ jumbo_component("base") { ...@@ -626,6 +626,7 @@ jumbo_component("base") {
"profiler/sample_metadata.h", "profiler/sample_metadata.h",
"profiler/stack_sampler.cc", "profiler/stack_sampler.cc",
"profiler/stack_sampler.h", "profiler/stack_sampler.h",
"profiler/stack_sampler_android.cc",
"profiler/stack_sampler_impl.cc", "profiler/stack_sampler_impl.cc",
"profiler/stack_sampler_impl.h", "profiler/stack_sampler_impl.h",
"profiler/stack_sampler_mac.cc", "profiler/stack_sampler_mac.cc",
...@@ -1331,7 +1332,10 @@ jumbo_component("base") { ...@@ -1331,7 +1332,10 @@ jumbo_component("base") {
# Android. # Android.
if (is_android) { if (is_android) {
sources -= [ "debug/stack_trace_posix.cc" ] sources -= [
"debug/stack_trace_posix.cc",
"profiler/stack_sampler_posix.cc",
]
sources += [ sources += [
"android/android_hardware_buffer_compat.cc", "android/android_hardware_buffer_compat.cc",
"android/android_hardware_buffer_compat.h", "android/android_hardware_buffer_compat.h",
......
// 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/profiler/native_unwinder_android.h"
#include "base/profiler/stack_sampler_impl.h"
#include "base/profiler/thread_delegate_android.h"
#include "base/threading/platform_thread.h"
namespace base {
std::unique_ptr<StackSampler> StackSampler::Create(
PlatformThreadId thread_id,
ModuleCache* module_cache,
StackSamplerTestDelegate* test_delegate) {
return std::make_unique<StackSamplerImpl>(
std::make_unique<ThreadDelegateAndroid>(),
std::make_unique<NativeUnwinderAndroid>(), module_cache, 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
...@@ -28,14 +28,8 @@ size_t StackSampler::GetStackBufferSize() { ...@@ -28,14 +28,8 @@ size_t StackSampler::GetStackBufferSize() {
pthread_attr_destroy(&attr); pthread_attr_destroy(&attr);
} }
// If we can't get stack limit from pthreads then use default value.
#if defined(OS_ANDROID)
// 1MB is default thread limit set by Android at art/runtime/thread_pool.h.
constexpr size_t kDefaultStackLimit = 1 << 20;
#else
// Maximum limits under NPTL implementation. // Maximum limits under NPTL implementation.
constexpr size_t kDefaultStackLimit = 4 * (1 << 20); constexpr size_t kDefaultStackLimit = 4 * (1 << 20);
#endif
return stack_size > 0 ? stack_size : kDefaultStackLimit; return stack_size > 0 ? stack_size : kDefaultStackLimit;
} }
......
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