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

RC: Fire OnProcessCPUUsageReady after a CPU measurement cycle.

Also rearrange method order a little and rename HandleMetrics to
DispatchMetrics, as there's no need to pass the metrics map to the
method.

R=chrisha@chromium.org

Bug: 755840
Change-Id: If316817f540315bf8c0465d1d32be60734183db6
Reviewed-on: https://chromium-review.googlesource.com/1019563Reviewed-by: default avatarChris Hamilton <chrisha@chromium.org>
Commit-Queue: Sigurður Ásgeirsson <siggi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#553066}
parent ba97da2d
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "content/public/common/service_manager_connection.h" #include "content/public/common/service_manager_connection.h"
#include "services/resource_coordinator/public/cpp/process_resource_coordinator.h" #include "services/resource_coordinator/public/cpp/process_resource_coordinator.h"
#include "services/resource_coordinator/public/cpp/resource_coordinator_features.h" #include "services/resource_coordinator/public/cpp/resource_coordinator_features.h"
#include "services/resource_coordinator/public/cpp/system_resource_coordinator.h"
#include "services/resource_coordinator/public/mojom/coordination_unit.mojom.h" #include "services/resource_coordinator/public/mojom/coordination_unit.mojom.h"
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
...@@ -150,33 +151,13 @@ void ResourceCoordinatorRenderProcessProbe:: ...@@ -150,33 +151,13 @@ void ResourceCoordinatorRenderProcessProbe::
DCHECK(is_gathering_); DCHECK(is_gathering_);
is_gathering_ = false; is_gathering_ = false;
if (HandleMetrics(render_process_info_map_)) { if (DispatchMetrics()) {
timer_.Start(FROM_HERE, interval_, this, timer_.Start(FROM_HERE, interval_, this,
&ResourceCoordinatorRenderProcessProbe:: &ResourceCoordinatorRenderProcessProbe::
RegisterAliveRenderProcessesOnUIThread); RegisterAliveRenderProcessesOnUIThread);
} }
} }
bool ResourceCoordinatorRenderProcessProbe::HandleMetrics(
const RenderProcessInfoMap& render_process_info_map) {
for (auto& render_process_info_map_entry : render_process_info_map) {
auto& render_process_info = render_process_info_map_entry.second;
// TODO(oysteine): Move the multiplier used to avoid precision loss
// into a shared location, when this property gets used.
// Note that the RPH may have been deleted while the CPU metrics were
// acquired on a blocking thread.
content::RenderProcessHost* host = content::RenderProcessHost::FromID(
render_process_info.render_process_host_id);
if (host) {
host->GetProcessResourceCoordinator()->SetCPUUsage(
render_process_info.cpu_usage);
}
}
return true;
}
void ResourceCoordinatorRenderProcessProbe::UpdateWithFieldTrialParams() { void ResourceCoordinatorRenderProcessProbe::UpdateWithFieldTrialParams() {
int64_t interval_ms = GetGRCRenderProcessCPUProfilingIntervalInMs(); int64_t interval_ms = GetGRCRenderProcessCPUProfilingIntervalInMs();
...@@ -185,4 +166,48 @@ void ResourceCoordinatorRenderProcessProbe::UpdateWithFieldTrialParams() { ...@@ -185,4 +166,48 @@ void ResourceCoordinatorRenderProcessProbe::UpdateWithFieldTrialParams() {
} }
} }
SystemResourceCoordinator*
ResourceCoordinatorRenderProcessProbe::EnsureSystemResourceCoordinator() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (!system_resource_coordinator_) {
content::ServiceManagerConnection* connection =
content::ServiceManagerConnection::GetForProcess();
if (connection)
system_resource_coordinator_ =
std::make_unique<SystemResourceCoordinator>(
connection->GetConnector());
}
return system_resource_coordinator_.get();
}
bool ResourceCoordinatorRenderProcessProbe::DispatchMetrics() {
SystemResourceCoordinator* system_resource_coordinator =
EnsureSystemResourceCoordinator();
if (system_resource_coordinator) {
bool dispatched_measurement = false;
for (auto& render_process_info_map_entry : render_process_info_map_) {
auto& render_process_info = render_process_info_map_entry.second;
// TODO(oysteine): Move the multiplier used to avoid precision loss
// into a shared location, when this property gets used.
// Note that the RPH may have been deleted while the CPU metrics were
// acquired on a blocking thread.
content::RenderProcessHost* host = content::RenderProcessHost::FromID(
render_process_info.render_process_host_id);
if (host) {
dispatched_measurement = true;
host->GetProcessResourceCoordinator()->SetCPUUsage(
render_process_info.cpu_usage);
}
}
if (dispatched_measurement)
system_resource_coordinator->OnProcessCPUUsageReady();
}
return true;
}
} // namespace resource_coordinator } // namespace resource_coordinator
...@@ -17,6 +17,8 @@ ...@@ -17,6 +17,8 @@
namespace resource_coordinator { namespace resource_coordinator {
class SystemResourceCoordinator;
struct RenderProcessInfo { struct RenderProcessInfo {
RenderProcessInfo(); RenderProcessInfo();
~RenderProcessInfo(); ~RenderProcessInfo();
...@@ -68,13 +70,17 @@ class ResourceCoordinatorRenderProcessProbe { ...@@ -68,13 +70,17 @@ class ResourceCoordinatorRenderProcessProbe {
// consists of a delayed call to perform (1) via a timer. // consists of a delayed call to perform (1) via a timer.
void HandleRenderProcessMetricsOnUIThread(); void HandleRenderProcessMetricsOnUIThread();
// Handle collected metrics. Returns |true| another metrics collection gather // Allows FieldTrial parameters to override defaults.
// cycle should be initiated. Virtual for testing. void UpdateWithFieldTrialParams();
SystemResourceCoordinator* EnsureSystemResourceCoordinator();
// Dispatch the collected metrics. Returns |true| if another metrics
// collection gather cycle should be initiated. Virtual for testing.
// Default implementation sends collected metrics back to the resource // Default implementation sends collected metrics back to the resource
// coordinator service and initiates another render process metrics gather // coordinator service and initiates another render process metrics gather
// cycle. // cycle.
virtual bool HandleMetrics( virtual bool DispatchMetrics();
const RenderProcessInfoMap& render_process_info_map);
// A map of currently running render process host IDs to Process. // A map of currently running render process host IDs to Process.
RenderProcessInfoMap render_process_info_map_; RenderProcessInfoMap render_process_info_map_;
...@@ -92,8 +98,8 @@ class ResourceCoordinatorRenderProcessProbe { ...@@ -92,8 +98,8 @@ class ResourceCoordinatorRenderProcessProbe {
// True while a gathering cycle is underways on a background thread. // True while a gathering cycle is underways on a background thread.
bool is_gathering_ = false; bool is_gathering_ = false;
// Allows FieldTrial parameters to override defaults. // Used to signal the end of a CPU measurement cycle to the RC.
void UpdateWithFieldTrialParams(); std::unique_ptr<SystemResourceCoordinator> system_resource_coordinator_;
DISALLOW_COPY_AND_ASSIGN(ResourceCoordinatorRenderProcessProbe); DISALLOW_COPY_AND_ASSIGN(ResourceCoordinatorRenderProcessProbe);
}; };
......
...@@ -30,8 +30,7 @@ class TestingResourceCoordinatorRenderProcessProbe ...@@ -30,8 +30,7 @@ class TestingResourceCoordinatorRenderProcessProbe
TestingResourceCoordinatorRenderProcessProbe() = default; TestingResourceCoordinatorRenderProcessProbe() = default;
~TestingResourceCoordinatorRenderProcessProbe() override = default; ~TestingResourceCoordinatorRenderProcessProbe() override = default;
bool HandleMetrics( bool DispatchMetrics() override {
const RenderProcessInfoMap& render_process_info_map) override {
current_run_loop_->QuitWhenIdle(); current_run_loop_->QuitWhenIdle();
return false; return false;
} }
......
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