Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/gfx/layers/composite/Diagnostics.h
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
#ifndef mozilla_gfx_layers_composite_Diagnostics_h
8
#define mozilla_gfx_layers_composite_Diagnostics_h
9
10
#include "FPSCounter.h"
11
#include "gfxPrefs.h"
12
#include "mozilla/Maybe.h"
13
#include "mozilla/TimeStamp.h"
14
#include <deque>
15
#include <string>
16
#include <utility>
17
18
namespace mozilla {
19
namespace layers {
20
21
class PaintTiming;
22
23
class TimedMetric
24
{
25
  typedef std::pair<float, TimeStamp> Entry;
26
27
public:
28
0
  void Add(float aValue) {
29
0
    if (mHistory.size() > kMaxHistory) {
30
0
      mHistory.pop_front();
31
0
    }
32
0
    mHistory.push_back(Entry(aValue, TimeStamp::Now()));
33
0
  }
34
35
  float Average() const;
36
0
  bool Empty() const {
37
0
    return mHistory.empty();
38
0
  }
39
40
private:
41
  static const size_t kMaxHistory = 60;
42
43
  std::deque<Entry> mHistory;
44
};
45
46
// These statistics are collected by layers backends, preferably by the GPU
47
struct GPUStats
48
{
49
  GPUStats()
50
   : mInvalidPixels(0),
51
     mScreenPixels(0),
52
     mPixelsFilled(0)
53
0
  {}
54
55
  uint32_t mInvalidPixels;
56
  uint32_t mScreenPixels;
57
  uint32_t mPixelsFilled;
58
  Maybe<float> mDrawTime;
59
};
60
61
// Collects various diagnostics about layers performance.
62
class Diagnostics
63
{
64
public:
65
  Diagnostics();
66
67
  void RecordPaintTimes(const PaintTiming& aPaintTimes);
68
0
  void RecordUpdateTime(float aValue) {
69
0
    mUpdateMs.Add(aValue);
70
0
  }
71
0
  void RecordPrepareTime(float aValue) {
72
0
    mPrepareMs.Add(aValue);
73
0
  }
74
0
  void RecordCompositeTime(float aValue) {
75
0
    mCompositeMs.Add(aValue);
76
0
  }
77
0
  void AddTxnFrame() {
78
0
    mTransactionFps.AddFrame(TimeStamp::Now());
79
0
  }
80
81
  std::string GetFrameOverlayString(const GPUStats& aStats);
82
83
  class Record {
84
  public:
85
0
    explicit Record(TimeStamp aStart = TimeStamp()) {
86
0
      if (gfxPrefs::LayersDrawFPS()) {
87
0
        mStart = aStart.IsNull() ? TimeStamp::Now() : aStart;
88
0
      }
89
0
    }
90
0
    bool Recording() const {
91
0
      return !mStart.IsNull();
92
0
    }
93
0
    float Duration() const {
94
0
      return (TimeStamp::Now() - mStart).ToMilliseconds();
95
0
    }
96
97
  private:
98
    TimeStamp mStart;
99
  };
100
101
private:
102
  FPSCounter mCompositeFps;
103
  FPSCounter mTransactionFps;
104
  TimedMetric mDlbMs;
105
  TimedMetric mDlb2Ms;
106
  TimedMetric mFlbMs;
107
  TimedMetric mRasterMs;
108
  TimedMetric mSerializeMs;
109
  TimedMetric mSendMs;
110
  TimedMetric mUpdateMs;
111
  TimedMetric mPrepareMs;
112
  TimedMetric mCompositeMs;
113
  TimedMetric mGPUDrawMs;
114
};
115
116
} // namespace layers
117
} // namespace mozilla
118
119
#endif // mozilla_gfx_layers_composite_Diagnostics_h