Skip to content

Commit

Permalink
Bug 1686295 - Flip the order of two time measurement calls in telemet…
Browse files Browse the repository at this point in the history
…ry to provide actual guarantees to callers. r=chutten

See the comment in the code for the rationale. Having it in the other order
(before this patch) caused a but real rare intermittent on Linux and macOS, the
two OSes where this is used and the clock has a high enough resolution. This
happened when the first call was made before a millisecond mark and the second
one after, with the same time source: machines on treeherder don't suspend, the
numbers should be equal, but rarely the time excluding suspend was longer by 1ms
compared to the time including suspend.

Differential Revision: https://phabricator.services.mozilla.com/D109370
  • Loading branch information
padenot committed Mar 23, 2021
1 parent a297afd commit 40f112b
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions toolkit/components/telemetry/pings/TelemetrySession.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -751,14 +751,21 @@ var Impl = {
const isMobile = AppConstants.platform == "android";
const isSubsession = isMobile ? false : !this._isClassicReason(reason);

Telemetry.scalarSet(
"browser.engagement.session_time_including_suspend",
Telemetry.msSinceProcessStartIncludingSuspend()
);
// The order of the next two msSinceProcessStart* calls is somewhat
// important. In theory, `session_time_including_suspend` is supposed to
// ALWAYS be lower or equal than `session_time_excluding_suspend` (because
// the former is a temporal superset of the latter). When a device has not
// been suspended since boot, we want the previous property to hold,
// regardless of the delay during or between the two
// `msSinceProcessStart*` calls.
Telemetry.scalarSet(
"browser.engagement.session_time_excluding_suspend",
Telemetry.msSinceProcessStartExcludingSuspend()
);
Telemetry.scalarSet(
"browser.engagement.session_time_including_suspend",
Telemetry.msSinceProcessStartIncludingSuspend()
);

if (isMobile) {
clearSubsession = false;
Expand Down

0 comments on commit 40f112b

Please sign in to comment.