diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:44:51 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-21 11:44:51 +0000 |
commit | 9e3c08db40b8916968b9f30096c7be3f00ce9647 (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /layout/base/LayoutTelemetryTools.h | |
parent | Initial commit. (diff) | |
download | thunderbird-upstream.tar.xz thunderbird-upstream.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'layout/base/LayoutTelemetryTools.h')
-rw-r--r-- | layout/base/LayoutTelemetryTools.h | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/layout/base/LayoutTelemetryTools.h b/layout/base/LayoutTelemetryTools.h new file mode 100644 index 0000000000..25c80dcc2c --- /dev/null +++ b/layout/base/LayoutTelemetryTools.h @@ -0,0 +1,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, LayoutSubsystem::Count, double>; +using LayoutFlushCount = + EnumeratedArray<FlushKind, FlushKind::Count, SaturateUint8>; + +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 |