Commit 863587aa authored by Mike Wittman's avatar Mike Wittman Committed by Commit Bot

[Sampling profiler] Add ThreadDelegate::GetThreadId()

This interface will be used for POSIX stack copying in a following CL.

Bug: 988579
Change-Id: Iefd9c14031ef34f88587de4615b58faa8a58dd9a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1860150
Commit-Queue: Mike Wittman <wittman@chromium.org>
Reviewed-by: default avatarCharlie Andrews <charliea@chromium.org>
Cr-Commit-Position: refs/heads/master@{#708345}
parent 292bd0d3
......@@ -63,6 +63,8 @@ class TestSuspendableThreadDelegate : public SuspendableThreadDelegate {
return true;
}
PlatformThreadId GetThreadId() const override { return PlatformThreadId(); }
uintptr_t GetStackBaseAddress() const override {
return reinterpret_cast<uintptr_t>(&fake_stack_[0] + fake_stack_.size());
}
......
......@@ -78,6 +78,10 @@ SuspendableThreadDelegateMac::CreateScopedSuspendThread() {
return std::make_unique<ScopedSuspendThread>(thread_port_);
}
PlatformThreadId SuspendableThreadDelegateMac::GetThreadId() const {
return thread_port_;
}
// NO HEAP ALLOCATIONS.
bool SuspendableThreadDelegateMac::GetThreadContext(
x86_thread_state64_t* thread_context) {
......
......@@ -46,6 +46,7 @@ class BASE_EXPORT SuspendableThreadDelegateMac
std::unique_ptr<SuspendableThreadDelegate::ScopedSuspendThread>
CreateScopedSuspendThread() override;
bool GetThreadContext(x86_thread_state64_t* thread_context) override;
PlatformThreadId GetThreadId() const override;
uintptr_t GetStackBaseAddress() const override;
bool CanCopyStack(uintptr_t stack_pointer) override;
std::vector<uintptr_t*> GetRegistersToRewrite(
......@@ -53,7 +54,7 @@ class BASE_EXPORT SuspendableThreadDelegateMac
private:
// Weak reference: Mach port for thread being profiled.
mach_port_t thread_port_;
const mach_port_t thread_port_;
// The stack base address corresponding to |thread_port_|.
const uintptr_t thread_stack_base_address_;
......
......@@ -173,7 +173,8 @@ bool SuspendableThreadDelegateWin::ScopedSuspendThread::WasSuccessful() const {
SuspendableThreadDelegateWin::SuspendableThreadDelegateWin(
PlatformThreadId thread_id)
: thread_handle_(GetThreadHandle(thread_id)),
: thread_id_(thread_id),
thread_handle_(GetThreadHandle(thread_id)),
thread_stack_base_address_(reinterpret_cast<uintptr_t>(
GetThreadEnvironmentBlock(thread_handle_.Get())->Tib.StackBase)) {}
......@@ -184,6 +185,10 @@ SuspendableThreadDelegateWin::CreateScopedSuspendThread() {
return std::make_unique<ScopedSuspendThread>(thread_handle_.Get());
}
PlatformThreadId SuspendableThreadDelegateWin::GetThreadId() const {
return thread_id_;
}
// NO HEAP ALLOCATIONS.
bool SuspendableThreadDelegateWin::GetThreadContext(CONTEXT* thread_context) {
*thread_context = {0};
......
......@@ -45,12 +45,14 @@ class BASE_EXPORT SuspendableThreadDelegateWin
std::unique_ptr<SuspendableThreadDelegate::ScopedSuspendThread>
CreateScopedSuspendThread() override;
bool GetThreadContext(CONTEXT* thread_context) override;
PlatformThreadId GetThreadId() const override;
uintptr_t GetStackBaseAddress() const override;
bool CanCopyStack(uintptr_t stack_pointer) override;
std::vector<uintptr_t*> GetRegistersToRewrite(
CONTEXT* thread_context) override;
private:
const PlatformThreadId thread_id_;
win::ScopedHandle thread_handle_;
const uintptr_t thread_stack_base_address_;
};
......
......@@ -9,6 +9,7 @@
#include "base/base_export.h"
#include "base/profiler/register_context.h"
#include "base/threading/platform_thread.h"
namespace base {
......@@ -24,6 +25,9 @@ class BASE_EXPORT ThreadDelegate {
ThreadDelegate(const ThreadDelegate&) = delete;
ThreadDelegate& operator=(const ThreadDelegate&) = delete;
// Gets the platform-specific id for the thread.
virtual PlatformThreadId GetThreadId() const = 0;
// Gets the base address of the thread's stack.
virtual uintptr_t GetStackBaseAddress() const = 0;
......
......@@ -24,7 +24,12 @@ uintptr_t GetThreadStackBaseAddress(PlatformThreadId thread_id) {
} // namespace
ThreadDelegatePosix::ThreadDelegatePosix(PlatformThreadId thread_id)
: thread_stack_base_address_(GetThreadStackBaseAddress(thread_id)) {}
: thread_id_(thread_id),
thread_stack_base_address_(GetThreadStackBaseAddress(thread_id)) {}
PlatformThreadId ThreadDelegatePosix::GetThreadId() const {
return thread_id_;
}
uintptr_t ThreadDelegatePosix::GetStackBaseAddress() const {
return thread_stack_base_address_;
......
......@@ -21,11 +21,13 @@ class BASE_EXPORT ThreadDelegatePosix : public ThreadDelegate {
ThreadDelegatePosix& operator=(const ThreadDelegatePosix&) = delete;
// ThreadDelegate
PlatformThreadId GetThreadId() const override;
uintptr_t GetStackBaseAddress() const override;
std::vector<uintptr_t*> GetRegistersToRewrite(
RegisterContext* thread_context) override;
private:
const PlatformThreadId thread_id_;
const uintptr_t thread_stack_base_address_;
};
......
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