gecko-dev/dom/base/TimeoutBudgetManager.h
Andreas Farre 132ec026c3 Bug 1362322 - Throttle background timeouts using budget. r=bkelly
Deduct timeout execution time from a continuously regenerating
execution budget. Then throttle timeouts by using that budget in
TimeoutManager::MinSchedulingDelay to adjust the minimum value if
the budget is negative. The minimum value is adjusted to be a
value where the budget would have regenerated to be +0 ms.

The execution budget is clamped by values in ms defined in prefs:

* dom.timeout.background_throttling_max_budget: 50
* dom.timeout.foreground_throttling_max_budget: -1

A value equal or less than 0 means that the budget is infinite.

The regeneration rate can be controlled by the following prefs:

* dom.timeout.background_budget_regeneration_rate
* dom.timeout.foreground_budget_regeneration_rate

one each for foreground and background throttling.

To not starve timeouts indefinitely we clamp the minimum delay using
the pref:

* dom.timeout.budget_throttling_max_delay: 15000

The feature is behind the pref:

* dom.timeout.enable_budget_timer_throttling
2017-07-02 18:02:38 +02:00

49 lines
1.4 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_dom_timeoutbudgetmanager_h
#define mozilla_dom_timeoutbudgetmanager_h
#include "mozilla/Telemetry.h"
#include "mozilla/TimeStamp.h"
namespace mozilla {
namespace dom {
class Timeout;
class TimeoutBudgetManager
{
public:
static TimeoutBudgetManager& Get();
void StartRecording(const TimeStamp& aNow);
void StopRecording();
TimeDuration RecordExecution(const TimeStamp& aNow,
const Timeout* aTimeout,
bool aIsBackground);
void MaybeCollectTelemetry(const TimeStamp& aNow);
private:
TimeoutBudgetManager() : mLastCollection(TimeStamp::Now()) {}
struct TelemetryData
{
TimeDuration mForegroundTracking;
TimeDuration mForegroundNonTracking;
TimeDuration mBackgroundTracking;
TimeDuration mBackgroundNonTracking;
};
void Accumulate(Telemetry::HistogramID aId, const TimeDuration& aSample);
TelemetryData mTelemetryData;
TimeStamp mStart;
TimeStamp mLastCollection;
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_timeoutbudgetmanager_h