Commit 87e15603 authored by Etienne Bergeron's avatar Etienne Bergeron Committed by Commit Bot

Sample process priority to slow-reports

This CL sampling the current process priority and add an instant event
to report it.

This will be used to figure out some priority inversion related to the
GPU process and background renderers.

R=oysteine@chromium.org

Change-Id: I9e2f9b4b48379ade4d476dd7c7fd2b2fe52639d7
Reviewed-on: https://chromium-review.googlesource.com/c/1350189Reviewed-by: default avataroysteine <oysteine@chromium.org>
Commit-Queue: Etienne Bergeron <etienneb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#611393}
parent e2cf7f50
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/format_macros.h" #include "base/format_macros.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/no_destructor.h" #include "base/no_destructor.h"
#include "base/process/process.h"
#include "base/profiler/stack_sampling_profiler.h" #include "base/profiler/stack_sampling_profiler.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/threading/sequence_local_storage_slot.h" #include "base/threading/sequence_local_storage_slot.h"
...@@ -43,6 +44,11 @@ class TracingProfileBuilder ...@@ -43,6 +44,11 @@ class TracingProfileBuilder
void OnSampleCompleted( void OnSampleCompleted(
std::vector<base::StackSamplingProfiler::Frame> frames) override { std::vector<base::StackSamplingProfiler::Frame> frames) override {
int process_priority = base::Process::Current().GetPriority();
TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("cpu_profiler"),
"ProcessPriority", TRACE_EVENT_SCOPE_THREAD,
"priority", process_priority);
if (frames.empty()) { if (frames.empty()) {
TRACE_EVENT_INSTANT2(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,
......
...@@ -54,8 +54,6 @@ class TracingSampleProfilerTest : public testing::Test { ...@@ -54,8 +54,6 @@ class TracingSampleProfilerTest : public testing::Test {
base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(200)); base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(200));
} }
size_t events_received_count() { return events_received_count_; }
// Returns whether of not the sampler profiling is able to unwind the stack // Returns whether of not the sampler profiling is able to unwind the stack
// on this platform. // on this platform.
bool IsStackUnwindingSupported() { bool IsStackUnwindingSupported() {
...@@ -106,12 +104,25 @@ class TracingSampleProfilerTest : public testing::Test { ...@@ -106,12 +104,25 @@ class TracingSampleProfilerTest : public testing::Test {
CHECK(item->GetAsDictionary(&dict)); CHECK(item->GetAsDictionary(&dict));
std::string name; std::string name;
CHECK(dict->GetString("name", &name)); CHECK(dict->GetString("name", &name));
if (name == "StackCpuSampling") if (name == "StackCpuSampling") {
events_received_count_++; events_stack_received_count_++;
} else if (name == "ProcessPriority") {
events_priority_received_count_++;
}
} }
} }
} }
void ValidateReceivedEvents() {
if (IsStackUnwindingSupported()) {
EXPECT_GT(events_stack_received_count_, 0U);
EXPECT_GT(events_priority_received_count_, 0U);
} else {
EXPECT_EQ(events_stack_received_count_, 0U);
EXPECT_EQ(events_priority_received_count_, 0U);
}
}
private: private:
base::test::ScopedTaskEnvironment scoped_task_environment_; base::test::ScopedTaskEnvironment scoped_task_environment_;
...@@ -120,8 +131,11 @@ class TracingSampleProfilerTest : public testing::Test { ...@@ -120,8 +131,11 @@ class TracingSampleProfilerTest : public testing::Test {
base::trace_event::TraceResultBuffer trace_buffer_; base::trace_event::TraceResultBuffer trace_buffer_;
base::trace_event::TraceResultBuffer::SimpleOutput json_output_; base::trace_event::TraceResultBuffer::SimpleOutput json_output_;
// Number of events received. // Number of stack sampling events received.
size_t events_received_count_ = 0; size_t events_stack_received_count_ = 0;
// Number of priority sampling events received.
size_t events_priority_received_count_ = 0;
DISALLOW_COPY_AND_ASSIGN(TracingSampleProfilerTest); DISALLOW_COPY_AND_ASSIGN(TracingSampleProfilerTest);
}; };
...@@ -136,10 +150,7 @@ TEST_F(TracingSampleProfilerTest, OnSampleCompleted) { ...@@ -136,10 +150,7 @@ TEST_F(TracingSampleProfilerTest, OnSampleCompleted) {
WaitForEvents(); WaitForEvents();
EndTracing(); EndTracing();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
if (IsStackUnwindingSupported()) ValidateReceivedEvents();
EXPECT_GT(events_received_count(), 0U);
else
EXPECT_EQ(events_received_count(), 0U);
} }
TEST_F(TracingSampleProfilerTest, JoinRunningTracing) { TEST_F(TracingSampleProfilerTest, JoinRunningTracing) {
...@@ -150,10 +161,7 @@ TEST_F(TracingSampleProfilerTest, JoinRunningTracing) { ...@@ -150,10 +161,7 @@ TEST_F(TracingSampleProfilerTest, JoinRunningTracing) {
WaitForEvents(); WaitForEvents();
EndTracing(); EndTracing();
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
if (IsStackUnwindingSupported()) ValidateReceivedEvents();
EXPECT_GT(events_received_count(), 0U);
else
EXPECT_EQ(events_received_count(), 0U);
} }
TEST_F(TracingSampleProfilerTest, SamplingChildThread) { TEST_F(TracingSampleProfilerTest, SamplingChildThread) {
...@@ -165,10 +173,7 @@ TEST_F(TracingSampleProfilerTest, SamplingChildThread) { ...@@ -165,10 +173,7 @@ TEST_F(TracingSampleProfilerTest, SamplingChildThread) {
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
WaitForEvents(); WaitForEvents();
EndTracing(); EndTracing();
if (IsStackUnwindingSupported()) ValidateReceivedEvents();
EXPECT_GT(events_received_count(), 0U);
else
EXPECT_EQ(events_received_count(), 0U);
} }
} // 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