Skip to content

Commit

Permalink
[iOS] Add active and inactive tabs count startup metrics
Browse files Browse the repository at this point in the history
Log the number of inactive tabs by arm definition and the number of
absolute inactive tab (older than 21 days) and the number of active tab
by arm definition.

Fixed: 1440123
Change-Id: I6c782535e22af450d366e8b422a736c26b2f8a01
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4459611
Reviewed-by: Olivier Robin <olivierrobin@chromium.org>
Commit-Queue: Aliona Dangla <alionadangla@chromium.org>
Reviewed-by: Sylvain Defresne <sdefresne@chromium.org>
Reviewed-by: Louis Romero <lpromero@google.com>
Reviewed-by: Dana Fried <dfried@chromium.org>
Code-Coverage: Findit <findit-for-me@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/heads/main@{#1135950}
  • Loading branch information
adangla authored and Chromium LUCI CQ committed Apr 26, 2023
1 parent 6d1cea7 commit 31c2e8f
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 2 deletions.
50 changes: 48 additions & 2 deletions ios/chrome/app/application_delegate/metrics_mediator.mm
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,14 @@ - (void)setAppGroupMetricsEnabled:(BOOL)enabled;
- (void)updateMetricsPrefsOnPermissionChange:(BOOL)enabled;
// Logs the inactive tabs settings preference.
+ (void)recordInactiveTabsSettingsAtStartup:(int)preference;
// Logs the number of active tabs (based on the arm's definition of
// active/inactive).
+ (void)recordNumActiveTabAtStartup:(int)numTabs;
// Logs the number of inactive tabs (based on the arm's definition of
// active/inactive).
+ (void)recordNumInactiveTabAtStartup:(int)numTabs;
// Logs the number of tabs older than 21 days.
+ (void)recordNumAbsoluteInactiveTabAtStartup:(int)numTabs;
// Logs the number of tabs with UMAHistogramCount100 and allows testing.
+ (void)recordNumTabAtStartup:(int)numTabs;
// Logs the number of tabs with UMAHistogramCount100 and allows testing.
Expand Down Expand Up @@ -406,6 +414,15 @@ + (void)logLaunchMetricsWithStartupInformation:
int numLiveNTPTabs = 0;
int numOldTabs = 0;
int numDuplicatedTabs = 0;
int numActiveTabs = 0;
int numInactiveTabs = 0;
int numAbsoluteInactiveTabs = 0;

// Amount of time after which a tab is considered as old.
constexpr base::TimeDelta kOldTabThreshold = base::Days(7);

// Amount of time after which a tab is considered as absolutely inactive.
constexpr base::TimeDelta kAbsoluteInactiveTabThreshold = base::Days(21);

NSMutableSet* uniqueURLs = [NSMutableSet set];
std::vector<base::TimeDelta> timesSinceCreation;
Expand All @@ -429,6 +446,8 @@ + (void)logLaunchMetricsWithStartupInformation:
const int inactiveWebStateListCount = inactiveWebStateList->count();

numTabs += webStateListCount + inactiveWebStateListCount;
numActiveTabs += webStateListCount;
numInactiveTabs += inactiveWebStateListCount;
// All inactive tabs are inactive since minimum 7 days or more.
numOldTabs += inactiveWebStateListCount;

Expand All @@ -450,9 +469,14 @@ + (void)logLaunchMetricsWithStartupInformation:
[uniqueURLs addObject:URLString];
}

// Count old (e.g. more than 7 days inactive) tabs.
if (now - webState->GetLastActiveTime() > base::Days(7)) {
// Count old tabs.
base::TimeDelta inactiveTime = now - webState->GetLastActiveTime();
if (inactiveTime > kOldTabThreshold) {
numOldTabs++;
// Count absolute inactive tabs.
if (inactiveTime > kAbsoluteInactiveTabThreshold) {
numAbsoluteInactiveTabs++;
}
}

// Calculate the age (time elapsed since creation) of WebState.
Expand All @@ -468,13 +492,23 @@ + (void)logLaunchMetricsWithStartupInformation:
// Calculate the age (time elapsed since creation) of WebState.
base::TimeDelta timeSinceCreation = now - webState->GetCreationTime();
timesSinceCreation.push_back(timeSinceCreation);

// Calculate absolute inactive tabs.
base::TimeDelta inactiveTime =
base::Time::Now() - webState->GetLastActiveTime();
if (inactiveTime > kAbsoluteInactiveTabThreshold) {
numAbsoluteInactiveTabs++;
}
}
}

if (startupInformation.isColdStart) {
[self recordInactiveTabsSettingsAtStartup:
GetApplicationContext()->GetLocalState()->GetInteger(
prefs::kInactiveTabsTimeThreshold)];
[self recordNumActiveTabAtStartup:numActiveTabs];
[self recordInactiveTabsSettingsAtStartup:numInactiveTabs];
[self recordNumAbsoluteInactiveTabAtStartup:numAbsoluteInactiveTabs];
[self recordNumTabAtStartup:numTabs];
[self recordNumNTPTabAtStartup:numNTPTabs];
[self recordNumOldTabAtStartup:numOldTabs];
Expand Down Expand Up @@ -688,6 +722,18 @@ + (void)recordInactiveTabsSettingsAtStartup:(int)preference {
InactiveTabsSettingFromPreference(preference));
}

+ (void)recordNumActiveTabAtStartup:(int)numTabs {
base::UmaHistogramCounts100("Tabs.ActiveCountAtStartup", numTabs);
}

+ (void)recordNumInactiveTabAtStartup:(int)numTabs {
base::UmaHistogramCounts100("Tabs.InactiveCountAtStartup", numTabs);
}

+ (void)recordNumAbsoluteInactiveTabAtStartup:(int)numTabs {
base::UmaHistogramCounts100("Tabs.OldCountAtStartup", numTabs);
}

+ (void)recordNumTabAtStartup:(int)numTabs {
base::UmaHistogramCounts100("Tabs.CountAtStartup", numTabs);
}
Expand Down
32 changes: 32 additions & 0 deletions tools/metrics/histograms/metadata/tab/histograms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,17 @@ chromium-metrics-reviews@google.com.
</token>
</histogram>

<histogram name="Tabs.ActiveCountAtStartup" units="tabs"
expires_after="2023-10-01">
<owner>alionadangla@chromium.org</owner>
<owner>lpromero@chromium.org</owner>
<owner>chromeleon@google.com</owner>
<summary>
[iOS] Records the number of tabs that are considered active as per the
current tab inactivity threshold. This is recorded at cold launch.
</summary>
</histogram>

<histogram name="Tabs.CountAtResume" units="tabs" expires_after="2024-01-15">
<!-- This histogram was expired between 2022-11-02 and M111 -->

Expand Down Expand Up @@ -1113,6 +1124,17 @@ chromium-metrics-reviews@google.com.
</summary>
</histogram>

<histogram name="Tabs.InactiveCountAtStartup" units="tabs"
expires_after="2023-10-01">
<owner>alionadangla@chromium.org</owner>
<owner>lpromero@chromium.org</owner>
<owner>chromeleon@google.com</owner>
<summary>
[iOS] Records the number of tabs that are considered inactive as per the
current tab inactivity threshold. This is recorded at cold launch.
</summary>
</histogram>

<histogram name="Tabs.LiveNTPCountAtResume" units="tabs"
expires_after="2024-02-26">
<owner>thegreenfrog@chromium.org</owner>
Expand Down Expand Up @@ -1221,6 +1243,16 @@ chromium-metrics-reviews@google.com.
<token key="BatteryState" variants="BatteryState"/>
</histogram>

<histogram name="Tabs.OldCountAtStartup" units="tabs"
expires_after="2023-10-01">
<owner>alionadangla@chromium.org</owner>
<owner>lpromero@chromium.org</owner>
<owner>chromeleon@google.com</owner>
<summary>
[iOS] Number of tabs older than 21 days. Recorded at cold launch.
</summary>
</histogram>

<histogram name="Tabs.PersistedTabData.Critical.Map.Success"
enum="BooleanSuccess" expires_after="2024-01-08">
<owner>davidjm@chromium.org</owner>
Expand Down

0 comments on commit 31c2e8f

Please sign in to comment.