Commit 9758caa1 authored by ssid's avatar ssid Committed by Commit Bot

Add module id in android sampling profiles

The unwinder uses module cache on Android to get module ids.

Change-Id: Iec80ae7f77581ce45d96a9f2b5d5585c3d1a7bb6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1699305
Commit-Queue: ssid <ssid@chromium.org>
Reviewed-by: default avataroysteine <oysteine@chromium.org>
Cr-Commit-Position: refs/heads/master@{#677101}
parent 78d550c3
...@@ -13,8 +13,9 @@ namespace { ...@@ -13,8 +13,9 @@ namespace {
constexpr size_t kMaxFrameDepth = 48; constexpr size_t kMaxFrameDepth = 48;
} // namespace } // namespace
StackSamplerAndroid::StackSamplerAndroid(base::PlatformThreadId tid) StackSamplerAndroid::StackSamplerAndroid(base::PlatformThreadId tid,
: tid_(tid) {} base::ModuleCache* module_cache)
: tid_(tid), module_cache_(module_cache) {}
StackSamplerAndroid::~StackSamplerAndroid() = default; StackSamplerAndroid::~StackSamplerAndroid() = default;
...@@ -38,8 +39,8 @@ void StackSamplerAndroid::RecordStackFrames( ...@@ -38,8 +39,8 @@ void StackSamplerAndroid::RecordStackFrames(
std::vector<base::Frame> frames; std::vector<base::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. uintptr_t address = reinterpret_cast<uintptr_t>(pcs[i]);
frames.emplace_back(reinterpret_cast<uintptr_t>(pcs[i]), nullptr); frames.emplace_back(address, module_cache_->GetModuleForAddress(address));
} }
profile_builder->OnSampleCompleted(std::move(frames)); profile_builder->OnSampleCompleted(std::move(frames));
} }
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define SERVICES_TRACING_PUBLIC_CPP_STACK_SAMPLING_STACK_SAMPLER_ANDROID_H_ #define SERVICES_TRACING_PUBLIC_CPP_STACK_SAMPLING_STACK_SAMPLER_ANDROID_H_
#include "base/profiler/stack_sampler.h" #include "base/profiler/stack_sampler.h"
#include "base/sampling_heap_profiler/module_cache.h"
#include "base/threading/platform_thread.h" #include "base/threading/platform_thread.h"
#include "services/tracing/public/cpp/stack_sampling/stack_unwinder_android.h" #include "services/tracing/public/cpp/stack_sampling/stack_unwinder_android.h"
...@@ -18,7 +19,8 @@ class StackSamplerAndroid : public base::StackSampler { ...@@ -18,7 +19,8 @@ class StackSamplerAndroid : public base::StackSampler {
// 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.
explicit StackSamplerAndroid(base::PlatformThreadId thread_id); explicit StackSamplerAndroid(base::PlatformThreadId thread_id,
base::ModuleCache*);
~StackSamplerAndroid() override; ~StackSamplerAndroid() override;
StackSamplerAndroid(const StackSamplerAndroid&) = delete; StackSamplerAndroid(const StackSamplerAndroid&) = delete;
...@@ -31,6 +33,7 @@ class StackSamplerAndroid : public base::StackSampler { ...@@ -31,6 +33,7 @@ class StackSamplerAndroid : public base::StackSampler {
private: private:
base::PlatformThreadId tid_; base::PlatformThreadId tid_;
base::ModuleCache* module_cache_;
StackUnwinderAndroid unwinder_; StackUnwinderAndroid unwinder_;
}; };
......
...@@ -279,6 +279,11 @@ TracingSamplerProfiler::TracingProfileBuilder::GetCallstackIDAndMaybeEmit( ...@@ -279,6 +279,11 @@ TracingSamplerProfiler::TracingProfileBuilder::GetCallstackIDAndMaybeEmit(
// useless anyway. // useless anyway.
if (frame_name.empty()) if (frame_name.empty())
frame_name = "Unknown"; frame_name = "Unknown";
if (frame.module) {
module_id = frame.module->GetId();
if (module_name.empty())
module_name = frame.module->GetDebugBasename().MaybeAsASCII();
}
#else #else
if (frame.module) { if (frame.module) {
module_name = frame.module->GetDebugBasename().MaybeAsASCII(); module_name = frame.module->GetDebugBasename().MaybeAsASCII();
...@@ -447,11 +452,13 @@ void TracingSamplerProfiler::StartTracing( ...@@ -447,11 +452,13 @@ void TracingSamplerProfiler::StartTracing(
// Create and start the stack sampling profiler. // Create and start the stack sampling profiler.
#if defined(OS_ANDROID) && BUILDFLAG(CAN_UNWIND_WITH_CFI_TABLE) && \ #if defined(OS_ANDROID) && BUILDFLAG(CAN_UNWIND_WITH_CFI_TABLE) && \
defined(OFFICIAL_BUILD) defined(OFFICIAL_BUILD)
auto profile_builder = std::make_unique<TracingProfileBuilder>(
sampled_thread_id_, std::move(trace_writer), should_enable_filtering);
auto* module_cache = profile_builder->GetModuleCache();
profiler_ = std::make_unique<base::StackSamplingProfiler>( profiler_ = std::make_unique<base::StackSamplingProfiler>(
sampled_thread_id_, params, sampled_thread_id_, params, std::move(profile_builder),
std::make_unique<TracingProfileBuilder>( std::make_unique<StackSamplerAndroid>(sampled_thread_id_, module_cache));
sampled_thread_id_, std::move(trace_writer), should_enable_filtering),
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,
......
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