Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 : /* This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #ifndef mozilla_dom_timeoutbudgetmanager_h
8 : #define mozilla_dom_timeoutbudgetmanager_h
9 :
10 : #include "mozilla/Telemetry.h"
11 : #include "mozilla/TimeStamp.h"
12 :
13 : namespace mozilla {
14 : namespace dom {
15 :
16 : class Timeout;
17 :
18 : class TimeoutBudgetManager
19 : {
20 : public:
21 : static TimeoutBudgetManager& Get();
22 : void StartRecording(const TimeStamp& aNow);
23 : void StopRecording();
24 : TimeDuration RecordExecution(const TimeStamp& aNow,
25 : const Timeout* aTimeout,
26 : bool aIsBackground);
27 : void MaybeCollectTelemetry(const TimeStamp& aNow);
28 : private:
29 1 : TimeoutBudgetManager() : mLastCollection(TimeStamp::Now()) {}
30 1 : struct TelemetryData
31 : {
32 : TimeDuration mForegroundTracking;
33 : TimeDuration mForegroundNonTracking;
34 : TimeDuration mBackgroundTracking;
35 : TimeDuration mBackgroundNonTracking;
36 : };
37 :
38 : void Accumulate(Telemetry::HistogramID aId, const TimeDuration& aSample);
39 :
40 : TelemetryData mTelemetryData;
41 : TimeStamp mStart;
42 : TimeStamp mLastCollection;
43 : };
44 :
45 : } // namespace dom
46 : } // namespace mozilla
47 :
48 : #endif // mozilla_dom_timeoutbudgetmanager_h
|