Commit d450cb9e authored by Scott Haseley's avatar Scott Haseley Committed by Commit Bot

Add session restore swap metrics UMAs to TabManager.

This CL adds UMAs for system swap metrics during session restore. The
implementation uses SwapMetricsDriver to collect the swap metrics during
session restore, and computes rates (e.g. swaps in/second) as an average over
the entire session restore interval. Swap metrics are platform-specific.
Currently, swap in/out rate is available on Linux and Mac, and page
compression/decompression rates are available on Mac only.

Bug: 740625
Change-Id: I3dfb4268759e6900e768756b8939ad64de603a06
Reviewed-on: https://chromium-review.googlesource.com/585405
Commit-Queue: Scott Haseley <shaseley@google.com>
Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Reviewed-by: default avatarFadi Meawad <fmeawad@chromium.org>
Reviewed-by: default avatarZhen Wang <zhenw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491254}
parent ad3d3557
...@@ -4,16 +4,70 @@ ...@@ -4,16 +4,70 @@
#include "chrome/browser/resource_coordinator/tab_manager_stats_collector.h" #include "chrome/browser/resource_coordinator/tab_manager_stats_collector.h"
#include <cstdint>
#include <memory>
#include <utility>
#include "base/memory/ptr_util.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/time/time.h"
#include "chrome/browser/resource_coordinator/tab_manager.h" #include "chrome/browser/resource_coordinator/tab_manager.h"
#include "chrome/browser/resource_coordinator/tab_manager_web_contents_data.h" #include "chrome/browser/resource_coordinator/tab_manager_web_contents_data.h"
#include "chrome/browser/sessions/session_restore.h"
#include "content/public/browser/swap_metrics_driver.h"
namespace resource_coordinator { namespace resource_coordinator {
class TabManagerStatsCollector::SessionRestoreSwapMetricsDelegate
: public content::SwapMetricsDriver::Delegate {
public:
explicit SessionRestoreSwapMetricsDelegate(
TabManagerStatsCollector* tab_manager_stats_collector)
: tab_manager_stats_collector_(tab_manager_stats_collector) {}
~SessionRestoreSwapMetricsDelegate() override = default;
void OnSwapInCount(uint64_t count, base::TimeDelta interval) override {
tab_manager_stats_collector_->OnSessionRestoreSwapInCount(count, interval);
}
void OnSwapOutCount(uint64_t count, base::TimeDelta interval) override {
tab_manager_stats_collector_->OnSessionRestoreSwapOutCount(count, interval);
}
void OnDecompressedPageCount(uint64_t count,
base::TimeDelta interval) override {
tab_manager_stats_collector_->OnSessionRestoreDecompressedPageCount(
count, interval);
}
void OnCompressedPageCount(uint64_t count,
base::TimeDelta interval) override {
tab_manager_stats_collector_->OnSessionRestoreCompressedPageCount(count,
interval);
}
void OnSessionRestoreUpdateMetricsFailed() {
tab_manager_stats_collector_->OnSessionRestoreUpdateMetricsFailed();
}
private:
TabManagerStatsCollector* tab_manager_stats_collector_;
};
TabManagerStatsCollector::TabManagerStatsCollector(TabManager* tab_manager) TabManagerStatsCollector::TabManagerStatsCollector(TabManager* tab_manager)
: tab_manager_(tab_manager) {} : tab_manager_(tab_manager), is_session_restore_loading_tabs_(false) {
std::unique_ptr<content::SwapMetricsDriver::Delegate> delegate(
base::WrapUnique<content::SwapMetricsDriver::Delegate>(
new SessionRestoreSwapMetricsDelegate(this)));
session_restore_swap_metrics_driver_ = content::SwapMetricsDriver::Create(
std::move(delegate), base::TimeDelta::FromSeconds(0));
SessionRestore::AddObserver(this);
}
TabManagerStatsCollector::~TabManagerStatsCollector() = default; TabManagerStatsCollector::~TabManagerStatsCollector() {
SessionRestore::RemoveObserver(this);
}
void TabManagerStatsCollector::RecordSwitchToTab( void TabManagerStatsCollector::RecordSwitchToTab(
content::WebContents* contents) const { content::WebContents* contents) const {
...@@ -25,4 +79,61 @@ void TabManagerStatsCollector::RecordSwitchToTab( ...@@ -25,4 +79,61 @@ void TabManagerStatsCollector::RecordSwitchToTab(
} }
} }
void TabManagerStatsCollector::OnSessionRestoreStartedLoadingTabs() {
DCHECK(!is_session_restore_loading_tabs_);
if (session_restore_swap_metrics_driver_)
session_restore_swap_metrics_driver_->InitializeMetrics();
is_session_restore_loading_tabs_ = true;
}
void TabManagerStatsCollector::OnSessionRestoreFinishedLoadingTabs() {
DCHECK(is_session_restore_loading_tabs_);
if (session_restore_swap_metrics_driver_)
session_restore_swap_metrics_driver_->UpdateMetrics();
is_session_restore_loading_tabs_ = false;
}
void TabManagerStatsCollector::OnSessionRestoreSwapInCount(
uint64_t count,
base::TimeDelta interval) {
DCHECK(is_session_restore_loading_tabs_);
UMA_HISTOGRAM_COUNTS_10000(
"TabManager.SessionRestore.SwapInPerSecond",
static_cast<double>(count) / interval.InSecondsF());
}
void TabManagerStatsCollector::OnSessionRestoreSwapOutCount(
uint64_t count,
base::TimeDelta interval) {
DCHECK(is_session_restore_loading_tabs_);
UMA_HISTOGRAM_COUNTS_10000(
"TabManager.SessionRestore.SwapOutPerSecond",
static_cast<double>(count) / interval.InSecondsF());
}
void TabManagerStatsCollector::OnSessionRestoreDecompressedPageCount(
uint64_t count,
base::TimeDelta interval) {
DCHECK(is_session_restore_loading_tabs_);
UMA_HISTOGRAM_COUNTS_10000(
"TabManager.SessionRestore.DecompressedPagesPerSecond",
static_cast<double>(count) / interval.InSecondsF());
}
void TabManagerStatsCollector::OnSessionRestoreCompressedPageCount(
uint64_t count,
base::TimeDelta interval) {
DCHECK(is_session_restore_loading_tabs_);
UMA_HISTOGRAM_COUNTS_10000(
"TabManager.SessionRestore.CompressedPagesPerSecond",
static_cast<double>(count) / interval.InSecondsF());
}
void TabManagerStatsCollector::OnSessionRestoreUpdateMetricsFailed() {
// If either InitializeMetrics() or UpdateMetrics() fails, it's unlikely an
// error that can be recovered from, in which case we don't collect swap
// metrics for session restore.
session_restore_swap_metrics_driver_.reset();
}
} // namespace resource_coordinator } // namespace resource_coordinator
...@@ -5,7 +5,17 @@ ...@@ -5,7 +5,17 @@
#ifndef CHROME_BROWSER_RESOURCE_COORDINATOR_TAB_MANAGER_STATS_COLLECTOR_H_ #ifndef CHROME_BROWSER_RESOURCE_COORDINATOR_TAB_MANAGER_STATS_COLLECTOR_H_
#define CHROME_BROWSER_RESOURCE_COORDINATOR_TAB_MANAGER_STATS_COLLECTOR_H_ #define CHROME_BROWSER_RESOURCE_COORDINATOR_TAB_MANAGER_STATS_COLLECTOR_H_
#include <cstdint>
#include <memory>
#include "chrome/browser/sessions/session_restore_observer.h"
namespace base {
class TimeDelta;
}
namespace content { namespace content {
class SwapMetricsDriver;
class WebContents; class WebContents;
} // namespace content } // namespace content
...@@ -15,7 +25,7 @@ class TabManager; ...@@ -15,7 +25,7 @@ class TabManager;
// TabManagerStatsCollector records UMAs on behalf of TabManager for tab and // TabManagerStatsCollector records UMAs on behalf of TabManager for tab and
// system-related events and properties during session restore. // system-related events and properties during session restore.
class TabManagerStatsCollector { class TabManagerStatsCollector : public SessionRestoreObserver {
public: public:
explicit TabManagerStatsCollector(TabManager* tab_manager); explicit TabManagerStatsCollector(TabManager* tab_manager);
~TabManagerStatsCollector(); ~TabManagerStatsCollector();
...@@ -24,8 +34,27 @@ class TabManagerStatsCollector { ...@@ -24,8 +34,27 @@ class TabManagerStatsCollector {
// during session restore. // during session restore.
void RecordSwitchToTab(content::WebContents* contents) const; void RecordSwitchToTab(content::WebContents* contents) const;
// SessionRestoreObserver
void OnSessionRestoreStartedLoadingTabs() override;
void OnSessionRestoreFinishedLoadingTabs() override;
// The following record UMA histograms for system swap metrics during session
// restore.
void OnSessionRestoreSwapInCount(uint64_t count, base::TimeDelta interval);
void OnSessionRestoreSwapOutCount(uint64_t count, base::TimeDelta interval);
void OnSessionRestoreDecompressedPageCount(uint64_t count,
base::TimeDelta interval);
void OnSessionRestoreCompressedPageCount(uint64_t count,
base::TimeDelta interval);
void OnSessionRestoreUpdateMetricsFailed();
private: private:
class SessionRestoreSwapMetricsDelegate;
TabManager* tab_manager_; TabManager* tab_manager_;
std::unique_ptr<content::SwapMetricsDriver>
session_restore_swap_metrics_driver_;
bool is_session_restore_loading_tabs_;
}; };
} // namespace resource_coordinator } // namespace resource_coordinator
......
...@@ -79989,6 +79989,56 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries. ...@@ -79989,6 +79989,56 @@ http://cs/file:chrome/histograms.xml - but prefer this file for new entries.
</summary> </summary>
</histogram> </histogram>
<histogram name="TabManager.SessionRestore.CompressedPagesPerSecond"
units="pages/s">
<owner>fmeawad@chromium.org</owner>
<summary>
The number of pages compressed per second during session restore. Recorded
at the end of session restore as an average over the entire period, defined
as the period of time when session restore is actively loading tabs, which
ends when either all tabs have been loaded and their pages rendered, or tab
loading needs to be deferred in cases where the system is under memory
pressure. Only recorded on macOS.
</summary>
</histogram>
<histogram name="TabManager.SessionRestore.DecompressedPagesPerSecond"
units="pages/s">
<owner>fmweawad@chromium.org</owner>
<summary>
The number of pages decompressed per second during session restore. Recorded
at the end of session restore as an average over the entire period, defined
as the period of time when session restore is actively loading tabs, which
ends when either all tabs have been loaded and their pages rendered, or tab
loading needs to be deferred in cases where the system is under memory
pressure. Only recorded on macOS.
</summary>
</histogram>
<histogram name="TabManager.SessionRestore.SwapInPerSecond" units="swaps/s">
<owner>fmeawad@chromium.org</owner>
<summary>
The number of swap-ins per second during session restore. Recorded at the
end of session restore as an average over the entire period, defined as the
period of time when session restore is actively loading tabs, which ends
when either all tabs have been loaded and their pages rendered, or tab
loading needs to be deferred in cases where the system is under memory
pressure.
</summary>
</histogram>
<histogram name="TabManager.SessionRestore.SwapOutPerSecond" units="swaps/s">
<owner>fmeawad@chromium.org</owner>
<summary>
The number of swap-ins per second during session restore. Recorded at the
end of session restore as an average over the entire period, defined as the
period of time when session restore is actively loading tabs, which ends
when either all tabs have been loaded and their pages rendered, or tab
loading needs to be deferred in cases where the system is under memory
pressure.
</summary>
</histogram>
<histogram name="TabManager.SessionRestore.SwitchToTab" enum="TabLoadingState"> <histogram name="TabManager.SessionRestore.SwitchToTab" enum="TabLoadingState">
<owner>fmeawad@chromium.org</owner> <owner>fmeawad@chromium.org</owner>
<summary> <summary>
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