Skip to content

Commit

Permalink
[M102] Add a metric for the extended browser crash monitoring duration.
Browse files Browse the repository at this point in the history
(cherry picked from commit 49058f9)

Bug: 1321465
Change-Id: I808216e2d9fe5afe36ff999d0421b771a07e49a9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3615364
Reviewed-by: Siddhartha S <ssid@chromium.org>
Commit-Queue: Caitlin Fischer <caitlinfischer@google.com>
Reviewed-by: Ilya Sherman <isherman@chromium.org>
Reviewed-by: Peter Wen <wnwen@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#998717}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3629706
Cr-Commit-Position: refs/branch-heads/5005@{#494}
Cr-Branched-From: 5b4d945-refs/heads/main@{#992738}
  • Loading branch information
Caitlin Fischer authored and Chromium LUCI CQ committed May 6, 2022
1 parent 315b6be commit 2d5ba6a
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 0 deletions.
20 changes: 20 additions & 0 deletions components/metrics/clean_exit_beacon.cc
Expand Up @@ -366,6 +366,11 @@ void CleanExitBeacon::WriteBeaconValue(bool exited_cleanly,
if (is_extended_safe_mode) {
DCHECK_EQ(group_name, kEnabledGroup);
DCHECK(!exited_cleanly);

#if BUILDFLAG(IS_ANDROID)
extended_monitoring_stage_start_time_ = base::TimeTicks::Now();
#endif

SCOPED_UMA_HISTOGRAM_TIMER_MICROS(
"Variations.ExtendedSafeMode.WritePrefsTime");
// The beacon value is written to disk synchronously twice during
Expand All @@ -390,6 +395,21 @@ void CleanExitBeacon::WriteBeaconValue(bool exited_cleanly,
} else {
local_state_->SetBoolean(prefs::kStabilityExitedCleanly, exited_cleanly);
local_state_->CommitPendingWrite(); // Schedule a write.
#if BUILDFLAG(IS_ANDROID)
if (!extended_monitoring_stage_start_time_.is_null()) {
// The time exists, so this is the transition from the extended browser
// crash monitoring stage to the status quo stage. Only Extended
// Variations Safe Mode enabled-group clients have the extended monitoring
// stage.
// TODO(crbug/1321989): Clean up this metric and
// |extended_monitoring_stage_start_time_| once Android Chrome
// stakeholders have enough data on the duration.
base::UmaHistogramLongTimes(
"UMA.CleanExitBeacon.ExtendedMonitoringStageDuration",
base::TimeTicks::Now() - extended_monitoring_stage_start_time_);
extended_monitoring_stage_start_time_ = base::TimeTicks(); // Null time.
}
#endif // BUILDFLAG(IS_ANDROID)
if (group_name == kEnabledGroup) {
// Clients in this group write to the Variations Safe Mode file whenever
// |kStabilityExitedCleanly| is updated. The file is kept in sync with the
Expand Down
6 changes: 6 additions & 0 deletions components/metrics/clean_exit_beacon.h
Expand Up @@ -196,6 +196,12 @@ class CleanExitBeacon {
static void ResetUserDefaultsBeacon();
#endif // BUILDFLAG(IS_IOS)

#if BUILDFLAG(IS_ANDROID)
// Denotes the time at which Chrome clients in the Extended Variations Safe
// Mode experiment's enabled group start watching for browser crashes.
base::TimeTicks extended_monitoring_stage_start_time_;
#endif

// Indicates whether the CleanExitBeacon has been initialized.
bool initialized_ = false;

Expand Down
63 changes: 63 additions & 0 deletions components/metrics/clean_exit_beacon_unittest.cc
Expand Up @@ -822,4 +822,67 @@ TEST_P(BeaconFileAndPlatformBeaconConsistencyTest, BeaconConsistency) {
}
#endif // BUILDFLAG(IS_IOS)

#if BUILDFLAG(IS_ANDROID)
TEST_F(CleanExitBeaconTest, EnabledGroupEmitsStageDurationMetric) {
// Force the client into the Extended Variations Safe Mode experiment's
// enabled group.
SetUpExtendedSafeModeExperiment(variations::kEnabledGroup);

// Create and initialize the CleanExitBeacon.
TestCleanExitBeacon clean_exit_beacon(&prefs_);

// Simulate Chrome starting to watch for browser crashes for enabled-group
// clients.
clean_exit_beacon.WriteBeaconValue(/*exited_cleanly=*/false,
/*is_extended_safe_mode=*/true);
// Verify that the metric has not yet been emitted.
histogram_tester_.ExpectTotalCount(
"UMA.CleanExitBeacon.ExtendedMonitoringStageDuration", 0);

// Simulate Chrome continuing to watch for crashes once the app enters the
// foreground.
clean_exit_beacon.WriteBeaconValue(/*exited_cleanly=*/false,
/*is_extended_safe_mode=*/false);
// Verify that the metric was emitted.
histogram_tester_.ExpectTotalCount(
"UMA.CleanExitBeacon.ExtendedMonitoringStageDuration", 1);

// Make the same call. Note that these two identical, consecutive calls to
// WriteBeaconValue() shouldn't actually happen, but this is done for the
// purpose of the test.
clean_exit_beacon.WriteBeaconValue(/*exited_cleanly=*/false,
/*is_extended_safe_mode=*/false);
// Verify that the metric was not emitted again.
histogram_tester_.ExpectTotalCount(
"UMA.CleanExitBeacon.ExtendedMonitoringStageDuration", 1);
}

TEST_F(CleanExitBeaconTest, ControlGroupDoesNotEmitStageDurationMetric) {
// Force the client into the Extended Variations Safe Mode experiment's
// control group.
SetUpExtendedSafeModeExperiment(variations::kControlGroup);

// Create and initialize the CleanExitBeacon.
TestCleanExitBeacon clean_exit_beacon(&prefs_);

// Simulate Chrome starting to watch for browser crashes for control-group
// clients once the app enters the foreground.
clean_exit_beacon.WriteBeaconValue(/*exited_cleanly=*/false,
/*is_extended_safe_mode=*/false);
// Verify that the metric was not emitted.
histogram_tester_.ExpectTotalCount(
"UMA.CleanExitBeacon.ExtendedMonitoringStageDuration", 0);

// Make the same call. Note that these two identical, consecutive calls to
// WriteBeaconValue() shouldn't actually happen, but this is done for the
// purpose of the test.
clean_exit_beacon.WriteBeaconValue(/*exited_cleanly=*/false,
/*is_extended_safe_mode=*/false);
// Verify that the metric was not emitted.
histogram_tester_.ExpectTotalCount(
"UMA.CleanExitBeacon.ExtendedMonitoringStageDuration", 0);
}

#endif // BUILDFLAG(IS_ANDROID)

} // namespace metrics
14 changes: 14 additions & 0 deletions tools/metrics/histograms/metadata/uma/histograms.xml
Expand Up @@ -114,6 +114,20 @@ chromium-metrics-reviews@google.com.
</summary>
</histogram>

<histogram name="UMA.CleanExitBeacon.ExtendedMonitoringStageDuration"
units="ms" expires_after="2022-11-01">
<owner>ssid@chromium.org</owner>
<owner>wnwen@chromium.org</owner>
<summary>
The amount of time in ms between the extended and status quo browser crash
monitoring stages. The extended monitoring stage may begin in
MaybeExtendVariationsSafeMode(), and the status quo stage begins in
MetricsService::OnAppEnterForeground(). Emitted when the status quo
monitoring stage begins. Recorded by Extended Variations Safe Mode
enabled-group clients on Android Chrome.
</summary>
</histogram>

<histogram name="UMA.CleanExitBeacon.MonitoringStage"
enum="BeaconMonitoringStage" expires_after="2022-10-04">
<owner>caitlinfischer@google.com</owner>
Expand Down

0 comments on commit 2d5ba6a

Please sign in to comment.