Skip to content

Commit

Permalink
Bug 1589554 - Part 5: Screen Wake Lock telemetry. r=dom-core,edgar
Browse files Browse the repository at this point in the history
Depends on D189511

Differential Revision: https://phabricator.services.mozilla.com/D189512
  • Loading branch information
vinhill committed Dec 5, 2023
1 parent 9f31a7c commit 3665f97
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
13 changes: 13 additions & 0 deletions dom/power/WakeLockSentinel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "mozilla/Assertions.h"
#include "mozilla/Telemetry.h"
#include "mozilla/TelemetryHistogramEnums.h"
#include "mozilla/dom/Document.h"
#include "mozilla/dom/Event.h"
#include "mozilla/dom/EventBinding.h"
Expand All @@ -27,6 +29,17 @@ void WakeLockSentinel::NotifyLockReleased() {
MOZ_ASSERT(!mReleased);
mReleased = true;

Telemetry::AccumulateTimeDelta(Telemetry::SCREENWAKELOCK_HELD_DURATION_MS,
mCreationTime);

hal::BatteryInformation batteryInfo;
hal::GetCurrentBatteryInformation(&batteryInfo);
if (!batteryInfo.charging()) {
uint32_t level = static_cast<uint32_t>(100 * batteryInfo.level());
Telemetry::Accumulate(
Telemetry::SCREENWAKELOCK_RELEASE_BATTERY_LEVEL_DISCHARGING, level);
}

if (mHoldsActualLock) {
MOZ_ASSERT(mType == WakeLockType::Screen);
NS_DispatchToMainThread(NS_NewRunnableFunction("ReleaseWakeLock", []() {
Expand Down
9 changes: 6 additions & 3 deletions dom/power/WakeLockSentinel.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "js/TypeDecls.h"
#include "mozilla/Attributes.h"
#include "mozilla/DOMEventTargetHelper.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/dom/WakeLockBinding.h"

namespace mozilla::dom {
Expand All @@ -23,7 +24,9 @@ namespace mozilla::dom {
class WakeLockSentinel final : public DOMEventTargetHelper {
public:
WakeLockSentinel(nsIGlobalObject* aOwnerWindow, WakeLockType aType)
: DOMEventTargetHelper(aOwnerWindow), mType(aType) {}
: DOMEventTargetHelper(aOwnerWindow),
mType(aType),
mCreationTime(TimeStamp::Now()) {}

protected:
~WakeLockSentinel() {
Expand Down Expand Up @@ -67,8 +70,8 @@ class WakeLockSentinel final : public DOMEventTargetHelper {
*/
bool mHoldsActualLock = false;

// Time when this object was created / the wake lock acquired.
TimeStamp mAcquireTime;
// Time when this object was created
TimeStamp mCreationTime;
};

} // namespace mozilla::dom
Expand Down
24 changes: 24 additions & 0 deletions toolkit/components/telemetry/Histograms.json
Original file line number Diff line number Diff line change
Expand Up @@ -18173,5 +18173,29 @@
"record_in_processes": ["all"],
"labels": ["inits"],
"releaseChannelCollection": "opt-out"
},
"SCREENWAKELOCK_HELD_DURATION_MS": {
"record_in_processes": ["content"],
"products": ["firefox"],
"alert_emails": ["[email protected]"],
"expires_in_version": "never",
"kind": "exponential",
"low": 240000,
"high": 28800000,
"n_buckets": 50,
"bug_numbers": [1589554],
"description": "How long a screen wake lock was held in ms"
},
"SCREENWAKELOCK_RELEASE_BATTERY_LEVEL_DISCHARGING": {
"record_in_processes": ["content"],
"products": ["firefox"],
"alert_emails": ["[email protected]"],
"expires_in_version": "never",
"kind": "linear",
"low": 1,
"high": 100,
"n_buckets": 50,
"bug_numbers": [1589554],
"description": "Battery level when discharging and the wake lock was released"
}
}

0 comments on commit 3665f97

Please sign in to comment.