Commit 216b0aaa authored by Dan Elphick's avatar Dan Elphick Committed by Commit Bot

[scheduler] Convert RAILMode tracing to perfetto

Emit Scheduler.RAILMode as a proto
(ChromeRendererSchedulerState.ChromeRAILMode) added in:
https://android-review.googlesource.com/c/platform/external/perfetto/+/1454655

Also updates services/tracing/perfetto/privacy_filtered_fields-inl.h so
the new fields are not filtered out.

Change-Id: I610648e87b017237e261478163b34757605c166b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2466244
Commit-Queue: Dan Elphick <delphick@chromium.org>
Reviewed-by: default avatarSami Kyöstilä <skyostil@chromium.org>
Cr-Commit-Position: refs/heads/master@{#818472}
parent f3394bc4
......@@ -175,10 +175,15 @@ constexpr int kChromeMojoEventInfoIndices[] = {1, -1};
constexpr MessageInfo kChromeMojoEventInfo = {kChromeMojoEventInfoIndices,
nullptr};
// Proto Message: ChromeRendererSchedulerState
constexpr int kChromeRendererSchedulerStateIndices[] = {1, -1};
constexpr MessageInfo kChromeRendererSchedulerState = {
kChromeRendererSchedulerStateIndices, nullptr};
// Proto Message: TrackEvent
constexpr int kTrackEventIndices[] = {1, 2, 3, 5, 6, 9, 10, 11, 12,
16, 17, 24, 25, 26, 27, 28, 29, 30,
31, 32, 33, 34, 35, 38, -1};
31, 32, 33, 34, 35, 38, 40, -1};
constexpr MessageInfo const* kTrackEventComplexMessages[] = {
nullptr,
nullptr,
......@@ -203,7 +208,8 @@ constexpr MessageInfo const* kTrackEventComplexMessages[] = {
&kSourceLocation,
nullptr,
&kChromeMessagePump,
&kChromeMojoEventInfo};
&kChromeMojoEventInfo,
&kChromeRendererSchedulerState};
constexpr MessageInfo kTrackEvent = {kTrackEventIndices,
kTrackEventComplexMessages};
......
......@@ -12,9 +12,13 @@
#include "base/macros.h"
#include "base/time/time.h"
#include "base/trace_event/trace_event.h"
#include "base/trace_event/typed_macros.h"
#include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
#include "third_party/blink/renderer/platform/wtf/text/wtf_string.h"
#include "third_party/perfetto/include/perfetto/tracing/event_context.h"
#include "third_party/perfetto/include/perfetto/tracing/track.h"
#include "third_party/perfetto/protos/perfetto/trace/track_event/track_event.pbzero.h"
namespace blink {
namespace scheduler {
......@@ -216,6 +220,126 @@ class TraceableState : public TraceableVariable, private StateTracer<category> {
DISALLOW_COPY(TraceableState);
};
template <const char* category, typename TypedValue>
class ProtoStateTracer {
DISALLOW_NEW();
public:
explicit ProtoStateTracer(const char* name)
: name_(name), slice_is_open_(false) {
internal::ValidateTracingCategory(category);
}
ProtoStateTracer(const ProtoStateTracer&) = delete;
ProtoStateTracer& operator=(const ProtoStateTracer&) = delete;
~ProtoStateTracer() {
if (slice_is_open_) {
TRACE_EVENT_END(category, track());
}
}
void TraceProto(TypedValue* value) {
const auto trace_track = track();
if (slice_is_open_) {
TRACE_EVENT_END(category, trace_track);
slice_is_open_ = false;
}
if (!is_enabled())
return;
TRACE_EVENT_BEGIN(category, name_, trace_track,
[value](perfetto::EventContext ctx) {
value->AsProtozeroInto(ctx.event());
});
slice_is_open_ = true;
}
protected:
bool is_enabled() const {
bool result = false;
TRACE_EVENT_CATEGORY_GROUP_ENABLED(category, &result); // Cached.
return result;
}
private:
perfetto::Track track() const {
return perfetto::Track(reinterpret_cast<uint64_t>(this));
}
const char* const name_; // Not owned.
// We have to track whether slice is open to avoid confusion since assignment,
// "absent" state and OnTraceLogEnabled can happen anytime.
bool slice_is_open_;
};
template <typename T>
using InitializeProtoFuncPtr =
void (*)(perfetto::protos::pbzero::TrackEvent* event, T e);
template <typename T, const char* category>
class TraceableObjectState
: public TraceableVariable,
public ProtoStateTracer<category, TraceableObjectState<T, category>> {
public:
TraceableObjectState(T initial_state,
const char* name,
TraceableVariableController* controller,
InitializeProtoFuncPtr<T> proto_init_func)
: TraceableVariable(controller),
ProtoStateTracer<category, TraceableObjectState<T, category>>(name),
state_(initial_state),
proto_init_func_(proto_init_func) {
Trace();
}
TraceableObjectState(const TraceableObjectState&) = delete;
~TraceableObjectState() override = default;
TraceableObjectState& operator=(const T& value) {
Assign(value);
return *this;
}
TraceableObjectState& operator=(const TraceableObjectState& another) {
Assign(another.state_);
return *this;
}
const T& get() const { return state_; }
void OnTraceLogEnabled() final { Trace(); }
void AsProtozeroInto(perfetto::protos::pbzero::TrackEvent* event) {
proto_init_func_(event, state_);
}
protected:
void Assign(T new_state) {
if (state_ != new_state) {
state_ = new_state;
Trace();
}
}
private:
void Trace() {
ProtoStateTracer<category, TraceableObjectState<T, category>>::TraceProto(
this);
}
bool is_enabled() const {
bool result = false;
TRACE_EVENT_CATEGORY_GROUP_ENABLED(category, &result); // Cached.
return result;
}
T state_;
InitializeProtoFuncPtr<T> proto_init_func_;
};
template <typename T, const char* category>
class TraceableCounter : public TraceableVariable {
public:
......
......@@ -47,6 +47,8 @@
#include "third_party/blink/renderer/platform/scheduler/main_thread/widget_scheduler.h"
#include "third_party/blink/renderer/platform/scheduler/public/event_loop.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
#include "third_party/perfetto/protos/perfetto/trace/track_event/chrome_renderer_scheduler_state.pbzero.h"
#include "third_party/perfetto/protos/perfetto/trace/track_event/track_event.pbzero.h"
#include "v8/include/v8.h"
namespace blink {
......@@ -84,6 +86,30 @@ v8::RAILMode RAILModeToV8RAILMode(RAILMode rail_mode) {
}
}
void AddRAILModeToProto(perfetto::protos::pbzero::TrackEvent* event,
RAILMode mode) {
perfetto::protos::pbzero::ChromeRAILMode proto_mode;
switch (mode) {
case RAILMode::kResponse:
proto_mode = perfetto::protos::pbzero::ChromeRAILMode::RAIL_MODE_RESPONSE;
break;
case RAILMode::kAnimation:
proto_mode =
perfetto::protos::pbzero::ChromeRAILMode::RAIL_MODE_ANIMATION;
break;
case RAILMode::kIdle:
proto_mode = perfetto::protos::pbzero::ChromeRAILMode::RAIL_MODE_IDLE;
break;
case RAILMode::kLoad:
proto_mode = perfetto::protos::pbzero::ChromeRAILMode::RAIL_MODE_LOAD;
break;
default:
proto_mode = perfetto::protos::pbzero::ChromeRAILMode::RAIL_MODE_NONE;
break;
}
event->set_chrome_renderer_scheduler_state()->set_rail_mode(proto_mode);
}
const char* BackgroundStateToString(bool is_backgrounded) {
if (is_backgrounded) {
return "renderer_backgrounded";
......@@ -362,7 +388,7 @@ MainThreadSchedulerImpl::MainThreadOnly::MainThreadOnly(
rail_mode_for_tracing(current_policy.rail_mode(),
"Scheduler.RAILMode",
&main_thread_scheduler_impl->tracing_controller_,
RAILModeToString),
&AddRAILModeToProto),
renderer_hidden(false,
"RendererVisibility",
&main_thread_scheduler_impl->tracing_controller_,
......
......@@ -853,8 +853,11 @@ class PLATFORM_EXPORT MainThreadSchedulerImpl
longest_jank_free_task_duration;
TraceableCounter<int, TracingCategoryName::kInfo>
renderer_pause_count; // Renderer is paused if non-zero.
TraceableState<RAILMode, TracingCategoryName::kTopLevel>
TraceableObjectState<RAILMode,
TracingCategoryName::kTopLevel>
rail_mode_for_tracing; // Don't use except for tracing.
TraceableState<bool, TracingCategoryName::kTopLevel> renderer_hidden;
base::Optional<base::ScopedSampleMetadata> renderer_hidden_metadata;
TraceableState<bool, TracingCategoryName::kTopLevel> renderer_backgrounded;
......
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