Skip to content

Commit

Permalink
Start on PerformanceMeasurementManager.
Browse files Browse the repository at this point in the history
This will glue together the measurement cycle from event notifications
from the TabLoadTracker to the measurements in RenderProcessProbe.
Eventually this class will also persist complete measurements issued
from an observer in the RC service by sinking notifications and
persisting to the feature database.

Bug: 755840
Change-Id: I8c6673fcf205709ad96435295f9010a6aceb3017
Reviewed-on: https://chromium-review.googlesource.com/1072232
Commit-Queue: Sigurður Ásgeirsson <siggi@chromium.org>
Reviewed-by: François Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#562258}
  • Loading branch information
sigurasg authored and Commit Bot committed May 28, 2018
1 parent 9ccc4fa commit b5590fe
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 0 deletions.
2 changes: 2 additions & 0 deletions chrome/browser/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1265,6 +1265,8 @@ jumbo_split_static_library("browser") {
"resource_coordinator/chrome_browser_main_extra_parts_resource_coordinator.h",
"resource_coordinator/page_signal_receiver.cc",
"resource_coordinator/page_signal_receiver.h",
"resource_coordinator/performance_measurement_manager.cc",
"resource_coordinator/performance_measurement_manager.h",
"resource_coordinator/render_process_probe.cc",
"resource_coordinator/render_process_probe.h",
"resource_coordinator/tab_helper.cc",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2018 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 "chrome/browser/resource_coordinator/performance_measurement_manager.h"

#include "chrome/browser/resource_coordinator/render_process_probe.h"
#include "chrome/browser/resource_coordinator/tab_load_tracker.h"

namespace resource_coordinator {

PerformanceMeasurementManager::PerformanceMeasurementManager(
TabLoadTracker* tab_load_tracker,
RenderProcessProbe* render_process_probe)
: scoped_observer_(this), render_process_probe_(render_process_probe) {
scoped_observer_.Add(tab_load_tracker);
}

PerformanceMeasurementManager::~PerformanceMeasurementManager() = default;

void PerformanceMeasurementManager::OnStartTracking(
content::WebContents* web_contents,
LoadingState loading_state) {
if (loading_state == TabLoadTracker::LOADED)
render_process_probe_->StartSingleGather();
}

void PerformanceMeasurementManager::OnLoadingStateChange(
content::WebContents* web_contents,
LoadingState loading_state) {
if (loading_state == TabLoadTracker::LOADED)
render_process_probe_->StartSingleGather();
}

} // namespace resource_coordinator
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2018 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 CHROME_BROWSER_RESOURCE_COORDINATOR_PERFORMANCE_MEASUREMENT_MANAGER_H_
#define CHROME_BROWSER_RESOURCE_COORDINATOR_PERFORMANCE_MEASUREMENT_MANAGER_H_

#include "base/macros.h"
#include "base/scoped_observer.h"
#include "base/sequence_checker.h"
#include "chrome/browser/resource_coordinator/tab_load_tracker.h"

namespace resource_coordinator {

class RenderProcessProbe;
class TabLoadTracker;

// This class observes tab state change notifications issued by the
// TabLoadTracker and uses them to drive performance measurement requests
// to the RenderProcessProbe. Results then funnel through the resource
// coordinator service, back to this class, which stores them in the feature
// database.
class PerformanceMeasurementManager : public TabLoadTracker::Observer {
public:
PerformanceMeasurementManager(TabLoadTracker* tab_load_tracker,
RenderProcessProbe* render_process_probe);
~PerformanceMeasurementManager() override;

// TabLoadTracker::Observer implementation.
void OnStartTracking(content::WebContents* web_contents,
LoadingState loading_state) override;
void OnLoadingStateChange(content::WebContents* web_contents,
LoadingState loading_state) override;

private:
ScopedObserver<TabLoadTracker, PerformanceMeasurementManager>
scoped_observer_;
RenderProcessProbe* render_process_probe_;

DISALLOW_COPY_AND_ASSIGN(PerformanceMeasurementManager);
};

} // namespace resource_coordinator

#endif // CHROME_BROWSER_RESOURCE_COORDINATOR_PERFORMANCE_MEASUREMENT_MANAGER_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2018 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 "chrome/browser/resource_coordinator/performance_measurement_manager.h"
#include "chrome/browser/resource_coordinator/render_process_probe.h"
#include "chrome/browser/resource_coordinator/tab_helper.h"
#include "chrome/browser/resource_coordinator/tab_load_tracker.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace resource_coordinator {

class LenientMockRenderProcessProbe : public RenderProcessProbe {
public:
MOCK_METHOD0(StartGatherCycle, void());
MOCK_METHOD0(StartSingleGather, void());
};
using MockRenderProcessProbe =
testing::StrictMock<LenientMockRenderProcessProbe>;

class PerformanceMeasurementManagerTest
: public ChromeRenderViewHostTestHarness {
public:
std::unique_ptr<content::WebContents> CreateWebContents() {
std::unique_ptr<content::WebContents> contents = CreateTestWebContents();
ResourceCoordinatorTabHelper::CreateForWebContents(contents.get());
return contents;
}

MockRenderProcessProbe& mock_render_process_probe() {
return mock_render_process_probe_;
}

private:
MockRenderProcessProbe mock_render_process_probe_;
};

TEST_F(PerformanceMeasurementManagerTest, NoMeasurementOnCreation) {
PerformanceMeasurementManager performance_measurement_manager(
TabLoadTracker::Get(), &mock_render_process_probe());

auto contents = CreateWebContents();
}

TEST_F(PerformanceMeasurementManagerTest, StartMeasurementOnLoaded) {
PerformanceMeasurementManager performance_measurement_manager(
TabLoadTracker::Get(), &mock_render_process_probe());

auto contents = CreateWebContents();

EXPECT_CALL(mock_render_process_probe(), StartSingleGather());
TabLoadTracker::Get()->TransitionStateForTesting(contents.get(),
TabLoadTracker::LOADED);
}

} // namespace resource_coordinator
1 change: 1 addition & 0 deletions chrome/test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2943,6 +2943,7 @@ test("unit_tests") {
"../browser/resource_coordinator/local_site_characteristics_data_unittest_utils.h",
"../browser/resource_coordinator/local_site_characteristics_data_writer_unittest.cc",
"../browser/resource_coordinator/local_site_characteristics_non_recording_data_store_unittest.cc",
"../browser/resource_coordinator/performance_measurement_manager_unittest.cc",
"../browser/resource_coordinator/tab_activity_watcher_unittest.cc",
"../browser/resource_coordinator/tab_lifecycle_unit_source_unittest.cc",
"../browser/resource_coordinator/tab_lifecycle_unit_unittest.cc",
Expand Down

0 comments on commit b5590fe

Please sign in to comment.