Commit 93cddd08 authored by Etienne Bergeron's avatar Etienne Bergeron Committed by Commit Bot

Add sampled thread id to the stack sampling events

This CL is adding the thread id for each sampled stack event.
This will allow using multiple sampling profiler in the same process.

We are planning to sample the UI and the IO thread in the browser process.


R=ssid@chromium.org

Change-Id: Ia520c7886356fa7bf5d5f069d079125db156995d
Reviewed-on: https://chromium-review.googlesource.com/c/1310500Reviewed-by: default avatarGabriel Charette <gab@chromium.org>
Reviewed-by: default avatarssid <ssid@chromium.org>
Commit-Queue: Etienne Bergeron <etienneb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606557}
parent 37c3a555
...@@ -36,12 +36,15 @@ std::string GetFrameNameFromOffsetAddr(uintptr_t offset_from_module_base) { ...@@ -36,12 +36,15 @@ std::string GetFrameNameFromOffsetAddr(uintptr_t offset_from_module_base) {
class TracingProfileBuilder class TracingProfileBuilder
: public base::StackSamplingProfiler::ProfileBuilder { : public base::StackSamplingProfiler::ProfileBuilder {
public: public:
TracingProfileBuilder(base::PlatformThreadId sampled_thread_id)
: sampled_thread_id_(sampled_thread_id) {}
void OnSampleCompleted( void OnSampleCompleted(
std::vector<base::StackSamplingProfiler::Frame> frames) override { std::vector<base::StackSamplingProfiler::Frame> frames) override {
if (frames.empty()) { if (frames.empty()) {
TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("cpu_profiler"), TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("cpu_profiler"),
"StackCpuSampling", TRACE_EVENT_SCOPE_THREAD, "StackCpuSampling", TRACE_EVENT_SCOPE_THREAD,
"frames", "empty"); "frames", "empty", "thread_id", sampled_thread_id_);
return; return;
} }
...@@ -101,13 +104,16 @@ class TracingProfileBuilder ...@@ -101,13 +104,16 @@ class TracingProfileBuilder
module_name.c_str(), frame.module.id.c_str()); module_name.c_str(), frame.module.id.c_str());
} }
TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("cpu_profiler"), TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("cpu_profiler"),
"StackCpuSampling", TRACE_EVENT_SCOPE_THREAD, "frames", "StackCpuSampling", TRACE_EVENT_SCOPE_THREAD, "frames",
result); result, "thread_id", sampled_thread_id_);
} }
void OnProfileCompleted(base::TimeDelta profile_duration, void OnProfileCompleted(base::TimeDelta profile_duration,
base::TimeDelta sampling_period) override {} base::TimeDelta sampling_period) override {}
private:
base::PlatformThreadId sampled_thread_id_;
}; };
} // namespace } // namespace
...@@ -153,11 +159,13 @@ void TracingSamplerProfiler::OnTraceLogEnabled() { ...@@ -153,11 +159,13 @@ void TracingSamplerProfiler::OnTraceLogEnabled() {
#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)
profiler_ = std::make_unique<base::StackSamplingProfiler>( profiler_ = std::make_unique<base::StackSamplingProfiler>(
sampled_thread_id_, params, std::make_unique<TracingProfileBuilder>(), sampled_thread_id_, params,
std::make_unique<TracingProfileBuilder>(sampled_thread_id_),
std::make_unique<NativeStackSamplerAndroid>(sampled_thread_id_)); std::make_unique<NativeStackSamplerAndroid>(sampled_thread_id_));
#else #else
profiler_ = std::make_unique<base::StackSamplingProfiler>( profiler_ = std::make_unique<base::StackSamplingProfiler>(
sampled_thread_id_, params, std::make_unique<TracingProfileBuilder>()); sampled_thread_id_, params,
std::make_unique<TracingProfileBuilder>(sampled_thread_id_));
#endif #endif
profiler_->Start(); profiler_->Start();
} }
......
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