Commit 766bad50 authored by Patrick Monette's avatar Patrick Monette Committed by Chromium LUCI CQ

[PM] Add ExecutionContextPriorityDecorator

This is a new class that takes care of setting up the voting tree that
decides which priority an execution context will have depending on the
votes of many voters.

Bug: 971272
Change-Id: Id4536e2180d7147357f80b706a8821eb44465145
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2538310Reviewed-by: default avatarChris Hamilton <chrisha@chromium.org>
Commit-Queue: Patrick Monette <pmonette@chromium.org>
Cr-Commit-Position: refs/heads/master@{#833184}
parent 3f73ae0f
......@@ -33,6 +33,8 @@ static_library("performance_manager") {
"execution_context_priority/boosting_vote_aggregator.cc",
"execution_context_priority/boosting_vote_aggregator.h",
"execution_context_priority/execution_context_priority.cc",
"execution_context_priority/execution_context_priority_decorator.cc",
"execution_context_priority/execution_context_priority_decorator.h",
"execution_context_priority/frame_visibility_voter.cc",
"execution_context_priority/frame_visibility_voter.h",
"execution_context_priority/max_vote_aggregator.cc",
......
......@@ -24,6 +24,7 @@ class GraphFeaturesHelper {
// (1) Add a corresponding EnableFeatureFoo() member function.
// (2) Add the feature to EnableDefault() if necessary.
// (3) Add the feature to the implementation of ConfigureGraph().
bool execution_context_priority_decorator : 1;
bool execution_context_registry : 1;
bool frame_node_impl_describer : 1;
bool frame_visibility_decorator : 1;
......@@ -42,6 +43,12 @@ class GraphFeaturesHelper {
constexpr GraphFeaturesHelper(const GraphFeaturesHelper& other) = default;
GraphFeaturesHelper& operator=(const GraphFeaturesHelper& other) = default;
constexpr GraphFeaturesHelper& EnableExecutionContextPriorityDecorator() {
EnableExecutionContextRegistry();
flags_.execution_context_priority_decorator = true;
return *this;
}
constexpr GraphFeaturesHelper& EnableExecutionContextRegistry() {
flags_.execution_context_registry = true;
return *this;
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/performance_manager/execution_context_priority/execution_context_priority_decorator.h"
namespace performance_manager {
namespace execution_context_priority {
ExecutionContextPriorityDecorator::ExecutionContextPriorityDecorator() {
// The following schema describes the structure of the voting tree. Arrows are
// voting channels.
//
// Note: |ad_frame_voter_| is currently the only downvoter but there could
// possibly be more should the need arise. Their votes would be aggregated
// using some sort of MinVoteAggregator.
//
// |root_vote_observer_|
// ^
// |
// |override_vote_aggregator_|
// ^ ^
// | (override) | (default)
// | |
// Downvoter |max_vote_aggregator_|
// ^ ^ ^
// / | \
// / | \
// Voter1, Voter2, ..., VoterN
//
// Set up the voting tree from top to bottom.
override_vote_aggregator_.SetUpstreamVotingChannel(
root_vote_observer_.GetVotingChannel());
max_vote_aggregator_.SetUpstreamVotingChannel(
override_vote_aggregator_.GetDefaultVotingChannel());
// Set up downvoter.
ad_frame_voter_.SetVotingChannel(
override_vote_aggregator_.GetOverrideVotingChannel());
// Set up voters.
frame_visibility_voter_.SetVotingChannel(
max_vote_aggregator_.GetVotingChannel());
}
ExecutionContextPriorityDecorator::~ExecutionContextPriorityDecorator() =
default;
void ExecutionContextPriorityDecorator::OnPassedToGraph(Graph* graph) {
// Subscribe voters to the graph.
graph->AddFrameNodeObserver(&ad_frame_voter_);
graph->AddFrameNodeObserver(&frame_visibility_voter_);
}
void ExecutionContextPriorityDecorator::OnTakenFromGraph(Graph* graph) {
// Unsubscribe voters from the graph.
graph->RemoveFrameNodeObserver(&frame_visibility_voter_);
graph->RemoveFrameNodeObserver(&ad_frame_voter_);
}
} // namespace execution_context_priority
} // namespace performance_manager
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_PERFORMANCE_MANAGER_EXECUTION_CONTEXT_PRIORITY_EXECUTION_CONTEXT_PRIORITY_DECORATOR_H_
#define COMPONENTS_PERFORMANCE_MANAGER_EXECUTION_CONTEXT_PRIORITY_EXECUTION_CONTEXT_PRIORITY_DECORATOR_H_
#include "components/performance_manager/execution_context_priority/ad_frame_voter.h"
#include "components/performance_manager/execution_context_priority/frame_visibility_voter.h"
#include "components/performance_manager/execution_context_priority/max_vote_aggregator.h"
#include "components/performance_manager/execution_context_priority/override_vote_aggregator.h"
#include "components/performance_manager/execution_context_priority/root_vote_observer.h"
#include "components/performance_manager/public/graph/graph.h"
namespace performance_manager {
namespace execution_context_priority {
// The ExecutionContextPriorityDecorator's responsibility is to own the voting
// system that assigns the priority of every frame and worker in the graph.
//
// See the README.md for more details on the voting system.
class ExecutionContextPriorityDecorator final : public GraphOwned {
public:
ExecutionContextPriorityDecorator();
~ExecutionContextPriorityDecorator() override;
ExecutionContextPriorityDecorator(const ExecutionContextPriorityDecorator&) =
delete;
ExecutionContextPriorityDecorator& operator=(
const ExecutionContextPriorityDecorator&) = delete;
private:
void OnPassedToGraph(Graph* graph) override;
void OnTakenFromGraph(Graph* graph) override;
// Takes in the aggregated votes and applies them to the execution contexts in
// the graph.
RootVoteObserver root_vote_observer_;
// Used to cast a negative vote that overrides the vote from
// |max_vote_aggregator_|.
OverrideVoteAggregator override_vote_aggregator_;
// Aggregates all the votes from the voters.
MaxVoteAggregator max_vote_aggregator_;
// Note: Voters should be added below this line so that they are destroyed
// before the aggregators.
// Casts a downvote for ad frames.
AdFrameVoter ad_frame_voter_;
// Casts a USER_VISIBLE vote when a frame is visible.
FrameVisibilityVoter frame_visibility_voter_;
};
} // namespace execution_context_priority
} // namespace performance_manager
#endif // COMPONENTS_PERFORMANCE_MANAGER_EXECUTION_CONTEXT_PRIORITY_EXECUTION_CONTEXT_PRIORITY_DECORATOR_H_
......@@ -10,6 +10,7 @@
#include "components/performance_manager/decorators/frame_visibility_decorator.h"
#include "components/performance_manager/decorators/page_load_tracker_decorator.h"
#include "components/performance_manager/execution_context/execution_context_registry_impl.h"
#include "components/performance_manager/execution_context_priority/execution_context_priority_decorator.h"
#include "components/performance_manager/graph/frame_node_impl_describer.h"
#include "components/performance_manager/graph/page_node_impl_describer.h"
#include "components/performance_manager/graph/process_node_impl_describer.h"
......@@ -59,10 +60,14 @@ void GraphFeaturesHelper::ConfigureGraph(Graph* graph) const {
Install<SiteDataRecorder>(graph);
#endif
// This class has a dependency on ExecutionContextRegistry, so must be
// These classes have a dependency on ExecutionContextRegistry, so must be
// installed after it.
if (flags_.execution_context_priority_decorator) {
Install<execution_context_priority::ExecutionContextPriorityDecorator>(
graph);
}
if (flags_.v8_context_tracker)
Install<v8_memory::V8ContextTracker>(graph);
}
} // namespace performance_manager
\ No newline at end of file
} // namespace performance_manager
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