summaryrefslogtreecommitdiffstats
path: root/layout/base/LayoutTelemetryTools.h
blob: 43eee799239f4c0ef0f13b14cb960197e0d96654 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */

/* Tools for collecting and reporting layout and style telemetry */

#ifndef mozilla_LayoutTelemetryTools_h
#define mozilla_LayoutTelemetryTools_h

#include "mozilla/EnumeratedArray.h"
#include "mozilla/EnumeratedRange.h"
#include "mozilla/FlushType.h"
#include "mozilla/Saturate.h"
#include "mozilla/TimeStamp.h"

#define LAYOUT_TELEMETRY_RECORD(subsystem) \
  layout_telemetry::AutoRecord a(layout_telemetry::LayoutSubsystem::subsystem)

#define LAYOUT_TELEMETRY_RECORD_BASE(subsystem)     \
  layout_telemetry::AutoRecord a(&mLayoutTelemetry, \
                                 layout_telemetry::LayoutSubsystem::subsystem)

namespace mozilla {
namespace layout_telemetry {

enum class FlushKind : uint8_t { Style, Layout, Count };

enum class LayoutSubsystem : uint8_t {
  Restyle,
  Reflow,
  ReflowFlex,
  ReflowGrid,
  ReflowTable,
  ReflowText,
  Count
};

using LayoutSubsystemDurations =
    EnumeratedArray<LayoutSubsystem, double, size_t(LayoutSubsystem::Count)>;
using LayoutFlushCount =
    EnumeratedArray<FlushKind, SaturateUint8, size_t(FlushKind::Count)>;

struct Data {
  Data();

  void IncReqsPerFlush(FlushType aFlushType);
  void IncFlushesPerTick(FlushType aFlushType);

  void PingTelemetry();

  // Send the current number of flush requests for aFlushType to telemetry and
  // reset the count.
  void PingReqsPerFlushTelemetry(FlushType aFlushType);

  // Send the current non-zero number of style and layout flushes to telemetry
  // and reset the count.
  void PingFlushPerTickTelemetry(FlushType aFlushType);

  // Send the current non-zero time spent under style and layout processing this
  // tick to telemetry and reset the total.
  void PingTotalMsPerTickTelemetry(FlushType aFlushType);

  // Send the current per-tick telemetry for `aFlushType`.
  void PingPerTickTelemetry(FlushType aFlushType);

  LayoutFlushCount mReqsPerFlush;
  LayoutFlushCount mFlushesPerTick;
  LayoutSubsystemDurations mLayoutSubsystemDurationMs;
};

class AutoRecord {
 public:
  explicit AutoRecord(LayoutSubsystem aSubsystem);
  AutoRecord(Data* aLayoutTelemetry, LayoutSubsystem aSubsystem);
  ~AutoRecord();

 private:
  AutoRecord* mParentRecord;
  Data* mLayoutTelemetry;
  LayoutSubsystem mSubsystem;
  TimeStamp mStartTime;
  double mDurationMs;
};

}  // namespace layout_telemetry
}  // namespace mozilla

#endif  // !mozilla_LayoutTelemetryTools_h