Skip to content

Commit

Permalink
Instrument wait time for the dispatcher at shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
badboy committed May 10, 2023
1 parent 5f4b8f2 commit ce37542
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
17 changes: 17 additions & 0 deletions glean-core/metrics.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,23 @@ glean.validation:
- jrediger@mozilla.com
expires: never

shutdown_dispatcher_wait:
type: timing_distribution
time_unit: millisecond
description: |
Time waited for the dispatcher to unblock during shutdown.
Most samples are expected to be below the 10s timeout used.
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1828066
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1828066#c7
data_sensitivity:
- technical
notification_emails:
- glean-team@mozilla.com
- jrediger@mozilla.com
expires: never

glean:
restarted:
type: event
Expand Down
15 changes: 15 additions & 0 deletions glean-core/src/internal_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ pub struct AdditionalMetrics {

/// Time waited for the uploader at shutdown.
pub shutdown_wait: TimingDistributionMetric,

/// Time waited for the dispatcher to unblock during shutdown.
pub shutdown_dispatcher_wait: TimingDistributionMetric,
}

impl CoreMetrics {
Expand Down Expand Up @@ -97,6 +100,18 @@ impl AdditionalMetrics {
},
TimeUnit::Millisecond,
),

shutdown_dispatcher_wait: TimingDistributionMetric::new(
CommonMetricData {
name: "shutdown_dispatcher_wait".into(),
category: "glean.validation".into(),
send_in_pings: vec!["metrics".into()],
lifetime: Lifetime::Ping,
disabled: false,
dynamic_label: None,
},
TimeUnit::Millisecond,
),
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions glean-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,12 +571,25 @@ pub fn shutdown() {
// TODO: Make the timeout configurable?
// The default hang watchdog on Firefox waits 60s,
// Glean's `uploader_shutdown` further below waits up to 30s.
let timer_id = core::with_glean(|glean| {
glean
.additional_metrics
.shutdown_dispatcher_wait
.start_sync()
});
if dispatcher::block_on_queue_timeout(Duration::from_secs(10)).is_err() {
log::error!(
"Timeout while blocking on the dispatcher. No further shutdown cleanup will happen."
);
return;
}
let stop_time = time::precise_time_ns();
core::with_glean(|glean| {
glean
.additional_metrics
.shutdown_dispatcher_wait
.set_stop_and_accumulate(glean, timer_id, stop_time);
});

if let Err(e) = dispatcher::shutdown() {
log::error!("Can't shutdown dispatcher thread: {:?}", e);
Expand Down

0 comments on commit ce37542

Please sign in to comment.