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 @@
#include "base/format_macros.h"
#include "base/memory/ptr_util.h"
#include "base/no_destructor.h"
#include "base/process/process.h"
#include "base/profiler/stack_sampling_profiler.h"
#include "base/strings/stringprintf.h"
#include "base/threading/sequence_local_storage_slot.h"
......@@ -43,6 +44,11 @@ class TracingProfileBuilder
void OnSampleCompleted(
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()) {
TRACE_EVENT_INSTANT2(TRACE_DISABLED_BY_DEFAULT("cpu_profiler"),
"StackCpuSampling", TRACE_EVENT_SCOPE_THREAD,
......
......@@ -54,8 +54,6 @@ class TracingSampleProfilerTest : public testing::Test {
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
// on this platform.
bool IsStackUnwindingSupported() {
......@@ -106,10 +104,23 @@ class TracingSampleProfilerTest : public testing::Test {
CHECK(item->GetAsDictionary(&dict));
std::string name;
CHECK(dict->GetString("name", &name));
if (name == "StackCpuSampling")
events_received_count_++;
if (name == "StackCpuSampling") {
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:
......@@ -120,8 +131,11 @@ class TracingSampleProfilerTest : public testing::Test {
base::trace_event::TraceResultBuffer trace_buffer_;
base::trace_event::TraceResultBuffer::SimpleOutput json_output_;
// Number of events received.
size_t events_received_count_ = 0;
// Number of stack sampling events received.
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);
};
......@@ -136,10 +150,7 @@ TEST_F(TracingSampleProfilerTest, OnSampleCompleted) {
WaitForEvents();
EndTracing();
base::RunLoop().RunUntilIdle();
if (IsStackUnwindingSupported())
EXPECT_GT(events_received_count(), 0U);
else
EXPECT_EQ(events_received_count(), 0U);
ValidateReceivedEvents();
}
TEST_F(TracingSampleProfilerTest, JoinRunningTracing) {
......@@ -150,10 +161,7 @@ TEST_F(TracingSampleProfilerTest, JoinRunningTracing) {
WaitForEvents();
EndTracing();
base::RunLoop().RunUntilIdle();
if (IsStackUnwindingSupported())
EXPECT_GT(events_received_count(), 0U);
else
EXPECT_EQ(events_received_count(), 0U);
ValidateReceivedEvents();
}
TEST_F(TracingSampleProfilerTest, SamplingChildThread) {
......@@ -165,10 +173,7 @@ TEST_F(TracingSampleProfilerTest, SamplingChildThread) {
base::RunLoop().RunUntilIdle();
WaitForEvents();
EndTracing();
if (IsStackUnwindingSupported())
EXPECT_GT(events_received_count(), 0U);
else
EXPECT_EQ(events_received_count(), 0U);
ValidateReceivedEvents();
}
} // 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