Commit 9606835b authored by Mike Wittman's avatar Mike Wittman Committed by Commit Bot

[Sampling profiler] Reland "Rename NativeStackSampler to StackSampler"

Drops the 'Native' part of the StackSampler name in support of a
future cross-platform sampler implementation that delegates to
platform-specific code at a lower level of abstraction.

This is a reland of f7d1ff11 with
a test compilation fix.

Bug: 909957
Change-Id: I54a9dcaac13a451fe1bea0f37e5e8b4edf1a7bf1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1537747
Auto-Submit: Mike Wittman <wittman@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Reviewed-by: default avataroysteine <oysteine@chromium.org>
Commit-Queue: oysteine <oysteine@chromium.org>
Cr-Commit-Position: refs/heads/master@{#644388}
parent 069842d7
...@@ -612,10 +612,12 @@ jumbo_component("base") { ...@@ -612,10 +612,12 @@ jumbo_component("base") {
#"process/process_metrics_openbsd.cc", # Unused in Chromium build. #"process/process_metrics_openbsd.cc", # Unused in Chromium build.
"process/process_metrics_win.cc", "process/process_metrics_win.cc",
"process/process_win.cc", "process/process_win.cc",
"profiler/native_stack_sampler.cc", "profiler/profile_builder.cc",
"profiler/native_stack_sampler.h", "profiler/profile_builder.h",
"profiler/native_stack_sampler_mac.cc", "profiler/stack_sampler.cc",
"profiler/native_stack_sampler_win.cc", "profiler/stack_sampler.h",
"profiler/stack_sampler_mac.cc",
"profiler/stack_sampler_win.cc",
"profiler/stack_sampling_profiler.cc", "profiler/stack_sampling_profiler.cc",
"profiler/stack_sampling_profiler.h", "profiler/stack_sampling_profiler.h",
"profiler/unwind_result.h", "profiler/unwind_result.h",
...@@ -1115,7 +1117,7 @@ jumbo_component("base") { ...@@ -1115,7 +1117,7 @@ jumbo_component("base") {
"process/process_handle_posix.cc", "process/process_handle_posix.cc",
"process/process_metrics_posix.cc", "process/process_metrics_posix.cc",
"process/process_posix.cc", "process/process_posix.cc",
"profiler/native_stack_sampler_posix.cc", "profiler/stack_sampler_posix.cc",
"rand_util_posix.cc", "rand_util_posix.cc",
"sampling_heap_profiler/module_cache_posix.cc", "sampling_heap_profiler/module_cache_posix.cc",
"strings/string_util_posix.h", "strings/string_util_posix.h",
...@@ -1471,7 +1473,7 @@ jumbo_component("base") { ...@@ -1471,7 +1473,7 @@ jumbo_component("base") {
"process/process_iterator_fuchsia.cc", "process/process_iterator_fuchsia.cc",
"process/process_metrics_fuchsia.cc", "process/process_metrics_fuchsia.cc",
"process/process_metrics_posix.cc", "process/process_metrics_posix.cc",
"profiler/native_stack_sampler_posix.cc", "profiler/stack_sampler_posix.cc",
"rand_util_fuchsia.cc", "rand_util_fuchsia.cc",
"sampling_heap_profiler/module_cache_posix.cc", "sampling_heap_profiler/module_cache_posix.cc",
"strings/string_util_posix.h", "strings/string_util_posix.h",
...@@ -1697,7 +1699,7 @@ jumbo_component("base") { ...@@ -1697,7 +1699,7 @@ jumbo_component("base") {
if (is_mac) { if (is_mac) {
sources -= [ sources -= [
"process/launch_posix.cc", "process/launch_posix.cc",
"profiler/native_stack_sampler_posix.cc", "profiler/stack_sampler_posix.cc",
"sampling_heap_profiler/module_cache_posix.cc", "sampling_heap_profiler/module_cache_posix.cc",
] ]
sources += [ sources += [
......
// 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/profile_builder.h"
namespace base {
ProfileBuilder::Frame::Frame(uintptr_t instruction_pointer,
const ModuleCache::Module* module)
: instruction_pointer(instruction_pointer), module(module) {}
ProfileBuilder::Frame::~Frame() = default;
} // namespace base
// 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.
#ifndef BASE_PROFILER_PROFILE_BUILDER_H_
#define BASE_PROFILER_PROFILE_BUILDER_H_
#include <memory>
#include "base/base_export.h"
#include "base/sampling_heap_profiler/module_cache.h"
#include "base/time/time.h"
namespace base {
// The ProfileBuilder interface allows the user to record profile information on
// the fly in whatever format is desired. Functions are invoked by the profiler
// on its own thread so must not block or perform expensive operations.
class BASE_EXPORT ProfileBuilder {
public:
// Frame represents an individual sampled stack frame with full module
// information.
struct BASE_EXPORT Frame {
Frame(uintptr_t instruction_pointer, const ModuleCache::Module* module);
~Frame();
// The sampled instruction pointer within the function.
uintptr_t instruction_pointer;
// The module information.
const ModuleCache::Module* module;
};
ProfileBuilder() = default;
virtual ~ProfileBuilder() = default;
// Gets the ModuleCache to be used by the StackSamplingProfiler when looking
// up modules from addresses.
virtual ModuleCache* GetModuleCache() = 0;
// Records metadata to be associated with the current sample. To avoid
// deadlock on locks taken by the suspended profiled thread, implementations
// of this method must not execute any code that could take a lock, including
// heap allocation or use of CHECK/DCHECK/LOG statements. Generally
// implementations should simply atomically copy metadata state to be
// associated with the sample.
virtual void RecordMetadata() {}
// Records a new set of frames. Invoked when sampling a sample completes.
virtual void OnSampleCompleted(std::vector<Frame> frames) = 0;
// Finishes the profile construction with |profile_duration| and
// |sampling_period|. Invoked when sampling a profile completes.
virtual void OnProfileCompleted(TimeDelta profile_duration,
TimeDelta sampling_period) = 0;
private:
DISALLOW_COPY_AND_ASSIGN(ProfileBuilder);
};
} // namespace base
#endif // BASE_PROFILER_PROFILE_BUILDER_H_
...@@ -2,33 +2,32 @@ ...@@ -2,33 +2,32 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "base/profiler/native_stack_sampler.h" #include "base/profiler/stack_sampler.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
namespace base { namespace base {
NativeStackSampler::StackBuffer::StackBuffer(size_t buffer_size) StackSampler::StackBuffer::StackBuffer(size_t buffer_size)
: buffer_(new uintptr_t[(buffer_size + sizeof(uintptr_t) - 1) / : buffer_(new uintptr_t[(buffer_size + sizeof(uintptr_t) - 1) /
sizeof(uintptr_t)]), sizeof(uintptr_t)]),
size_(buffer_size) {} size_(buffer_size) {}
NativeStackSampler::StackBuffer::~StackBuffer() = default; StackSampler::StackBuffer::~StackBuffer() = default;
NativeStackSampler::NativeStackSampler() = default; StackSampler::StackSampler() = default;
NativeStackSampler::~NativeStackSampler() = default; StackSampler::~StackSampler() = default;
std::unique_ptr<NativeStackSampler::StackBuffer> std::unique_ptr<StackSampler::StackBuffer> StackSampler::CreateStackBuffer() {
NativeStackSampler::CreateStackBuffer() {
size_t size = GetStackBufferSize(); size_t size = GetStackBufferSize();
if (size == 0) if (size == 0)
return nullptr; return nullptr;
return std::make_unique<StackBuffer>(size); return std::make_unique<StackBuffer>(size);
} }
NativeStackSamplerTestDelegate::~NativeStackSamplerTestDelegate() = default; StackSamplerTestDelegate::~StackSamplerTestDelegate() = default;
NativeStackSamplerTestDelegate::NativeStackSamplerTestDelegate() = default; StackSamplerTestDelegate::StackSamplerTestDelegate() = default;
} // namespace base } // namespace base
...@@ -2,28 +2,28 @@ ...@@ -2,28 +2,28 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef BASE_PROFILER_NATIVE_STACK_SAMPLER_H_ #ifndef BASE_PROFILER_STACK_SAMPLER_H_
#define BASE_PROFILER_NATIVE_STACK_SAMPLER_H_ #define BASE_PROFILER_STACK_SAMPLER_H_
#include <memory> #include <memory>
#include "base/base_export.h" #include "base/base_export.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/profiler/stack_sampling_profiler.h"
#include "base/threading/platform_thread.h" #include "base/threading/platform_thread.h"
namespace base { namespace base {
class ModuleCache; class ModuleCache;
class NativeStackSamplerTestDelegate; class ProfileBuilder;
class StackSamplerTestDelegate;
// NativeStackSampler is an implementation detail of StackSamplingProfiler. It // StackSampler is an implementation detail of StackSamplingProfiler. It
// abstracts the native implementation required to record a set of stack frames // abstracts the native implementation required to record a set of stack frames
// for a given thread. // for a given thread.
class NativeStackSampler { class StackSampler {
public: public:
// This class contains a buffer for stack copies that can be shared across // This class contains a buffer for stack copies that can be shared across
// multiple instances of NativeStackSampler. // multiple instances of StackSampler.
class StackBuffer { class StackBuffer {
public: public:
StackBuffer(size_t buffer_size); StackBuffer(size_t buffer_size);
...@@ -42,54 +42,53 @@ class NativeStackSampler { ...@@ -42,54 +42,53 @@ class NativeStackSampler {
DISALLOW_COPY_AND_ASSIGN(StackBuffer); DISALLOW_COPY_AND_ASSIGN(StackBuffer);
}; };
virtual ~NativeStackSampler(); virtual ~StackSampler();
// Creates a stack sampler that records samples for thread with |thread_id|. // Creates a stack sampler that records samples for thread with |thread_id|.
// Returns null if this platform does not support stack sampling. // Returns null if this platform does not support stack sampling.
static std::unique_ptr<NativeStackSampler> Create( static std::unique_ptr<StackSampler> Create(
PlatformThreadId thread_id, PlatformThreadId thread_id,
ModuleCache* module_cache, ModuleCache* module_cache,
NativeStackSamplerTestDelegate* test_delegate); StackSamplerTestDelegate* test_delegate);
// Gets the required size of the stack buffer. // Gets the required size of the stack buffer.
static size_t GetStackBufferSize(); static size_t GetStackBufferSize();
// Creates an instance of the a stack buffer that can be used for calls to // Creates an instance of the a stack buffer that can be used for calls to
// any NativeStackSampler object. // any StackSampler object.
static std::unique_ptr<StackBuffer> CreateStackBuffer(); static std::unique_ptr<StackBuffer> CreateStackBuffer();
// The following functions are all called on the SamplingThread (not the // The following functions are all called on the SamplingThread (not the
// thread being sampled). // thread being sampled).
// Records a set of frames and returns them. // Records a set of frames and returns them.
virtual void RecordStackFrames( virtual void RecordStackFrames(StackBuffer* stackbuffer,
StackBuffer* stackbuffer, ProfileBuilder* profile_builder) = 0;
StackSamplingProfiler::ProfileBuilder* profile_builder) = 0;
protected: protected:
NativeStackSampler(); StackSampler();
private: private:
DISALLOW_COPY_AND_ASSIGN(NativeStackSampler); DISALLOW_COPY_AND_ASSIGN(StackSampler);
}; };
// NativeStackSamplerTestDelegate provides seams for test code to execute during // StackSamplerTestDelegate provides seams for test code to execute during stack
// stack collection. // collection.
class BASE_EXPORT NativeStackSamplerTestDelegate { class BASE_EXPORT StackSamplerTestDelegate {
public: public:
virtual ~NativeStackSamplerTestDelegate(); virtual ~StackSamplerTestDelegate();
// Called after copying the stack and resuming the target thread, but prior to // Called after copying the stack and resuming the target thread, but prior to
// walking the stack. Invoked on the SamplingThread. // walking the stack. Invoked on the SamplingThread.
virtual void OnPreStackWalk() = 0; virtual void OnPreStackWalk() = 0;
protected: protected:
NativeStackSamplerTestDelegate(); StackSamplerTestDelegate();
private: private:
DISALLOW_COPY_AND_ASSIGN(NativeStackSamplerTestDelegate); DISALLOW_COPY_AND_ASSIGN(StackSamplerTestDelegate);
}; };
} // namespace base } // namespace base
#endif // BASE_PROFILER_NATIVE_STACK_SAMPLER_H_ #endif // BASE_PROFILER_STACK_SAMPLER_H_
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "base/profiler/native_stack_sampler.h" #include "base/profiler/stack_sampler.h"
#include <libkern/OSByteOrder.h> #include <libkern/OSByteOrder.h>
#include <libunwind.h> #include <libunwind.h>
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "base/mac/mach_logging.h" #include "base/mac/mach_logging.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/profiler/profile_builder.h"
#include "base/sampling_heap_profiler/module_cache.h" #include "base/sampling_heap_profiler/module_cache.h"
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
...@@ -34,9 +35,6 @@ void _sigtramp(int, int, struct sigset*); ...@@ -34,9 +35,6 @@ void _sigtramp(int, int, struct sigset*);
namespace base { namespace base {
using Frame = StackSamplingProfiler::Frame;
using ProfileBuilder = StackSamplingProfiler::ProfileBuilder;
namespace { namespace {
// Stack walking -------------------------------------------------------------- // Stack walking --------------------------------------------------------------
...@@ -242,16 +240,16 @@ class ScopedSuspendThread { ...@@ -242,16 +240,16 @@ class ScopedSuspendThread {
} // namespace } // namespace
// NativeStackSamplerMac ------------------------------------------------------ // StackSamplerMac ------------------------------------------------------
class NativeStackSamplerMac : public NativeStackSampler { class StackSamplerMac : public StackSampler {
public: public:
NativeStackSamplerMac(mach_port_t thread_port, StackSamplerMac(mach_port_t thread_port,
ModuleCache* module_cache, ModuleCache* module_cache,
NativeStackSamplerTestDelegate* test_delegate); StackSamplerTestDelegate* test_delegate);
~NativeStackSamplerMac() override; ~StackSamplerMac() override;
// StackSamplingProfiler::NativeStackSampler: // StackSamplingProfiler::StackSampler:
void RecordStackFrames(StackBuffer* stack_buffer, void RecordStackFrames(StackBuffer* stack_buffer,
ProfileBuilder* profile_builder) override; ProfileBuilder* profile_builder) override;
...@@ -268,8 +266,9 @@ class NativeStackSamplerMac : public NativeStackSampler { ...@@ -268,8 +266,9 @@ class NativeStackSamplerMac : public NativeStackSampler {
// Walks the stack represented by |thread_state|, calling back to the // Walks the stack represented by |thread_state|, calling back to the
// provided lambda for each frame. // provided lambda for each frame.
std::vector<Frame> WalkStack(const x86_thread_state64_t& thread_state, std::vector<ProfileBuilder::Frame> WalkStack(
uintptr_t stack_top); const x86_thread_state64_t& thread_state,
uintptr_t stack_top);
// Weak reference: Mach port for thread being profiled. // Weak reference: Mach port for thread being profiled.
mach_port_t thread_port_; mach_port_t thread_port_;
...@@ -277,7 +276,7 @@ class NativeStackSamplerMac : public NativeStackSampler { ...@@ -277,7 +276,7 @@ class NativeStackSamplerMac : public NativeStackSampler {
// Maps a module's address range to the module. // Maps a module's address range to the module.
ModuleCache* const module_cache_; ModuleCache* const module_cache_;
NativeStackSamplerTestDelegate* const test_delegate_; StackSamplerTestDelegate* const test_delegate_;
// The stack base address corresponding to |thread_handle_|. // The stack base address corresponding to |thread_handle_|.
const void* const thread_stack_base_address_; const void* const thread_stack_base_address_;
...@@ -289,13 +288,12 @@ class NativeStackSamplerMac : public NativeStackSampler { ...@@ -289,13 +288,12 @@ class NativeStackSamplerMac : public NativeStackSampler {
uintptr_t sigtramp_start_; uintptr_t sigtramp_start_;
uintptr_t sigtramp_end_; uintptr_t sigtramp_end_;
DISALLOW_COPY_AND_ASSIGN(NativeStackSamplerMac); DISALLOW_COPY_AND_ASSIGN(StackSamplerMac);
}; };
NativeStackSamplerMac::NativeStackSamplerMac( StackSamplerMac::StackSamplerMac(mach_port_t thread_port,
mach_port_t thread_port, ModuleCache* module_cache,
ModuleCache* module_cache, StackSamplerTestDelegate* test_delegate)
NativeStackSamplerTestDelegate* test_delegate)
: thread_port_(thread_port), : thread_port_(thread_port),
module_cache_(module_cache), module_cache_(module_cache),
test_delegate_(test_delegate), test_delegate_(test_delegate),
...@@ -311,10 +309,10 @@ NativeStackSamplerMac::NativeStackSamplerMac( ...@@ -311,10 +309,10 @@ NativeStackSamplerMac::NativeStackSamplerMac(
GetThreadState(thread_port_, &thread_state); GetThreadState(thread_port_, &thread_state);
} }
NativeStackSamplerMac::~NativeStackSamplerMac() {} StackSamplerMac::~StackSamplerMac() {}
void NativeStackSamplerMac::RecordStackFrames(StackBuffer* stack_buffer, void StackSamplerMac::RecordStackFrames(StackBuffer* stack_buffer,
ProfileBuilder* profile_builder) { ProfileBuilder* profile_builder) {
x86_thread_state64_t thread_state; x86_thread_state64_t thread_state;
uintptr_t stack_top; uintptr_t stack_top;
...@@ -332,12 +330,12 @@ void NativeStackSamplerMac::RecordStackFrames(StackBuffer* stack_buffer, ...@@ -332,12 +330,12 @@ void NativeStackSamplerMac::RecordStackFrames(StackBuffer* stack_buffer,
} }
// static // static
bool NativeStackSamplerMac::CopyStack(mach_port_t thread_port, bool StackSamplerMac::CopyStack(mach_port_t thread_port,
const void* base_address, const void* base_address,
StackBuffer* stack_buffer, StackBuffer* stack_buffer,
ProfileBuilder* profile_builder, ProfileBuilder* profile_builder,
x86_thread_state64_t* thread_state, x86_thread_state64_t* thread_state,
uintptr_t* stack_top) { uintptr_t* stack_top) {
// IMPORTANT NOTE: Do not do ANYTHING in this in this scope that might // IMPORTANT NOTE: Do not do ANYTHING in this in this scope that might
// allocate memory, including indirectly via use of DCHECK/CHECK or other // allocate memory, including indirectly via use of DCHECK/CHECK or other
// logging statements. Otherwise this code can deadlock on heap locks acquired // logging statements. Otherwise this code can deadlock on heap locks acquired
...@@ -370,10 +368,10 @@ bool NativeStackSamplerMac::CopyStack(mach_port_t thread_port, ...@@ -370,10 +368,10 @@ bool NativeStackSamplerMac::CopyStack(mach_port_t thread_port,
return true; return true;
} }
std::vector<Frame> NativeStackSamplerMac::WalkStack( std::vector<ProfileBuilder::Frame> StackSamplerMac::WalkStack(
const x86_thread_state64_t& thread_state, const x86_thread_state64_t& thread_state,
uintptr_t stack_top) { uintptr_t stack_top) {
std::vector<Frame> stack; std::vector<ProfileBuilder::Frame> stack;
// Reserve enough memory for most stacks, to avoid repeated // Reserve enough memory for most stacks, to avoid repeated
// allocations. Approximately 99.9% of recorded stacks are 128 frames or // allocations. Approximately 99.9% of recorded stacks are 128 frames or
...@@ -396,7 +394,7 @@ std::vector<Frame> NativeStackSamplerMac::WalkStack( ...@@ -396,7 +394,7 @@ std::vector<Frame> NativeStackSamplerMac::WalkStack(
const ModuleCache::Module* leaf_frame_module = const ModuleCache::Module* leaf_frame_module =
module_cache_->GetModuleForAddress(thread_state.__rip); module_cache_->GetModuleForAddress(thread_state.__rip);
if (leaf_frame_module && MayTriggerUnwInitLocalCrash(leaf_frame_module)) { if (leaf_frame_module && MayTriggerUnwInitLocalCrash(leaf_frame_module)) {
return {Frame(thread_state.__rip, leaf_frame_module)}; return {ProfileBuilder::Frame(thread_state.__rip, leaf_frame_module)};
} }
unw_cursor_t unwind_cursor; unw_cursor_t unwind_cursor;
...@@ -470,19 +468,19 @@ std::vector<Frame> NativeStackSamplerMac::WalkStack( ...@@ -470,19 +468,19 @@ std::vector<Frame> NativeStackSamplerMac::WalkStack(
return stack; return stack;
} }
// NativeStackSampler --------------------------------------------------------- // StackSampler ---------------------------------------------------------
// static // static
std::unique_ptr<NativeStackSampler> NativeStackSampler::Create( std::unique_ptr<StackSampler> StackSampler::Create(
PlatformThreadId thread_id, PlatformThreadId thread_id,
ModuleCache* module_cache, ModuleCache* module_cache,
NativeStackSamplerTestDelegate* test_delegate) { StackSamplerTestDelegate* test_delegate) {
return std::make_unique<NativeStackSamplerMac>(thread_id, module_cache, return std::make_unique<StackSamplerMac>(thread_id, module_cache,
test_delegate); test_delegate);
} }
// static // static
size_t NativeStackSampler::GetStackBufferSize() { size_t StackSampler::GetStackBufferSize() {
size_t stack_size = PlatformThread::GetDefaultThreadStackSize(); size_t stack_size = PlatformThread::GetDefaultThreadStackSize();
// If getrlimit somehow fails, return the default macOS main thread stack size // If getrlimit somehow fails, return the default macOS main thread stack size
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "base/profiler/native_stack_sampler.h" #include "base/profiler/stack_sampler.h"
#include <pthread.h> #include <pthread.h>
...@@ -11,14 +11,14 @@ ...@@ -11,14 +11,14 @@
namespace base { namespace base {
std::unique_ptr<NativeStackSampler> NativeStackSampler::Create( std::unique_ptr<StackSampler> StackSampler::Create(
PlatformThreadId thread_id, PlatformThreadId thread_id,
ModuleCache* module_cache, ModuleCache* module_cache,
NativeStackSamplerTestDelegate* test_delegate) { StackSamplerTestDelegate* test_delegate) {
return std::unique_ptr<NativeStackSampler>(); return nullptr;
} }
size_t NativeStackSampler::GetStackBufferSize() { size_t StackSampler::GetStackBufferSize() {
size_t stack_size = PlatformThread::GetDefaultThreadStackSize(); size_t stack_size = PlatformThread::GetDefaultThreadStackSize();
pthread_attr_t attr; pthread_attr_t attr;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "base/profiler/native_stack_sampler.h" #include "base/profiler/stack_sampler.h"
#include <windows.h> #include <windows.h>
...@@ -19,19 +19,18 @@ ...@@ -19,19 +19,18 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/profiler/profile_builder.h"
#include "base/profiler/unwind_result.h" #include "base/profiler/unwind_result.h"
#include "base/profiler/win32_stack_frame_unwinder.h" #include "base/profiler/win32_stack_frame_unwinder.h"
#include "base/sampling_heap_profiler/module_cache.h" #include "base/sampling_heap_profiler/module_cache.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event.h"
#include "base/win/scoped_handle.h"
#include "build/build_config.h" #include "build/build_config.h"
namespace base { namespace base {
using Frame = StackSamplingProfiler::Frame;
using ProfileBuilder = StackSamplingProfiler::ProfileBuilder;
// Stack recording functions -------------------------------------------------- // Stack recording functions --------------------------------------------------
namespace { namespace {
...@@ -140,12 +139,28 @@ void CopyStackContentsAndRewritePointers(const uintptr_t* original_stack_bottom, ...@@ -140,12 +139,28 @@ void CopyStackContentsAndRewritePointers(const uintptr_t* original_stack_bottom,
#if defined(ARCH_CPU_64_BITS) #if defined(ARCH_CPU_64_BITS)
DWORD64 CONTEXT::*const nonvolatile_registers[] = { DWORD64 CONTEXT::*const nonvolatile_registers[] = {
#if defined(ARCH_CPU_X86_64) #if defined(ARCH_CPU_X86_64)
&CONTEXT::R12, &CONTEXT::R13, &CONTEXT::R14, &CONTEXT::R15, &CONTEXT::Rdi, &CONTEXT::R12,
&CONTEXT::Rsi, &CONTEXT::Rbx, &CONTEXT::Rbp, &CONTEXT::Rsp &CONTEXT::R13,
&CONTEXT::R14,
&CONTEXT::R15,
&CONTEXT::Rdi,
&CONTEXT::Rsi,
&CONTEXT::Rbx,
&CONTEXT::Rbp,
&CONTEXT::Rsp
#elif defined(ARCH_CPU_ARM64) #elif defined(ARCH_CPU_ARM64)
&CONTEXT::X19, &CONTEXT::X20, &CONTEXT::X21, &CONTEXT::X22, &CONTEXT::X23, &CONTEXT::X19,
&CONTEXT::X24, &CONTEXT::X25, &CONTEXT::X26, &CONTEXT::X27, &CONTEXT::X28, &CONTEXT::X20,
&CONTEXT::Fp, &CONTEXT::Lr &CONTEXT::X21,
&CONTEXT::X22,
&CONTEXT::X23,
&CONTEXT::X24,
&CONTEXT::X25,
&CONTEXT::X26,
&CONTEXT::X27,
&CONTEXT::X28,
&CONTEXT::Fp,
&CONTEXT::Lr
#else #else
#error Unsupported Windows 64-bit Arch #error Unsupported Windows 64-bit Arch
#endif #endif
...@@ -250,16 +265,16 @@ bool PointsToGuardPage(uintptr_t stack_pointer) { ...@@ -250,16 +265,16 @@ bool PointsToGuardPage(uintptr_t stack_pointer) {
} // namespace } // namespace
// NativeStackSamplerWin ------------------------------------------------------ // StackSamplerWin ------------------------------------------------------
class NativeStackSamplerWin : public NativeStackSampler { class StackSamplerWin : public StackSampler {
public: public:
NativeStackSamplerWin(win::ScopedHandle thread_handle, StackSamplerWin(win::ScopedHandle thread_handle,
ModuleCache* module_cache, ModuleCache* module_cache,
NativeStackSamplerTestDelegate* test_delegate); StackSamplerTestDelegate* test_delegate);
~NativeStackSamplerWin() override; ~StackSamplerWin() override;
// StackSamplingProfiler::NativeStackSampler: // StackSamplingProfiler::StackSampler:
void RecordStackFrames(StackBuffer* stack_buffer, void RecordStackFrames(StackBuffer* stack_buffer,
ProfileBuilder* profile_builder) override; ProfileBuilder* profile_builder) override;
...@@ -277,42 +292,41 @@ class NativeStackSamplerWin : public NativeStackSampler { ...@@ -277,42 +292,41 @@ class NativeStackSamplerWin : public NativeStackSampler {
// Walks the stack represented by |thread_context|, recording and returning // Walks the stack represented by |thread_context|, recording and returning
// the frames. // the frames.
std::vector<Frame> WalkStack(CONTEXT* thread_context); std::vector<ProfileBuilder::Frame> WalkStack(CONTEXT* thread_context);
// Attempts to walk native frames in the stack represented by // Attempts to walk native frames in the stack represented by
// |thread_context|, appending frames to |stack|. Returns a result indicating // |thread_context|, appending frames to |stack|. Returns a result indicating
// the disposition of the unwinding. // the disposition of the unwinding.
UnwindResult WalkNativeFrames(CONTEXT* thread_context, UnwindResult WalkNativeFrames(CONTEXT* thread_context,
std::vector<Frame>* stack); std::vector<ProfileBuilder::Frame>* stack);
win::ScopedHandle thread_handle_; win::ScopedHandle thread_handle_;
ModuleCache* module_cache_; ModuleCache* module_cache_;
NativeStackSamplerTestDelegate* const test_delegate_; StackSamplerTestDelegate* const test_delegate_;
// The stack base address corresponding to |thread_handle_|. // The stack base address corresponding to |thread_handle_|.
const void* const thread_stack_base_address_; const void* const thread_stack_base_address_;
DISALLOW_COPY_AND_ASSIGN(NativeStackSamplerWin); DISALLOW_COPY_AND_ASSIGN(StackSamplerWin);
}; };
NativeStackSamplerWin::NativeStackSamplerWin( StackSamplerWin::StackSamplerWin(win::ScopedHandle thread_handle,
win::ScopedHandle thread_handle, ModuleCache* module_cache,
ModuleCache* module_cache, StackSamplerTestDelegate* test_delegate)
NativeStackSamplerTestDelegate* test_delegate)
: thread_handle_(thread_handle.Take()), : thread_handle_(thread_handle.Take()),
module_cache_(module_cache), module_cache_(module_cache),
test_delegate_(test_delegate), test_delegate_(test_delegate),
thread_stack_base_address_( thread_stack_base_address_(
GetThreadEnvironmentBlock(thread_handle_.Get())->Tib.StackBase) {} GetThreadEnvironmentBlock(thread_handle_.Get())->Tib.StackBase) {}
NativeStackSamplerWin::~NativeStackSamplerWin() {} StackSamplerWin::~StackSamplerWin() {}
void NativeStackSamplerWin::RecordStackFrames(StackBuffer* stack_buffer, void StackSamplerWin::RecordStackFrames(StackBuffer* stack_buffer,
ProfileBuilder* profile_builder) { ProfileBuilder* profile_builder) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cpu_profiler.debug"), TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cpu_profiler.debug"),
"NativeStackSamplerWin::RecordStackFrames"); "StackSamplerWin::RecordStackFrames");
DCHECK(stack_buffer); DCHECK(stack_buffer);
CONTEXT thread_context; CONTEXT thread_context;
...@@ -336,11 +350,11 @@ void NativeStackSamplerWin::RecordStackFrames(StackBuffer* stack_buffer, ...@@ -336,11 +350,11 @@ void NativeStackSamplerWin::RecordStackFrames(StackBuffer* stack_buffer,
// the default heap acquired by the target thread before it was suspended. // the default heap acquired by the target thread before it was suspended.
// //
// static // static
bool NativeStackSamplerWin::CopyStack(HANDLE thread_handle, bool StackSamplerWin::CopyStack(HANDLE thread_handle,
const void* base_address, const void* base_address,
StackBuffer* stack_buffer, StackBuffer* stack_buffer,
ProfileBuilder* profile_builder, ProfileBuilder* profile_builder,
CONTEXT* thread_context) { CONTEXT* thread_context) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cpu_profiler.debug"), TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cpu_profiler.debug"),
"SuspendThread"); "SuspendThread");
...@@ -385,9 +399,10 @@ bool NativeStackSamplerWin::CopyStack(HANDLE thread_handle, ...@@ -385,9 +399,10 @@ bool NativeStackSamplerWin::CopyStack(HANDLE thread_handle,
return true; return true;
} }
std::vector<Frame> NativeStackSamplerWin::WalkStack(CONTEXT* thread_context) { std::vector<ProfileBuilder::Frame> StackSamplerWin::WalkStack(
CONTEXT* thread_context) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cpu_profiler.debug"), "WalkStack"); TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cpu_profiler.debug"), "WalkStack");
std::vector<Frame> stack; std::vector<ProfileBuilder::Frame> stack;
// Reserve enough memory for most stacks, to avoid repeated // Reserve enough memory for most stacks, to avoid repeated
// allocations. Approximately 99.9% of recorded stacks are 128 frames or // allocations. Approximately 99.9% of recorded stacks are 128 frames or
// fewer. // fewer.
...@@ -398,9 +413,9 @@ std::vector<Frame> NativeStackSamplerWin::WalkStack(CONTEXT* thread_context) { ...@@ -398,9 +413,9 @@ std::vector<Frame> NativeStackSamplerWin::WalkStack(CONTEXT* thread_context) {
return stack; return stack;
} }
UnwindResult NativeStackSamplerWin::WalkNativeFrames( UnwindResult StackSamplerWin::WalkNativeFrames(
CONTEXT* thread_context, CONTEXT* thread_context,
std::vector<Frame>* stack) { std::vector<ProfileBuilder::Frame>* stack) {
Win32StackFrameUnwinder frame_unwinder; Win32StackFrameUnwinder frame_unwinder;
while (ContextPC(thread_context)) { while (ContextPC(thread_context)) {
const ModuleCache::Module* const module = const ModuleCache::Module* const module =
...@@ -437,13 +452,13 @@ UnwindResult NativeStackSamplerWin::WalkNativeFrames( ...@@ -437,13 +452,13 @@ UnwindResult NativeStackSamplerWin::WalkNativeFrames(
return UnwindResult::COMPLETED; return UnwindResult::COMPLETED;
} }
// NativeStackSampler --------------------------------------------------------- // StackSampler ---------------------------------------------------------
// static // static
std::unique_ptr<NativeStackSampler> NativeStackSampler::Create( std::unique_ptr<StackSampler> StackSampler::Create(
PlatformThreadId thread_id, PlatformThreadId thread_id,
ModuleCache* module_cache, ModuleCache* module_cache,
NativeStackSamplerTestDelegate* test_delegate) { StackSamplerTestDelegate* test_delegate) {
#if _WIN64 #if _WIN64
// Get the thread's handle. // Get the thread's handle.
HANDLE thread_handle = ::OpenThread( HANDLE thread_handle = ::OpenThread(
...@@ -451,15 +466,15 @@ std::unique_ptr<NativeStackSampler> NativeStackSampler::Create( ...@@ -451,15 +466,15 @@ std::unique_ptr<NativeStackSampler> NativeStackSampler::Create(
FALSE, thread_id); FALSE, thread_id);
if (thread_handle) { if (thread_handle) {
return std::unique_ptr<NativeStackSampler>(new NativeStackSamplerWin( return std::make_unique<StackSamplerWin>(win::ScopedHandle(thread_handle),
win::ScopedHandle(thread_handle), module_cache, test_delegate)); module_cache, test_delegate);
} }
#endif #endif
return std::unique_ptr<NativeStackSampler>(); return nullptr;
} }
// static // static
size_t NativeStackSampler::GetStackBufferSize() { size_t StackSampler::GetStackBufferSize() {
// The default Win32 reserved stack size is 1 MB and Chrome Windows threads // The default Win32 reserved stack size is 1 MB and Chrome Windows threads
// currently always use the default, but this allows for expansion if it // currently always use the default, but this allows for expansion if it
// occurs. The size beyond the actual stack size consists of unallocated // occurs. The size beyond the actual stack size consists of unallocated
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/memory/singleton.h" #include "base/memory/singleton.h"
#include "base/profiler/native_stack_sampler.h" #include "base/profiler/stack_sampler.h"
#include "base/synchronization/lock.h" #include "base/synchronization/lock.h"
#include "base/thread_annotations.h" #include "base/thread_annotations.h"
#include "base/threading/thread.h" #include "base/threading/thread.h"
...@@ -47,14 +47,6 @@ const int kNullProfilerId = -1; ...@@ -47,14 +47,6 @@ const int kNullProfilerId = -1;
} // namespace } // namespace
// StackSamplingProfiler::Frame -------------------------------------
StackSamplingProfiler::Frame::Frame(uintptr_t instruction_pointer,
const ModuleCache::Module* module)
: instruction_pointer(instruction_pointer), module(module) {}
StackSamplingProfiler::Frame::~Frame() = default;
// StackSamplingProfiler::SamplingThread -------------------------------------- // StackSamplingProfiler::SamplingThread --------------------------------------
class StackSamplingProfiler::SamplingThread : public Thread { class StackSamplingProfiler::SamplingThread : public Thread {
...@@ -88,7 +80,7 @@ class StackSamplingProfiler::SamplingThread : public Thread { ...@@ -88,7 +80,7 @@ class StackSamplingProfiler::SamplingThread : public Thread {
CollectionContext(PlatformThreadId target, CollectionContext(PlatformThreadId target,
const SamplingParams& params, const SamplingParams& params,
WaitableEvent* finished, WaitableEvent* finished,
std::unique_ptr<NativeStackSampler> sampler, std::unique_ptr<StackSampler> sampler,
std::unique_ptr<ProfileBuilder> profile_builder) std::unique_ptr<ProfileBuilder> profile_builder)
: collection_id(next_collection_id.GetNext()), : collection_id(next_collection_id.GetNext()),
target(target), target(target),
...@@ -107,7 +99,7 @@ class StackSamplingProfiler::SamplingThread : public Thread { ...@@ -107,7 +99,7 @@ class StackSamplingProfiler::SamplingThread : public Thread {
WaitableEvent* const finished; // Signaled when all sampling complete. WaitableEvent* const finished; // Signaled when all sampling complete.
// Platform-specific module that does the actual sampling. // Platform-specific module that does the actual sampling.
std::unique_ptr<NativeStackSampler> native_sampler; std::unique_ptr<StackSampler> native_sampler;
// Receives the sampling data and builds a CallStackProfile. // Receives the sampling data and builds a CallStackProfile.
std::unique_ptr<ProfileBuilder> profile_builder; std::unique_ptr<ProfileBuilder> profile_builder;
...@@ -192,7 +184,7 @@ class StackSamplingProfiler::SamplingThread : public Thread { ...@@ -192,7 +184,7 @@ class StackSamplingProfiler::SamplingThread : public Thread {
// A stack-buffer used by the native sampler for its work. This buffer can // A stack-buffer used by the native sampler for its work. This buffer can
// be re-used for multiple native sampler objects so long as the API calls // be re-used for multiple native sampler objects so long as the API calls
// that take it are not called concurrently. // that take it are not called concurrently.
std::unique_ptr<NativeStackSampler::StackBuffer> stack_buffer_; std::unique_ptr<StackSampler::StackBuffer> stack_buffer_;
// A map of collection ids to collection contexts. Because this class is a // A map of collection ids to collection contexts. Because this class is a
// singleton that is never destroyed, context objects will never be destructed // singleton that is never destroyed, context objects will never be destructed
...@@ -380,7 +372,7 @@ StackSamplingProfiler::SamplingThread::GetOrCreateTaskRunnerForAdd() { ...@@ -380,7 +372,7 @@ StackSamplingProfiler::SamplingThread::GetOrCreateTaskRunnerForAdd() {
} }
DCHECK(!stack_buffer_); DCHECK(!stack_buffer_);
stack_buffer_ = NativeStackSampler::CreateStackBuffer(); stack_buffer_ = StackSampler::CreateStackBuffer();
// The thread is not running. Start it and get associated runner. The task- // The thread is not running. Start it and get associated runner. The task-
// runner has to be saved for future use because though it can be used from // runner has to be saved for future use because though it can be used from
...@@ -623,13 +615,11 @@ void StackSamplingProfiler::TestPeer::PerformSamplingThreadIdleShutdown( ...@@ -623,13 +615,11 @@ void StackSamplingProfiler::TestPeer::PerformSamplingThreadIdleShutdown(
SamplingThread::TestPeer::ShutdownAssumingIdle(simulate_intervening_start); SamplingThread::TestPeer::ShutdownAssumingIdle(simulate_intervening_start);
} }
void StackSamplingProfiler::ProfileBuilder::RecordMetadata() {}
StackSamplingProfiler::StackSamplingProfiler( StackSamplingProfiler::StackSamplingProfiler(
PlatformThreadId thread_id, PlatformThreadId thread_id,
const SamplingParams& params, const SamplingParams& params,
std::unique_ptr<ProfileBuilder> profile_builder, std::unique_ptr<ProfileBuilder> profile_builder,
NativeStackSamplerTestDelegate* test_delegate) StackSamplerTestDelegate* test_delegate)
: StackSamplingProfiler(thread_id, : StackSamplingProfiler(thread_id,
params, params,
std::move(profile_builder), std::move(profile_builder),
...@@ -640,12 +630,12 @@ StackSamplingProfiler::StackSamplingProfiler( ...@@ -640,12 +630,12 @@ StackSamplingProfiler::StackSamplingProfiler(
PlatformThreadId thread_id, PlatformThreadId thread_id,
const SamplingParams& params, const SamplingParams& params,
std::unique_ptr<ProfileBuilder> profile_builder, std::unique_ptr<ProfileBuilder> profile_builder,
std::unique_ptr<NativeStackSampler> sampler, std::unique_ptr<StackSampler> sampler,
NativeStackSamplerTestDelegate* test_delegate) StackSamplerTestDelegate* test_delegate)
: thread_id_(thread_id), : thread_id_(thread_id),
params_(params), params_(params),
profile_builder_(std::move(profile_builder)), profile_builder_(std::move(profile_builder)),
native_sampler_(std::move(sampler)), sampler_(std::move(sampler)),
// The event starts "signaled" so code knows it's safe to start thread // The event starts "signaled" so code knows it's safe to start thread
// and "manual" so that it can be waited in multiple places. // and "manual" so that it can be waited in multiple places.
profiling_inactive_(kResetPolicy, WaitableEvent::InitialState::SIGNALED), profiling_inactive_(kResetPolicy, WaitableEvent::InitialState::SIGNALED),
...@@ -687,11 +677,11 @@ void StackSamplingProfiler::Start() { ...@@ -687,11 +677,11 @@ void StackSamplingProfiler::Start() {
// already. // already.
DCHECK(profile_builder_); DCHECK(profile_builder_);
if (!native_sampler_) if (!sampler_)
native_sampler_ = NativeStackSampler::Create( sampler_ = StackSampler::Create(
thread_id_, profile_builder_->GetModuleCache(), test_delegate_); thread_id_, profile_builder_->GetModuleCache(), test_delegate_);
if (!native_sampler_) if (!sampler_)
return; return;
// The IsSignaled() check below requires that the WaitableEvent be manually // The IsSignaled() check below requires that the WaitableEvent be manually
...@@ -709,7 +699,7 @@ void StackSamplingProfiler::Start() { ...@@ -709,7 +699,7 @@ void StackSamplingProfiler::Start() {
DCHECK_EQ(kNullProfilerId, profiler_id_); DCHECK_EQ(kNullProfilerId, profiler_id_);
profiler_id_ = SamplingThread::GetInstance()->Add( profiler_id_ = SamplingThread::GetInstance()->Add(
std::make_unique<SamplingThread::CollectionContext>( std::make_unique<SamplingThread::CollectionContext>(
thread_id_, params_, &profiling_inactive_, std::move(native_sampler_), thread_id_, params_, &profiling_inactive_, std::move(sampler_),
std::move(profile_builder_))); std::move(profile_builder_)));
DCHECK_NE(kNullProfilerId, profiler_id_); DCHECK_NE(kNullProfilerId, profiler_id_);
......
...@@ -10,15 +10,15 @@ ...@@ -10,15 +10,15 @@
#include "base/base_export.h" #include "base/base_export.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/sampling_heap_profiler/module_cache.h" #include "base/profiler/profile_builder.h"
#include "base/synchronization/waitable_event.h" #include "base/synchronization/waitable_event.h"
#include "base/threading/platform_thread.h" #include "base/threading/platform_thread.h"
#include "base/time/time.h" #include "base/time/time.h"
namespace base { namespace base {
class NativeStackSampler; class StackSampler;
class NativeStackSamplerTestDelegate; class StackSamplerTestDelegate;
// StackSamplingProfiler periodically stops a thread to sample its stack, for // StackSamplingProfiler periodically stops a thread to sample its stack, for
// the purpose of collecting information about which code paths are // the purpose of collecting information about which code paths are
...@@ -31,8 +31,7 @@ class NativeStackSamplerTestDelegate; ...@@ -31,8 +31,7 @@ class NativeStackSamplerTestDelegate;
// base::StackStackSamplingProfiler::SamplingParams params; // base::StackStackSamplingProfiler::SamplingParams params;
// //
// // To process the profiles, use a custom ProfileBuilder subclass: // // To process the profiles, use a custom ProfileBuilder subclass:
// class SubProfileBuilder : // class SubProfileBuilder : public base::ProfileBuilder {...}
// public base::StackSamplingProfiler::ProfileBuilder{...}
// //
// // On Android the |sampler| is not implemented in base. So, client can pass // // On Android the |sampler| is not implemented in base. So, client can pass
// // in |sampler| to use while profiling. // // in |sampler| to use while profiling.
...@@ -52,22 +51,6 @@ class NativeStackSamplerTestDelegate; ...@@ -52,22 +51,6 @@ class NativeStackSamplerTestDelegate;
// by the profiler. // by the profiler.
class BASE_EXPORT StackSamplingProfiler { class BASE_EXPORT StackSamplingProfiler {
public: public:
// Frame represents an individual sampled stack frame with full module
// information.
//
// This struct is only used for sampling data transfer from NativeStackSampler
// to ProfileBuilder.
struct BASE_EXPORT Frame {
Frame(uintptr_t instruction_pointer, const ModuleCache::Module* module);
~Frame();
// The sampled instruction pointer within the function.
uintptr_t instruction_pointer;
// The module information.
const ModuleCache::Module* module;
};
// Represents parameters that configure the sampling. // Represents parameters that configure the sampling.
struct BASE_EXPORT SamplingParams { struct BASE_EXPORT SamplingParams {
// Time to delay before first samples are taken. // Time to delay before first samples are taken.
...@@ -91,58 +74,23 @@ class BASE_EXPORT StackSamplingProfiler { ...@@ -91,58 +74,23 @@ class BASE_EXPORT StackSamplingProfiler {
bool keep_consistent_sampling_interval = true; bool keep_consistent_sampling_interval = true;
}; };
// The ProfileBuilder interface allows the user to record profile information
// on the fly in whatever format is desired. Functions are invoked by the
// profiler on its own thread so must not block or perform expensive
// operations.
class BASE_EXPORT ProfileBuilder {
public:
ProfileBuilder() = default;
virtual ~ProfileBuilder() = default;
// Gets the ModuleCache to be used by the StackSamplingProfiler when looking
// up modules from addresses.
virtual ModuleCache* GetModuleCache() = 0;
// Records metadata to be associated with the current sample. To avoid
// deadlock on locks taken by the suspended profiled thread, implementations
// of this method must not execute any code that could take a lock,
// including heap allocation or use of CHECK/DCHECK/LOG
// statements. Generally implementations should simply atomically copy
// metadata state to be associated with the sample.
virtual void RecordMetadata();
// Records a new set of frames. Invoked when sampling a sample completes.
virtual void OnSampleCompleted(std::vector<Frame> frames) = 0;
// Finishes the profile construction with |profile_duration| and
// |sampling_period|. Invoked when sampling a profile completes.
virtual void OnProfileCompleted(TimeDelta profile_duration,
TimeDelta sampling_period) = 0;
private:
DISALLOW_COPY_AND_ASSIGN(ProfileBuilder);
};
// Creates a profiler for the specified thread. An optional |test_delegate| // Creates a profiler for the specified thread. An optional |test_delegate|
// can be supplied by tests. // can be supplied by tests.
// //
// The caller must ensure that this object gets destroyed before the thread // The caller must ensure that this object gets destroyed before the thread
// exits. // exits.
StackSamplingProfiler( StackSamplingProfiler(PlatformThreadId thread_id,
PlatformThreadId thread_id, const SamplingParams& params,
const SamplingParams& params, std::unique_ptr<ProfileBuilder> profile_builder,
std::unique_ptr<ProfileBuilder> profile_builder, StackSamplerTestDelegate* test_delegate = nullptr);
NativeStackSamplerTestDelegate* test_delegate = nullptr);
// Same as above function, with custom |sampler| implementation. The sampler // Same as above function, with custom |sampler| implementation. The sampler
// on Android is not implemented in base. // on Android is not implemented in base.
StackSamplingProfiler( StackSamplingProfiler(PlatformThreadId thread_id,
PlatformThreadId thread_id, const SamplingParams& params,
const SamplingParams& params, std::unique_ptr<ProfileBuilder> profile_builder,
std::unique_ptr<ProfileBuilder> profile_builder, std::unique_ptr<StackSampler> sampler,
std::unique_ptr<NativeStackSampler> sampler, StackSamplerTestDelegate* test_delegate = nullptr);
NativeStackSamplerTestDelegate* test_delegate = nullptr);
// Stops any profiling currently taking place before destroying the profiler. // Stops any profiling currently taking place before destroying the profiler.
// This will block until profile_builder_'s OnProfileCompleted function has // This will block until profile_builder_'s OnProfileCompleted function has
...@@ -210,7 +158,7 @@ class BASE_EXPORT StackSamplingProfiler { ...@@ -210,7 +158,7 @@ class BASE_EXPORT StackSamplingProfiler {
// Stack sampler which stops the thread and collects stack frames. The // Stack sampler which stops the thread and collects stack frames. The
// ownership of this object will be transferred to the sampling thread when // ownership of this object will be transferred to the sampling thread when
// thread sampling starts. // thread sampling starts.
std::unique_ptr<NativeStackSampler> native_sampler_; std::unique_ptr<StackSampler> sampler_;
// This starts "signaled", is reset when sampling begins, and is signaled // This starts "signaled", is reset when sampling begins, and is signaled
// when that sampling is complete and the profile_builder_'s // when that sampling is complete and the profile_builder_'s
...@@ -221,8 +169,8 @@ class BASE_EXPORT StackSamplingProfiler { ...@@ -221,8 +169,8 @@ class BASE_EXPORT StackSamplingProfiler {
// will be an internal "null" value when no collection has been started. // will be an internal "null" value when no collection has been started.
int profiler_id_; int profiler_id_;
// Stored until it can be passed to the NativeStackSampler created in Start(). // Stored until it can be passed to the StackSampler created in Start().
NativeStackSamplerTestDelegate* const test_delegate_; StackSamplerTestDelegate* const test_delegate_;
DISALLOW_COPY_AND_ASSIGN(StackSamplingProfiler); DISALLOW_COPY_AND_ASSIGN(StackSamplingProfiler);
}; };
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/native_library.h" #include "base/native_library.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/profiler/native_stack_sampler.h" #include "base/profiler/stack_sampler.h"
#include "base/profiler/stack_sampling_profiler.h" #include "base/profiler/stack_sampling_profiler.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/scoped_native_library.h" #include "base/scoped_native_library.h"
...@@ -63,7 +63,7 @@ namespace base { ...@@ -63,7 +63,7 @@ namespace base {
#endif #endif
using SamplingParams = StackSamplingProfiler::SamplingParams; using SamplingParams = StackSamplingProfiler::SamplingParams;
using Frame = StackSamplingProfiler::Frame; using Frame = ProfileBuilder::Frame;
using Frames = std::vector<Frame>; using Frames = std::vector<Frame>;
using FrameSets = std::vector<std::vector<Frame>>; using FrameSets = std::vector<std::vector<Frame>>;
...@@ -316,14 +316,14 @@ Profile::Profile(const FrameSets& frame_sets, ...@@ -316,14 +316,14 @@ Profile::Profile(const FrameSets& frame_sets,
using ProfileCompletedCallback = Callback<void(Profile)>; using ProfileCompletedCallback = Callback<void(Profile)>;
// TestProfileBuilder collects frames produced by the profiler. // TestProfileBuilder collects frames produced by the profiler.
class TestProfileBuilder : public StackSamplingProfiler::ProfileBuilder { class TestProfileBuilder : public ProfileBuilder {
public: public:
TestProfileBuilder(ModuleCache* module_cache, TestProfileBuilder(ModuleCache* module_cache,
const ProfileCompletedCallback& callback); const ProfileCompletedCallback& callback);
~TestProfileBuilder() override; ~TestProfileBuilder() override;
// StackSamplingProfiler::ProfileBuilder: // ProfileBuilder:
ModuleCache* GetModuleCache() override; ModuleCache* GetModuleCache() override;
void RecordMetadata() override; void RecordMetadata() override;
void OnSampleCompleted(Frames frames) override; void OnSampleCompleted(Frames frames) override;
...@@ -443,7 +443,7 @@ struct TestProfilerInfo { ...@@ -443,7 +443,7 @@ struct TestProfilerInfo {
TestProfilerInfo(PlatformThreadId thread_id, TestProfilerInfo(PlatformThreadId thread_id,
const SamplingParams& params, const SamplingParams& params,
ModuleCache* module_cache, ModuleCache* module_cache,
NativeStackSamplerTestDelegate* delegate = nullptr) StackSamplerTestDelegate* delegate = nullptr)
: completed(WaitableEvent::ResetPolicy::MANUAL, : completed(WaitableEvent::ResetPolicy::MANUAL,
WaitableEvent::InitialState::NOT_SIGNALED), WaitableEvent::InitialState::NOT_SIGNALED),
profiler(thread_id, profiler(thread_id,
...@@ -580,7 +580,7 @@ TimeDelta AVeryLongTimeDelta() { ...@@ -580,7 +580,7 @@ TimeDelta AVeryLongTimeDelta() {
void TestLibraryUnload(bool wait_until_unloaded, ModuleCache* module_cache) { void TestLibraryUnload(bool wait_until_unloaded, ModuleCache* module_cache) {
// Test delegate that supports intervening between the copying of the stack // Test delegate that supports intervening between the copying of the stack
// and the walking of the stack. // and the walking of the stack.
class StackCopiedSignaler : public NativeStackSamplerTestDelegate { class StackCopiedSignaler : public StackSamplerTestDelegate {
public: public:
StackCopiedSignaler(WaitableEvent* stack_copied, StackCopiedSignaler(WaitableEvent* stack_copied,
WaitableEvent* start_stack_walk, WaitableEvent* start_stack_walk,
...@@ -878,7 +878,7 @@ PROFILER_TEST_F(StackSamplingProfilerTest, StopWithoutStarting) { ...@@ -878,7 +878,7 @@ PROFILER_TEST_F(StackSamplingProfilerTest, StopWithoutStarting) {
// sampling thread continues to run. // sampling thread continues to run.
PROFILER_TEST_F(StackSamplingProfilerTest, StopSafely) { PROFILER_TEST_F(StackSamplingProfilerTest, StopSafely) {
// Test delegate that counts samples. // Test delegate that counts samples.
class SampleRecordedCounter : public NativeStackSamplerTestDelegate { class SampleRecordedCounter : public StackSamplerTestDelegate {
public: public:
SampleRecordedCounter() = default; SampleRecordedCounter() = default;
...@@ -965,7 +965,7 @@ PROFILER_TEST_F(StackSamplingProfilerTest, StopDuringInitialDelay) { ...@@ -965,7 +965,7 @@ PROFILER_TEST_F(StackSamplingProfilerTest, StopDuringInitialDelay) {
// captured. // captured.
PROFILER_TEST_F(StackSamplingProfilerTest, StopDuringInterSampleInterval) { PROFILER_TEST_F(StackSamplingProfilerTest, StopDuringInterSampleInterval) {
// Test delegate that counts samples. // Test delegate that counts samples.
class SampleRecordedEvent : public NativeStackSamplerTestDelegate { class SampleRecordedEvent : public StackSamplerTestDelegate {
public: public:
SampleRecordedEvent() SampleRecordedEvent()
: sample_recorded_(WaitableEvent::ResetPolicy::MANUAL, : sample_recorded_(WaitableEvent::ResetPolicy::MANUAL,
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "base/feature_list.h" #include "base/feature_list.h"
#include "base/metrics/field_trial_params.h" #include "base/metrics/field_trial_params.h"
#include "base/metrics/metrics_hashes.h" #include "base/metrics/metrics_hashes.h"
#include "base/profiler/stack_sampling_profiler.h"
#include "base/rand_util.h" #include "base/rand_util.h"
#include "base/sampling_heap_profiler/module_cache.h" #include "base/sampling_heap_profiler/module_cache.h"
#include "base/sampling_heap_profiler/sampling_heap_profiler.h" #include "base/sampling_heap_profiler/sampling_heap_profiler.h"
...@@ -126,7 +125,7 @@ void HeapProfilerController::RetrieveAndSendSnapshot() { ...@@ -126,7 +125,7 @@ void HeapProfilerController::RetrieveAndSendSnapshot() {
&metadata_recorder); &metadata_recorder);
for (const base::SamplingHeapProfiler::Sample& sample : samples) { for (const base::SamplingHeapProfiler::Sample& sample : samples) {
std::vector<base::StackSamplingProfiler::Frame> frames; std::vector<base::ProfileBuilder::Frame> frames;
frames.reserve(sample.stack.size()); frames.reserve(sample.stack.size());
for (const void* frame : sample.stack) { for (const void* frame : sample.stack) {
uintptr_t address = reinterpret_cast<uintptr_t>(frame); uintptr_t address = reinterpret_cast<uintptr_t>(frame);
......
...@@ -83,7 +83,7 @@ void CallStackProfileBuilder::RecordMetadata() { ...@@ -83,7 +83,7 @@ void CallStackProfileBuilder::RecordMetadata() {
} }
void CallStackProfileBuilder::OnSampleCompleted( void CallStackProfileBuilder::OnSampleCompleted(
std::vector<base::StackSamplingProfiler::Frame> frames) { std::vector<base::ProfileBuilder::Frame> frames) {
// Write CallStackProfile::Stack protobuf message. // Write CallStackProfile::Stack protobuf message.
CallStackProfile::Stack stack; CallStackProfile::Stack stack;
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/profiler/stack_sampling_profiler.h" #include "base/profiler/profile_builder.h"
#include "base/sampling_heap_profiler/module_cache.h" #include "base/sampling_heap_profiler/module_cache.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "components/metrics/call_stack_profile_params.h" #include "components/metrics/call_stack_profile_params.h"
...@@ -55,8 +55,7 @@ class MetadataRecorder { ...@@ -55,8 +55,7 @@ class MetadataRecorder {
// //
// This uses the new StackSample encoding rather than the legacy Sample // This uses the new StackSample encoding rather than the legacy Sample
// encoding. // encoding.
class CallStackProfileBuilder class CallStackProfileBuilder : public base::ProfileBuilder {
: public base::StackSamplingProfiler::ProfileBuilder {
public: public:
// |completed_callback| is made when sampling a profile completes. Other // |completed_callback| is made when sampling a profile completes. Other
// threads, including the UI thread, may block on callback completion so this // threads, including the UI thread, may block on callback completion so this
...@@ -73,11 +72,11 @@ class CallStackProfileBuilder ...@@ -73,11 +72,11 @@ class CallStackProfileBuilder
~CallStackProfileBuilder() override; ~CallStackProfileBuilder() override;
// base::StackSamplingProfiler::ProfileBuilder: // base::ProfileBuilder:
base::ModuleCache* GetModuleCache() override; base::ModuleCache* GetModuleCache() override;
void RecordMetadata() override; void RecordMetadata() override;
void OnSampleCompleted( void OnSampleCompleted(
std::vector<base::StackSamplingProfiler::Frame> frames) override; std::vector<base::ProfileBuilder::Frame> frames) override;
void OnProfileCompleted(base::TimeDelta profile_duration, void OnProfileCompleted(base::TimeDelta profile_duration,
base::TimeDelta sampling_period) override; base::TimeDelta sampling_period) override;
......
...@@ -16,12 +16,12 @@ ...@@ -16,12 +16,12 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "third_party/metrics_proto/sampled_profile.pb.h" #include "third_party/metrics_proto/sampled_profile.pb.h"
using Frame = base::StackSamplingProfiler::Frame;
namespace metrics { namespace metrics {
namespace { namespace {
using Frame = base::ProfileBuilder::Frame;
// Stub module for testing. // Stub module for testing.
class TestModule : public base::ModuleCache::Module { class TestModule : public base::ModuleCache::Module {
public: public:
......
...@@ -35,8 +35,8 @@ component("tracing") { ...@@ -35,8 +35,8 @@ component("tracing") {
if (is_android && can_unwind_with_cfi_table && is_official_build) { if (is_android && can_unwind_with_cfi_table && is_official_build) {
sources += [ sources += [
"common/native_stack_sampler_android.cc", "common/stack_sampler_android.cc",
"common/native_stack_sampler_android.h", "common/stack_sampler_android.h",
"common/stack_unwinder_android.cc", "common/stack_unwinder_android.cc",
"common/stack_unwinder_android.h", "common/stack_unwinder_android.h",
] ]
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "components/tracing/common/native_stack_sampler_android.h" #include "components/tracing/common/stack_sampler_android.h"
#include "base/sampling_heap_profiler/module_cache.h" #include "base/profiler/profile_builder.h"
#include "base/trace_event/trace_event.h" #include "base/trace_event/trace_event.h"
namespace tracing { namespace tracing {
...@@ -12,14 +12,14 @@ namespace { ...@@ -12,14 +12,14 @@ namespace {
constexpr size_t kMaxFrameDepth = 48; constexpr size_t kMaxFrameDepth = 48;
} // namespace } // namespace
NativeStackSamplerAndroid::NativeStackSamplerAndroid(base::PlatformThreadId tid) StackSamplerAndroid::StackSamplerAndroid(base::PlatformThreadId tid)
: tid_(tid) {} : tid_(tid) {}
NativeStackSamplerAndroid::~NativeStackSamplerAndroid() = default; StackSamplerAndroid::~StackSamplerAndroid() = default;
void NativeStackSamplerAndroid::RecordStackFrames( void StackSamplerAndroid::RecordStackFrames(
StackBuffer* stack_buffer, StackBuffer* stack_buffer,
base::StackSamplingProfiler::ProfileBuilder* profile_builder) { base::ProfileBuilder* profile_builder) {
if (!unwinder_.is_initialized()) { if (!unwinder_.is_initialized()) {
// May block on disk access. This function is executed on the profiler // May block on disk access. This function is executed on the profiler
// thread, so this will only block profiling execution. // thread, so this will only block profiling execution.
...@@ -29,7 +29,7 @@ void NativeStackSamplerAndroid::RecordStackFrames( ...@@ -29,7 +29,7 @@ void NativeStackSamplerAndroid::RecordStackFrames(
} }
const void* pcs[kMaxFrameDepth]; const void* pcs[kMaxFrameDepth];
size_t depth = unwinder_.TraceStack(tid_, stack_buffer, pcs, kMaxFrameDepth); size_t depth = unwinder_.TraceStack(tid_, stack_buffer, pcs, kMaxFrameDepth);
std::vector<base::StackSamplingProfiler::Frame> frames; std::vector<base::ProfileBuilder::Frame> frames;
frames.reserve(depth); frames.reserve(depth);
for (size_t i = 0; i < depth; ++i) { for (size_t i = 0; i < depth; ++i) {
// TODO(ssid): Add support for obtaining modules here. // TODO(ssid): Add support for obtaining modules here.
......
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef COMPONENTS_TRACING_COMMON_NATIVE_STACK_SAMPLER_ANDROID_H_ #ifndef COMPONENTS_TRACING_COMMON_STACK_SAMPLER_ANDROID_H_
#define COMPONENTS_TRACING_COMMON_NATIVE_STACK_SAMPLER_ANDROID_H_ #define COMPONENTS_TRACING_COMMON_STACK_SAMPLER_ANDROID_H_
#include "base/profiler/native_stack_sampler.h" #include "base/profiler/stack_sampler.h"
#include "base/threading/platform_thread.h" #include "base/threading/platform_thread.h"
#include "components/tracing/common/stack_unwinder_android.h" #include "components/tracing/common/stack_unwinder_android.h"
...@@ -13,26 +13,26 @@ namespace tracing { ...@@ -13,26 +13,26 @@ namespace tracing {
// On Android the sampling implementation is delegated and this class just // On Android the sampling implementation is delegated and this class just
// stores a callback to the real implementation. // stores a callback to the real implementation.
class NativeStackSamplerAndroid : public base::NativeStackSampler { class StackSamplerAndroid : public base::StackSampler {
public: public:
// StackUnwinderAndroid only supports sampling one thread at a time. So, the // StackUnwinderAndroid only supports sampling one thread at a time. So, the
// clients of this class must ensure synchronization between multiple // clients of this class must ensure synchronization between multiple
// instances of the sampler. // instances of the sampler.
NativeStackSamplerAndroid(base::PlatformThreadId thread_id); explicit StackSamplerAndroid(base::PlatformThreadId thread_id);
~NativeStackSamplerAndroid() override; ~StackSamplerAndroid() override;
// StackSamplingProfiler::NativeStackSampler: StackSamplerAndroid(const StackSamplerAndroid&) = delete;
void RecordStackFrames( StackSamplerAndroid& operator=(const StackSamplerAndroid&) = delete;
StackBuffer* stack_buffer,
base::StackSamplingProfiler::ProfileBuilder* profile_builder) override; // StackSamplingProfiler::StackSampler:
void RecordStackFrames(StackBuffer* stack_buffer,
base::ProfileBuilder* profile_builder) override;
private: private:
base::PlatformThreadId tid_; base::PlatformThreadId tid_;
StackUnwinderAndroid unwinder_; StackUnwinderAndroid unwinder_;
DISALLOW_COPY_AND_ASSIGN(NativeStackSamplerAndroid);
}; };
} // namespace tracing } // namespace tracing
#endif // COMPONENTS_TRACING_COMMON_NATIVE_STACK_SAMPLER_ANDROID_H_ #endif // COMPONENTS_TRACING_COMMON_STACK_SAMPLER_ANDROID_H_
...@@ -92,7 +92,7 @@ class UnwindHelper { ...@@ -92,7 +92,7 @@ class UnwindHelper {
const tracing::StackUnwinderAndroid* unwinder, const tracing::StackUnwinderAndroid* unwinder,
uintptr_t original_sp, uintptr_t original_sp,
size_t stack_size, size_t stack_size,
base::NativeStackSampler::StackBuffer* stack_buffer, base::StackSampler::StackBuffer* stack_buffer,
const void** out_trace, const void** out_trace,
size_t max_depth) size_t max_depth)
: use_libunwind_(use_libunwind), : use_libunwind_(use_libunwind),
...@@ -120,7 +120,7 @@ class UnwindHelper { ...@@ -120,7 +120,7 @@ class UnwindHelper {
size_t Unwind(uintptr_t original_sp, size_t Unwind(uintptr_t original_sp,
unw_context_t* context, unw_context_t* context,
const ucontext_t& signal_context, const ucontext_t& signal_context,
base::NativeStackSampler::StackBuffer* stack_buffer) { base::StackSampler::StackBuffer* stack_buffer) {
const uintptr_t new_stack_top = initial_sp_; const uintptr_t new_stack_top = initial_sp_;
// Set the frame to the return frame from signal handler. // Set the frame to the return frame from signal handler.
current_ip_ = signal_context.uc_mcontext.arm_pc; current_ip_ = signal_context.uc_mcontext.arm_pc;
...@@ -312,7 +312,7 @@ class UnwindHelper { ...@@ -312,7 +312,7 @@ class UnwindHelper {
} }
void RewritePointersAndGetMarkers( void RewritePointersAndGetMarkers(
base::NativeStackSampler::StackBuffer* stack_buffer, base::StackSampler::StackBuffer* stack_buffer,
uintptr_t original_sp, uintptr_t original_sp,
size_t stack_size) { size_t stack_size) {
jni_markers_.clear(); jni_markers_.clear();
...@@ -398,7 +398,7 @@ struct HandlerParams { ...@@ -398,7 +398,7 @@ struct HandlerParams {
// The context of the return function from signal context. // The context of the return function from signal context.
ucontext_t* ucontext; ucontext_t* ucontext;
// Buffer to copy the stack segment. // Buffer to copy the stack segment.
base::NativeStackSampler::StackBuffer* stack_buffer; base::StackSampler::StackBuffer* stack_buffer;
size_t* stack_size; size_t* stack_size;
}; };
...@@ -536,7 +536,7 @@ size_t StackUnwinderAndroid::TraceStack(const void** out_trace, ...@@ -536,7 +536,7 @@ size_t StackUnwinderAndroid::TraceStack(const void** out_trace,
size_t StackUnwinderAndroid::TraceStack( size_t StackUnwinderAndroid::TraceStack(
base::PlatformThreadId tid, base::PlatformThreadId tid,
base::NativeStackSampler::StackBuffer* stack_buffer, base::StackSampler::StackBuffer* stack_buffer,
const void** out_trace, const void** out_trace,
size_t max_depth) const { size_t max_depth) const {
// Stops the thread with given tid with a signal handler. The signal handler // Stops the thread with given tid with a signal handler. The signal handler
...@@ -579,7 +579,7 @@ bool StackUnwinderAndroid::IsAddressMapped(uintptr_t pc) const { ...@@ -579,7 +579,7 @@ bool StackUnwinderAndroid::IsAddressMapped(uintptr_t pc) const {
bool StackUnwinderAndroid::SuspendThreadAndRecordStack( bool StackUnwinderAndroid::SuspendThreadAndRecordStack(
base::PlatformThreadId tid, base::PlatformThreadId tid,
base::NativeStackSampler::StackBuffer* stack_buffer, base::StackSampler::StackBuffer* stack_buffer,
uintptr_t* sp, uintptr_t* sp,
size_t* stack_size, size_t* stack_size,
unw_context_t* context, unw_context_t* context,
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include <vector> #include <vector>
#include "base/debug/proc_maps_linux.h" #include "base/debug/proc_maps_linux.h"
#include "base/profiler/native_stack_sampler.h" #include "base/profiler/stack_sampler.h"
#include "base/threading/platform_thread.h" #include "base/threading/platform_thread.h"
#include "components/tracing/tracing_export.h" #include "components/tracing/tracing_export.h"
...@@ -52,7 +52,7 @@ class TRACING_EXPORT StackUnwinderAndroid { ...@@ -52,7 +52,7 @@ class TRACING_EXPORT StackUnwinderAndroid {
// Same as above function, but pauses the thread with the given |tid| and then // Same as above function, but pauses the thread with the given |tid| and then
// unwinds. |tid| should not be current thread's. // unwinds. |tid| should not be current thread's.
size_t TraceStack(base::PlatformThreadId tid, size_t TraceStack(base::PlatformThreadId tid,
base::NativeStackSampler::StackBuffer* stack_buffer, base::StackSampler::StackBuffer* stack_buffer,
const void** out_trace, const void** out_trace,
size_t max_depth) const; size_t max_depth) const;
...@@ -71,7 +71,7 @@ class TRACING_EXPORT StackUnwinderAndroid { ...@@ -71,7 +71,7 @@ class TRACING_EXPORT StackUnwinderAndroid {
// success. // success.
bool SuspendThreadAndRecordStack( bool SuspendThreadAndRecordStack(
base::PlatformThreadId tid, base::PlatformThreadId tid,
base::NativeStackSampler::StackBuffer* stack_buffer, base::StackSampler::StackBuffer* stack_buffer,
uintptr_t* sp, uintptr_t* sp,
size_t* stack_size, size_t* stack_size,
unw_context_t* context, unw_context_t* context,
...@@ -80,7 +80,7 @@ class TRACING_EXPORT StackUnwinderAndroid { ...@@ -80,7 +80,7 @@ class TRACING_EXPORT StackUnwinderAndroid {
// Replaces any pointers to the old stack to point to the new stack segment. // Replaces any pointers to the old stack to point to the new stack segment.
// Returns the jni markers found on stack while scanning stack for pointers. // Returns the jni markers found on stack while scanning stack for pointers.
std::vector<const JniMarker*> RewritePointersAndGetMarkers( std::vector<const JniMarker*> RewritePointersAndGetMarkers(
base::NativeStackSampler::StackBuffer* stack_buffer, base::StackSampler::StackBuffer* stack_buffer,
uintptr_t sp, uintptr_t sp,
size_t stack_size) const; size_t stack_size) const;
......
...@@ -67,7 +67,7 @@ TEST_F(StackUnwinderTest, UnwindOtherThread) { ...@@ -67,7 +67,7 @@ TEST_F(StackUnwinderTest, UnwindOtherThread) {
base::WaitableEvent* unwind_finished_event, base::WaitableEvent* unwind_finished_event,
uintptr_t test_pc) { uintptr_t test_pc) {
const void* frames[kMaxStackFrames]; const void* frames[kMaxStackFrames];
auto stack_buffer = base::NativeStackSampler::CreateStackBuffer(); auto stack_buffer = base::StackSampler::CreateStackBuffer();
EXPECT_GT(stack_buffer->size(), 0u); EXPECT_GT(stack_buffer->size(), 0u);
size_t result = size_t result =
unwinder->TraceStack(tid, stack_buffer.get(), frames, kMaxStackFrames); unwinder->TraceStack(tid, stack_buffer.get(), frames, kMaxStackFrames);
...@@ -111,7 +111,7 @@ TEST_F(StackUnwinderTest, UnwindOtherThreadOnJNICall) { ...@@ -111,7 +111,7 @@ TEST_F(StackUnwinderTest, UnwindOtherThreadOnJNICall) {
auto callback = [](StackUnwinderAndroid* unwinder, base::PlatformThreadId tid, auto callback = [](StackUnwinderAndroid* unwinder, base::PlatformThreadId tid,
uintptr_t test_pc) { uintptr_t test_pc) {
const void* frames[kMaxStackFrames]; const void* frames[kMaxStackFrames];
auto stack_buffer = base::NativeStackSampler::CreateStackBuffer(); auto stack_buffer = base::StackSampler::CreateStackBuffer();
EXPECT_GT(stack_buffer->size(), 0u); EXPECT_GT(stack_buffer->size(), 0u);
size_t result = size_t result =
unwinder->TraceStack(tid, stack_buffer.get(), frames, kMaxStackFrames); unwinder->TraceStack(tid, stack_buffer.get(), frames, kMaxStackFrames);
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#include <dlfcn.h> #include <dlfcn.h>
#include "base/trace_event/cfi_backtrace_android.h" #include "base/trace_event/cfi_backtrace_android.h"
#include "components/tracing/common/native_stack_sampler_android.h" #include "components/tracing/common/stack_sampler_android.h"
#endif #endif
namespace tracing { namespace tracing {
...@@ -50,7 +50,7 @@ TracingSamplerProfiler::TracingProfileBuilder::GetModuleCache() { ...@@ -50,7 +50,7 @@ TracingSamplerProfiler::TracingProfileBuilder::GetModuleCache() {
} }
void TracingSamplerProfiler::TracingProfileBuilder::OnSampleCompleted( void TracingSamplerProfiler::TracingProfileBuilder::OnSampleCompleted(
std::vector<base::StackSamplingProfiler::Frame> frames) { std::vector<base::ProfileBuilder::Frame> frames) {
int process_priority = base::Process::Current().GetPriority(); int process_priority = base::Process::Current().GetPriority();
TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("cpu_profiler"), TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("cpu_profiler"),
"ProcessPriority", TRACE_EVENT_SCOPE_THREAD, "priority", "ProcessPriority", TRACE_EVENT_SCOPE_THREAD, "priority",
...@@ -201,7 +201,7 @@ void TracingSamplerProfiler::OnTraceLogEnabled() { ...@@ -201,7 +201,7 @@ void TracingSamplerProfiler::OnTraceLogEnabled() {
profiler_ = std::make_unique<base::StackSamplingProfiler>( profiler_ = std::make_unique<base::StackSamplingProfiler>(
sampled_thread_id_, params, sampled_thread_id_, params,
std::make_unique<TracingProfileBuilder>(sampled_thread_id_), std::make_unique<TracingProfileBuilder>(sampled_thread_id_),
std::make_unique<NativeStackSamplerAndroid>(sampled_thread_id_)); std::make_unique<StackSamplerAndroid>(sampled_thread_id_));
#else #else
profiler_ = std::make_unique<base::StackSamplingProfiler>( profiler_ = std::make_unique<base::StackSamplingProfiler>(
sampled_thread_id_, params, sampled_thread_id_, params,
......
...@@ -29,15 +29,14 @@ class TRACING_EXPORT TracingSamplerProfiler ...@@ -29,15 +29,14 @@ class TRACING_EXPORT TracingSamplerProfiler
public: public:
// This class will receive the sampling profiler stackframes and output them // This class will receive the sampling profiler stackframes and output them
// to the chrome trace via an event. Exposed for testing. // to the chrome trace via an event. Exposed for testing.
class TRACING_EXPORT TracingProfileBuilder class TRACING_EXPORT TracingProfileBuilder : public base::ProfileBuilder {
: public base::StackSamplingProfiler::ProfileBuilder {
public: public:
TracingProfileBuilder(base::PlatformThreadId sampled_thread_id); TracingProfileBuilder(base::PlatformThreadId sampled_thread_id);
// base::StackSamplingProfiler::ProfileBuilder // base::ProfileBuilder
base::ModuleCache* GetModuleCache() override; base::ModuleCache* GetModuleCache() override;
void OnSampleCompleted( void OnSampleCompleted(
std::vector<base::StackSamplingProfiler::Frame> frames) override; std::vector<base::ProfileBuilder::Frame> frames) override;
void OnProfileCompleted(base::TimeDelta profile_duration, void OnProfileCompleted(base::TimeDelta profile_duration,
base::TimeDelta sampling_period) override {} base::TimeDelta sampling_period) override {}
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/json/json_reader.h" #include "base/json/json_reader.h"
#include "base/memory/ref_counted_memory.h" #include "base/memory/ref_counted_memory.h"
#include "base/profiler/stack_sampling_profiler.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/test/scoped_task_environment.h" #include "base/test/scoped_task_environment.h"
#include "base/threading/thread.h" #include "base/threading/thread.h"
...@@ -22,7 +21,6 @@ namespace tracing { ...@@ -22,7 +21,6 @@ namespace tracing {
namespace { namespace {
using base::trace_event::TraceLog; using base::trace_event::TraceLog;
using base::StackSamplingProfiler;
class TracingSampleProfilerTest : public testing::Test { class TracingSampleProfilerTest : public testing::Test {
public: public:
...@@ -195,14 +193,14 @@ TEST(TracingProfileBuilderTest, ValidModule) { ...@@ -195,14 +193,14 @@ TEST(TracingProfileBuilderTest, ValidModule) {
TracingSamplerProfiler::TracingProfileBuilder profile_builder( TracingSamplerProfiler::TracingProfileBuilder profile_builder(
(base::PlatformThreadId())); (base::PlatformThreadId()));
profile_builder.OnSampleCompleted( profile_builder.OnSampleCompleted(
{base::StackSamplingProfiler::Frame(0x1010, &module)}); {base::ProfileBuilder::Frame(0x1010, &module)});
} }
TEST(TracingProfileBuilderTest, InvalidModule) { TEST(TracingProfileBuilderTest, InvalidModule) {
TracingSamplerProfiler::TracingProfileBuilder profile_builder( TracingSamplerProfiler::TracingProfileBuilder profile_builder(
(base::PlatformThreadId())); (base::PlatformThreadId()));
profile_builder.OnSampleCompleted( profile_builder.OnSampleCompleted(
{base::StackSamplingProfiler::Frame(0x1010, nullptr)}); {base::ProfileBuilder::Frame(0x1010, nullptr)});
} }
} // namespace tracing } // namespace tracing
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