Commit ecec4f7d authored by Sigurdur Asgeirsson's avatar Sigurdur Asgeirsson Committed by Commit Bot

PM: Parametrize initialization of PerformanceManagerImpl.

This breaks up some of the dependencies in preparation for a move
to //components.

Bug: 953031
Change-Id: I7955635a348d051c73178536caa8bd31b840645c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1835199
Commit-Queue: Sigurður Ásgeirsson <siggi@chromium.org>
Reviewed-by: default avatarChris Hamilton <chrisha@chromium.org>
Cr-Commit-Position: refs/heads/master@{#702057}
parent 5a74ea62
......@@ -6,10 +6,31 @@
#include <utility>
#include "base/bind.h"
#include "base/feature_list.h"
#include "build/build_config.h"
#include "chrome/browser/performance_manager/browser_child_process_watcher.h"
#include "chrome/browser/performance_manager/decorators/freeze_origin_trial_policy_aggregator.h"
#include "chrome/browser/performance_manager/decorators/frozen_frame_aggregator.h"
#include "chrome/browser/performance_manager/decorators/page_almost_idle_decorator.h"
#include "chrome/browser/performance_manager/decorators/process_metrics_decorator.h"
#include "chrome/browser/performance_manager/graph/graph_impl.h"
#include "chrome/browser/performance_manager/graph/policies/policy_features.h"
#include "chrome/browser/performance_manager/graph/policies/working_set_trimmer_policy.h"
#include "chrome/browser/performance_manager/observers/isolation_context_metrics.h"
#include "chrome/browser/performance_manager/observers/metrics_collector.h"
#include "chrome/browser/performance_manager/performance_manager_impl.h"
#include "chrome/browser/performance_manager/performance_manager_tab_helper.h"
#include "chrome/browser/performance_manager/render_process_user_data.h"
#include "content/public/common/content_features.h"
#if defined(OS_LINUX)
#include "base/allocator/buildflags.h"
#if BUILDFLAG(USE_TCMALLOC)
#include "chrome/browser/performance_manager/graph/policies/dynamic_tcmalloc_policy_linux.h"
#include "chrome/common/performance_manager/mojom/tcmalloc.mojom.h"
#endif // BUILDFLAG(USE_TCMALLOC)
#endif // defined(OS_LINUX)
ChromeBrowserMainExtraPartsPerformanceManager::
ChromeBrowserMainExtraPartsPerformanceManager() = default;
......@@ -17,7 +38,9 @@ ChromeBrowserMainExtraPartsPerformanceManager::
~ChromeBrowserMainExtraPartsPerformanceManager() = default;
void ChromeBrowserMainExtraPartsPerformanceManager::PostCreateThreads() {
performance_manager_ = performance_manager::PerformanceManagerImpl::Create();
performance_manager_ = performance_manager::PerformanceManagerImpl::Create(
base::BindOnce(&ChromeBrowserMainExtraPartsPerformanceManager::
CreateDefaultPoliciesAndDecorators));
browser_child_process_watcher_ =
std::make_unique<performance_manager::BrowserChildProcessWatcher>();
browser_child_process_watcher_->Initialize();
......@@ -42,3 +65,35 @@ void ChromeBrowserMainExtraPartsPerformanceManager::PostMainMessageLoopRun() {
performance_manager::PerformanceManagerImpl::Destroy(
std::move(performance_manager_));
}
// static
void ChromeBrowserMainExtraPartsPerformanceManager::
CreateDefaultPoliciesAndDecorators(performance_manager::GraphImpl* graph) {
graph->PassToGraph(std::make_unique<
performance_manager::FreezeOriginTrialPolicyAggregator>());
graph->PassToGraph(
std::make_unique<performance_manager::FrozenFrameAggregator>());
graph->PassToGraph(
std::make_unique<performance_manager::PageAlmostIdleDecorator>());
graph->PassToGraph(
std::make_unique<performance_manager::IsolationContextMetrics>());
graph->PassToGraph(std::make_unique<performance_manager::MetricsCollector>());
graph->PassToGraph(
std::make_unique<performance_manager::ProcessMetricsDecorator>());
if (performance_manager::policies::WorkingSetTrimmerPolicy::
PlatformSupportsWorkingSetTrim()) {
graph->PassToGraph(performance_manager::policies::WorkingSetTrimmerPolicy::
CreatePolicyForPlatform());
}
#if defined(OS_LINUX)
#if BUILDFLAG(USE_TCMALLOC)
if (base::FeatureList::IsEnabled(
performance_manager::features::kDynamicTcmallocTuning)) {
graph->PassToGraph(std::make_unique<
performance_manager::policies::DynamicTcmallocPolicy>());
}
#endif // BUILDFLAG(USE_TCMALLOC)
#endif // defined(OS_LINUX)
}
......@@ -13,6 +13,7 @@
namespace performance_manager {
class BrowserChildProcessWatcher;
class GraphImpl;
class PerformanceManagerImpl;
} // namespace performance_manager
......@@ -22,6 +23,9 @@ class ChromeBrowserMainExtraPartsPerformanceManager
ChromeBrowserMainExtraPartsPerformanceManager();
~ChromeBrowserMainExtraPartsPerformanceManager() override;
static void CreateDefaultPoliciesAndDecorators(
performance_manager::GraphImpl* graph);
private:
// ChromeBrowserMainExtraParts overrides.
void PostCreateThreads() override;
......
......@@ -9,35 +9,16 @@
#include <utility>
#include "base/containers/flat_set.h"
#include "base/feature_list.h"
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/task/post_task.h"
#include "base/task/task_traits.h"
#include "build/build_config.h"
#include "chrome/browser/performance_manager/decorators/freeze_origin_trial_policy_aggregator.h"
#include "chrome/browser/performance_manager/decorators/frozen_frame_aggregator.h"
#include "chrome/browser/performance_manager/decorators/page_almost_idle_decorator.h"
#include "chrome/browser/performance_manager/decorators/process_metrics_decorator.h"
#include "chrome/browser/performance_manager/graph/frame_node_impl.h"
#include "chrome/browser/performance_manager/graph/page_node_impl.h"
#include "chrome/browser/performance_manager/graph/policies/policy_features.h"
#include "chrome/browser/performance_manager/graph/policies/working_set_trimmer_policy.h"
#include "chrome/browser/performance_manager/graph/process_node_impl.h"
#include "chrome/browser/performance_manager/graph/system_node_impl.h"
#include "chrome/browser/performance_manager/graph/worker_node_impl.h"
#include "chrome/browser/performance_manager/observers/isolation_context_metrics.h"
#include "chrome/browser/performance_manager/observers/metrics_collector.h"
#include "content/public/common/content_features.h"
#if defined(OS_LINUX)
#include "base/allocator/buildflags.h"
#if BUILDFLAG(USE_TCMALLOC)
#include "chrome/browser/performance_manager/graph/policies/dynamic_tcmalloc_policy_linux.h"
#include "chrome/common/performance_manager/mojom/tcmalloc.mojom.h"
#endif // BUILDFLAG(USE_TCMALLOC)
#endif // defined(OS_LINUX)
namespace performance_manager {
......@@ -106,11 +87,16 @@ PerformanceManagerImpl* PerformanceManagerImpl::GetInstance() {
}
// static
std::unique_ptr<PerformanceManagerImpl> PerformanceManagerImpl::Create() {
std::unique_ptr<PerformanceManagerImpl> PerformanceManagerImpl::Create(
GraphImplCallback on_start) {
std::unique_ptr<PerformanceManagerImpl> instance =
base::WrapUnique(new PerformanceManagerImpl());
instance->OnStart();
instance->task_runner()->PostTask(
FROM_HERE,
base::BindOnce(&PerformanceManagerImpl::OnStartImpl,
base::Unretained(instance.get()), std::move(on_start)));
g_performance_manager.Set(instance.get());
return instance;
......@@ -291,12 +277,6 @@ void PerformanceManagerImpl::BatchDeleteNodesImpl(
// When |nodes| goes out of scope, all nodes are deleted.
}
void PerformanceManagerImpl::OnStart() {
task_runner_->PostTask(FROM_HERE,
base::BindOnce(&PerformanceManagerImpl::OnStartImpl,
base::Unretained(this)));
}
void PerformanceManagerImpl::RunCallbackWithGraphImpl(
GraphImplCallback graph_callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
......@@ -311,30 +291,11 @@ void PerformanceManagerImpl::RunCallbackWithGraph(
std::move(graph_callback).Run(&graph_);
}
void PerformanceManagerImpl::OnStartImpl() {
void PerformanceManagerImpl::OnStartImpl(GraphImplCallback on_start) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
graph_.PassToGraph(std::make_unique<FreezeOriginTrialPolicyAggregator>());
graph_.PassToGraph(std::make_unique<FrozenFrameAggregator>());
graph_.PassToGraph(std::make_unique<PageAlmostIdleDecorator>());
graph_.PassToGraph(std::make_unique<IsolationContextMetrics>());
graph_.PassToGraph(std::make_unique<MetricsCollector>());
graph_.PassToGraph(std::make_unique<ProcessMetricsDecorator>());
if (policies::WorkingSetTrimmerPolicy::PlatformSupportsWorkingSetTrim()) {
graph_.PassToGraph(
policies::WorkingSetTrimmerPolicy::CreatePolicyForPlatform());
}
#if defined(OS_LINUX)
#if BUILDFLAG(USE_TCMALLOC)
if (base::FeatureList::IsEnabled(features::kDynamicTcmallocTuning)) {
graph_.PassToGraph(std::make_unique<policies::DynamicTcmallocPolicy>());
}
#endif // BUILDFLAG(USE_TCMALLOC)
#endif // defined(OS_LINUX)
graph_.set_ukm_recorder(ukm::UkmRecorder::Get());
std::move(on_start).Run(&graph_);
}
} // namespace performance_manager
......@@ -63,7 +63,9 @@ class PerformanceManagerImpl : public PerformanceManager {
static PerformanceManagerImpl* GetInstance();
// Creates, initializes and registers an instance.
static std::unique_ptr<PerformanceManagerImpl> Create();
// Invokes |on_start| on the PM sequence.
static std::unique_ptr<PerformanceManagerImpl> Create(
GraphImplCallback on_start);
// Unregisters |instance| if it's currently registered and arranges for its
// deletion on its sequence.
......@@ -140,8 +142,7 @@ class PerformanceManagerImpl : public PerformanceManager {
void DeleteNodeImpl(std::unique_ptr<NodeBase> node);
void BatchDeleteNodesImpl(std::vector<std::unique_ptr<NodeBase>> nodes);
void OnStart();
void OnStartImpl();
void OnStartImpl(GraphImplCallback graph_callback);
void RunCallbackWithGraphImpl(GraphImplCallback graph_callback);
void RunCallbackWithGraph(GraphCallback graph_callback);
......
......@@ -6,6 +6,7 @@
#include <utility>
#include "base/bind_helpers.h"
#include "base/callback.h"
#include "base/run_loop.h"
#include "base/test/bind_test_util.h"
......@@ -26,7 +27,7 @@ class PerformanceManagerTest : public testing::Test {
void SetUp() override {
EXPECT_EQ(nullptr, PerformanceManagerImpl::GetInstance());
performance_manager_ = PerformanceManagerImpl::Create();
performance_manager_ = PerformanceManagerImpl::Create(base::DoNothing());
// Make sure creation registers the created instance.
EXPECT_EQ(performance_manager_.get(),
PerformanceManagerImpl::GetInstance());
......
......@@ -4,6 +4,7 @@
#include "chrome/browser/performance_manager/performance_manager_test_harness.h"
#include "base/bind_helpers.h"
#include "chrome/browser/performance_manager/performance_manager_tab_helper.h"
namespace performance_manager {
......@@ -14,7 +15,7 @@ PerformanceManagerTestHarness::~PerformanceManagerTestHarness() = default;
void PerformanceManagerTestHarness::SetUp() {
Super::SetUp();
perf_man_ = PerformanceManagerImpl::Create();
perf_man_ = PerformanceManagerImpl::Create(base::DoNothing());
}
void PerformanceManagerTestHarness::TearDown() {
......
......@@ -3,6 +3,7 @@
// found in the LICENSE file.
#include "chrome/browser/performance_manager/persistence/site_data/unittest_utils.h"
#include "base/bind_helpers.h"
#include "base/callback.h"
#include <utility>
......@@ -48,7 +49,7 @@ TestWithPerformanceManager::~TestWithPerformanceManager() = default;
void TestWithPerformanceManager::SetUp() {
EXPECT_EQ(nullptr, PerformanceManagerImpl::GetInstance());
performance_manager_ = PerformanceManagerImpl::Create();
performance_manager_ = PerformanceManagerImpl::Create(base::DoNothing());
// Make sure creation registers the created instance.
EXPECT_EQ(performance_manager_.get(), PerformanceManagerImpl::GetInstance());
}
......
......@@ -6,6 +6,7 @@
#include <utility>
#include "base/bind_helpers.h"
#include "base/task/post_task.h"
#include "chrome/browser/performance_manager/performance_manager_impl.h"
#include "chrome/browser/resource_coordinator/local_site_characteristics_data_store_factory.h"
......@@ -104,7 +105,8 @@ void ChromeTestHarnessWithLocalDB::SetUp() {
// ChromeRenderViewHostTestHarness::SetUp(), this will prevent the creation
// of a non-mock version of a data store when browser_context() gets
// initialized.
performance_manager_ = performance_manager::PerformanceManagerImpl::Create();
performance_manager_ =
performance_manager::PerformanceManagerImpl::Create(base::DoNothing());
LocalSiteCharacteristicsDataStoreFactory::EnableForTesting();
......
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