Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/xpcom/threads/MainThreadIdlePeriod.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
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
#include "MainThreadIdlePeriod.h"
8
9
#include "mozilla/Maybe.h"
10
#include "mozilla/Preferences.h"
11
#include "nsRefreshDriver.h"
12
#include "nsThreadUtils.h"
13
14
// The amount of idle time (milliseconds) reserved for a long idle period.
15
static const double kLongIdlePeriodMS = 50.0;
16
17
// The minimum amount of time (milliseconds) required for an idle period to be
18
// scheduled on the main thread. N.B. layout.idle_period.time_limit adds
19
// padding at the end of the idle period, which makes the point in time that we
20
// expect to become busy again be:
21
//   now + kMinIdlePeriodMS + layout.idle_period.time_limit
22
static const double kMinIdlePeriodMS = 3.0;
23
24
static const uint32_t kMaxTimerThreadBound = 5;       // milliseconds
25
static const uint32_t kMaxTimerThreadBoundClamp = 15; // milliseconds
26
27
namespace mozilla {
28
29
NS_IMETHODIMP
30
MainThreadIdlePeriod::GetIdlePeriodHint(TimeStamp* aIdleDeadline)
31
0
{
32
0
  MOZ_ASSERT(NS_IsMainThread());
33
0
  MOZ_ASSERT(aIdleDeadline);
34
0
35
0
  TimeStamp now = TimeStamp::Now();
36
0
  TimeStamp currentGuess =
37
0
    now + TimeDuration::FromMilliseconds(kLongIdlePeriodMS);
38
0
39
0
  currentGuess = nsRefreshDriver::GetIdleDeadlineHint(currentGuess);
40
0
  currentGuess = NS_GetTimerDeadlineHintOnCurrentThread(currentGuess, kMaxTimerThreadBound);
41
0
42
0
  // If the idle period is too small, then just return a null time
43
0
  // to indicate we are busy. Otherwise return the actual deadline.
44
0
  TimeDuration minIdlePeriod =
45
0
    TimeDuration::FromMilliseconds(kMinIdlePeriodMS);
46
0
  bool busySoon = currentGuess.IsNull() ||
47
0
                  (now >= (currentGuess - minIdlePeriod)) ||
48
0
                  currentGuess < mLastIdleDeadline;
49
0
50
0
  if (!busySoon) {
51
0
    *aIdleDeadline = mLastIdleDeadline = currentGuess;
52
0
  }
53
0
54
0
  return NS_OK;
55
0
}
56
57
/* static */ float
58
MainThreadIdlePeriod::GetLongIdlePeriod()
59
0
{
60
0
  return kLongIdlePeriodMS;
61
0
}
62
63
} // namespace mozilla