Commit 22ab811a authored by Charlene Yan's avatar Charlene Yan Committed by Commit Bot

[Tab Search] Add metrics for tabs with same domains.

Logging the number of tabs in a particular domain along with a rough
estimate of the total number of tabs across all windows.

Bug: 109917
Change-Id: I7c88cc6693b41d34b671342697b20772ef377f88
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2441285
Commit-Queue: Charlene Yan <cyan@chromium.org>
Reviewed-by: default avatarAlexei Svitkine <asvitkine@chromium.org>
Reviewed-by: default avatarPeter Boström <pbos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#813252}
parent 544debc5
...@@ -4,8 +4,10 @@ ...@@ -4,8 +4,10 @@
#include "chrome/browser/ui/uma_browsing_activity_observer.h" #include "chrome/browser/ui/uma_browsing_activity_observer.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h" #include "base/metrics/user_metrics.h"
#include "base/numerics/ranges.h"
#include "base/time/time.h" #include "base/time/time.h"
#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
...@@ -115,6 +117,8 @@ void UMABrowsingActivityObserver::LogBrowserTabCount() const { ...@@ -115,6 +117,8 @@ void UMABrowsingActivityObserver::LogBrowserTabCount() const {
int app_window_count = 0; int app_window_count = 0;
int popup_window_count = 0; int popup_window_count = 0;
int tabbed_window_count = 0; int tabbed_window_count = 0;
std::map<base::StringPiece, int> unique_domain;
for (auto* browser : *BrowserList::GetInstance()) { for (auto* browser : *BrowserList::GetInstance()) {
// Record how many tabs each window has open. // Record how many tabs each window has open.
UMA_HISTOGRAM_CUSTOM_COUNTS("Tabs.TabCountPerWindow", UMA_HISTOGRAM_CUSTOM_COUNTS("Tabs.TabCountPerWindow",
...@@ -123,6 +127,13 @@ void UMABrowsingActivityObserver::LogBrowserTabCount() const { ...@@ -123,6 +127,13 @@ void UMABrowsingActivityObserver::LogBrowserTabCount() const {
TabStripModel* const tab_strip_model = browser->tab_strip_model(); TabStripModel* const tab_strip_model = browser->tab_strip_model();
tab_count += tab_strip_model->count(); tab_count += tab_strip_model->count();
for (int i = 0; i < tab_strip_model->count(); ++i) {
base::StringPiece domain = tab_strip_model->GetWebContentsAt(i)
->GetLastCommittedURL()
.host_piece();
unique_domain[domain] += 1;
}
const std::vector<tab_groups::TabGroupId>& groups = const std::vector<tab_groups::TabGroupId>& groups =
tab_strip_model->group_model()->ListTabGroups(); tab_strip_model->group_model()->ListTabGroups();
tab_group_count += groups.size(); tab_group_count += groups.size();
...@@ -152,6 +163,15 @@ void UMABrowsingActivityObserver::LogBrowserTabCount() const { ...@@ -152,6 +163,15 @@ void UMABrowsingActivityObserver::LogBrowserTabCount() const {
else if (browser->is_type_normal()) else if (browser->is_type_normal())
tabbed_window_count++; tabbed_window_count++;
} }
// Record how many tabs share a domain based on the total number of tabs open.
const std::string tab_count_per_domain_histogram_name =
AppendTabBucketCountToHistogramName(tab_count);
for (auto domain : unique_domain) {
base::UmaHistogramSparse(tab_count_per_domain_histogram_name,
base::ClampToRange(domain.second, 0, 200));
}
// Record how many tabs total are open (across all windows). // Record how many tabs total are open (across all windows).
UMA_HISTOGRAM_CUSTOM_COUNTS("Tabs.TabCountPerLoad", tab_count, 1, 200, 50); UMA_HISTOGRAM_CUSTOM_COUNTS("Tabs.TabCountPerLoad", tab_count, 1, 200, 50);
...@@ -192,4 +212,42 @@ void UMABrowsingActivityObserver::LogBrowserTabCount() const { ...@@ -192,4 +212,42 @@ void UMABrowsingActivityObserver::LogBrowserTabCount() const {
tabbed_window_count); tabbed_window_count);
} }
std::string UMABrowsingActivityObserver::AppendTabBucketCountToHistogramName(
int total_tab_count) const {
const char* bucket = nullptr;
if (total_tab_count < 6) {
bucket = "0to5";
} else if (total_tab_count < 11) {
bucket = "6to10";
} else if (total_tab_count < 16) {
bucket = "10to15";
} else if (total_tab_count < 21) {
bucket = "16to20";
} else if (total_tab_count < 31) {
bucket = "21to30";
} else if (total_tab_count < 41) {
bucket = "31to40";
} else if (total_tab_count < 61) {
bucket = "41to60";
} else if (total_tab_count < 81) {
bucket = "61to80";
} else if (total_tab_count < 101) {
bucket = "81to100";
} else if (total_tab_count < 151) {
bucket = "101to150";
} else if (total_tab_count < 201) {
bucket = "151to200";
} else if (total_tab_count < 301) {
bucket = "201to300";
} else if (total_tab_count < 401) {
bucket = "301to400";
} else if (total_tab_count < 501) {
bucket = "401to500";
} else {
bucket = "501+";
}
const char kHistogramBaseName[] = "Tabs.TabCountPerDomainPerLoad";
return base::StringPrintf("%s.%s", kHistogramBaseName, bucket);
}
} // namespace chrome } // namespace chrome
...@@ -41,6 +41,10 @@ class UMABrowsingActivityObserver : public content::NotificationObserver { ...@@ -41,6 +41,10 @@ class UMABrowsingActivityObserver : public content::NotificationObserver {
// tabs here. // tabs here.
void LogBrowserTabCount() const; void LogBrowserTabCount() const;
// Maps |total_tab_count| to the corresponding histogram bucket with the
// proper name suffix.
std::string AppendTabBucketCountToHistogramName(int total_tab_count) const;
content::NotificationRegistrar registrar_; content::NotificationRegistrar registrar_;
TabStripModelStatsRecorder tab_recorder_; TabStripModelStatsRecorder tab_recorder_;
......
...@@ -1672,6 +1672,35 @@ reviews. Googlers can read more about this at go/gwsq-gerrit. ...@@ -1672,6 +1672,35 @@ reviews. Googlers can read more about this at go/gwsq-gerrit.
</details> </details>
</histogram> </histogram>
<histogram name="Tabs.TabCountPerDomainPerLoad.{TotalTabCountBucket}"
units="tabs" expires_after="2021-03-07">
<owner>connily@chromium.org</owner>
<owner>cyan@chromium.org</owner>
<owner>chrome-desktop-ui-sea@google.com</owner>
<summary>
The number of tabs across all browsers (counting app-mode windows) with the
same host piece when a load completes. {TotalTabCountBucket} is inclusive
and describes the total number of tabs when logging.
</summary>
<token key="TotalTabCountBucket">
<variant name="0to5" summary=""/>
<variant name="6to10" summary=""/>
<variant name="10to15" summary=""/>
<variant name="16to20" summary=""/>
<variant name="21to30" summary=""/>
<variant name="31to40" summary=""/>
<variant name="41to60" summary=""/>
<variant name="61to80" summary=""/>
<variant name="81to100" summary=""/>
<variant name="101to150" summary=""/>
<variant name="151to200" summary=""/>
<variant name="201to300" summary=""/>
<variant name="301to400" summary=""/>
<variant name="401to500" summary=""/>
<variant name="500+" summary=""/>
</token>
</histogram>
<histogram name="Tabs.TabCountPerLoad" units="tabs" expires_after="2021-07-31"> <histogram name="Tabs.TabCountPerLoad" units="tabs" expires_after="2021-07-31">
<owner>mpearson@chromium.org</owner> <owner>mpearson@chromium.org</owner>
<owner>chrome-desktop-ui-sea@google.com</owner> <owner>chrome-desktop-ui-sea@google.com</owner>
......
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