Commit 02991ba7 authored by Sigurdur Asgeirsson's avatar Sigurdur Asgeirsson Committed by Commit Bot

RC: Add a StartSingleGather method on the render process probe.

Bug: 755840
Change-Id: Ib992197eb21d4705e8911c9ded73dfa7197b329d
Reviewed-on: https://chromium-review.googlesource.com/1024499
Commit-Queue: Sigurður Ásgeirsson <siggi@chromium.org>
Reviewed-by: default avatarChris Hamilton <chrisha@chromium.org>
Cr-Commit-Position: refs/heads/master@{#553101}
parent bc529d6c
...@@ -62,10 +62,30 @@ bool ResourceCoordinatorRenderProcessProbe::IsEnabled() { ...@@ -62,10 +62,30 @@ bool ResourceCoordinatorRenderProcessProbe::IsEnabled() {
void ResourceCoordinatorRenderProcessProbe::StartGatherCycle() { void ResourceCoordinatorRenderProcessProbe::StartGatherCycle() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
// TODO(siggi): It irks me to have this bit of policy embedded here.
// I feel this should be moved to the caller...
if (!ResourceCoordinatorRenderProcessProbe::IsEnabled()) { if (!ResourceCoordinatorRenderProcessProbe::IsEnabled()) {
return; return;
} }
DCHECK(!is_gather_cycle_started_);
is_gather_cycle_started_ = true;
if (!is_gathering_) {
timer_.Start(FROM_HERE, base::TimeDelta(), this,
&ResourceCoordinatorRenderProcessProbe::
RegisterAliveRenderProcessesOnUIThread);
}
}
void ResourceCoordinatorRenderProcessProbe::StartSingleGather() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
if (is_gathering_)
return;
// If the gather cycle is started this measurement will go through early,
// and the interval between measurements will be shortened.
timer_.Start(FROM_HERE, base::TimeDelta(), this, timer_.Start(FROM_HERE, base::TimeDelta(), this,
&ResourceCoordinatorRenderProcessProbe:: &ResourceCoordinatorRenderProcessProbe::
RegisterAliveRenderProcessesOnUIThread); RegisterAliveRenderProcessesOnUIThread);
...@@ -151,10 +171,12 @@ void ResourceCoordinatorRenderProcessProbe:: ...@@ -151,10 +171,12 @@ void ResourceCoordinatorRenderProcessProbe::
DCHECK(is_gathering_); DCHECK(is_gathering_);
is_gathering_ = false; is_gathering_ = false;
if (DispatchMetrics()) { if (DispatchMetrics() && is_gather_cycle_started_) {
timer_.Start(FROM_HERE, interval_, this, timer_.Start(FROM_HERE, interval_, this,
&ResourceCoordinatorRenderProcessProbe:: &ResourceCoordinatorRenderProcessProbe::
RegisterAliveRenderProcessesOnUIThread); RegisterAliveRenderProcessesOnUIThread);
} else {
is_gather_cycle_started_ = false;
} }
} }
......
...@@ -51,6 +51,11 @@ class ResourceCoordinatorRenderProcessProbe { ...@@ -51,6 +51,11 @@ class ResourceCoordinatorRenderProcessProbe {
// Can only be invoked from the UI thread. // Can only be invoked from the UI thread.
void StartGatherCycle(); void StartGatherCycle();
// Starts a single immediate collection cycle, if a cycle is not already
// in progress. If the timed gather cycle is running, this will preempt the
// next cycle and reset the metronome.
void StartSingleGather();
protected: protected:
// Internal state protected for testing. // Internal state protected for testing.
friend struct base::LazyInstanceTraitsBase< friend struct base::LazyInstanceTraitsBase<
...@@ -95,6 +100,9 @@ class ResourceCoordinatorRenderProcessProbe { ...@@ -95,6 +100,9 @@ class ResourceCoordinatorRenderProcessProbe {
// Number of measurements collected so far. // Number of measurements collected so far.
size_t current_gather_cycle_ = 0u; size_t current_gather_cycle_ = 0u;
// True if StartGatherCycle has been called.
bool is_gather_cycle_started_ = false;
// 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;
......
...@@ -49,21 +49,27 @@ class TestingResourceCoordinatorRenderProcessProbe ...@@ -49,21 +49,27 @@ class TestingResourceCoordinatorRenderProcessProbe
return true; return true;
} }
size_t current_gather_cycle() const { return current_gather_cycle_; }
const RenderProcessInfoMap& render_process_info_map() const { const RenderProcessInfoMap& render_process_info_map() const {
return render_process_info_map_; return render_process_info_map_;
} }
void StartGatherCycleAndWait() { size_t current_gather_cycle() const { return current_gather_cycle_; }
bool is_gather_cycle_started() const { return is_gather_cycle_started_; }
void WaitForGather() {
base::RunLoop run_loop; base::RunLoop run_loop;
current_run_loop_ = &run_loop; current_run_loop_ = &run_loop;
StartGatherCycle();
run_loop.Run(); run_loop.Run();
current_run_loop_ = nullptr; current_run_loop_ = nullptr;
} }
void StartGatherCycleAndWait() {
StartGatherCycle();
WaitForGather();
}
private: private:
base::RunLoop* current_run_loop_ = nullptr; base::RunLoop* current_run_loop_ = nullptr;
...@@ -152,4 +158,47 @@ IN_PROC_BROWSER_TEST_F(ResourceCoordinatorRenderProcessProbeBrowserTest, ...@@ -152,4 +158,47 @@ IN_PROC_BROWSER_TEST_F(ResourceCoordinatorRenderProcessProbeBrowserTest,
EXPECT_TRUE(probe.AllMeasurementsAreAtCurrentCycle()); EXPECT_TRUE(probe.AllMeasurementsAreAtCurrentCycle());
} }
IN_PROC_BROWSER_TEST_F(ResourceCoordinatorRenderProcessProbeBrowserTest,
StartSingleGather) {
// Ensure that the |resource_coordinator| service is enabled.
base::test::ScopedFeatureList feature_list;
feature_list.InitWithFeatures({features::kGlobalResourceCoordinator,
features::kGRCRenderProcessCPUProfiling},
{});
TestingResourceCoordinatorRenderProcessProbe probe;
// Test the gather cycle state.
EXPECT_FALSE(probe.is_gather_cycle_started());
probe.StartGatherCycle();
EXPECT_TRUE(probe.is_gather_cycle_started());
probe.WaitForGather();
EXPECT_FALSE(probe.is_gather_cycle_started());
EXPECT_EQ(1u, probe.current_gather_cycle());
// Test a single gather while the gather cycle is disabled.
probe.StartSingleGather();
EXPECT_FALSE(probe.is_gather_cycle_started());
probe.WaitForGather();
EXPECT_FALSE(probe.is_gather_cycle_started());
EXPECT_EQ(2u, probe.current_gather_cycle());
// Test a single gather followed by starting the gather cycle.
probe.StartSingleGather();
EXPECT_FALSE(probe.is_gather_cycle_started());
probe.StartGatherCycle();
EXPECT_TRUE(probe.is_gather_cycle_started());
probe.WaitForGather();
EXPECT_FALSE(probe.is_gather_cycle_started());
EXPECT_EQ(3u, probe.current_gather_cycle());
// And now a single gather after the cycle is started.
probe.StartGatherCycle();
EXPECT_TRUE(probe.is_gather_cycle_started());
probe.StartSingleGather();
probe.WaitForGather();
EXPECT_FALSE(probe.is_gather_cycle_started());
EXPECT_EQ(4u, probe.current_gather_cycle());
}
} // namespace resource_coordinator } // namespace resource_coordinator
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