diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /tools/performance/PerfStats.h | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | tools/performance/PerfStats.h | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/tools/performance/PerfStats.h b/tools/performance/PerfStats.h new file mode 100644 index 0000000000..68ebfc3a57 --- /dev/null +++ b/tools/performance/PerfStats.h @@ -0,0 +1,91 @@ +/* -*- 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/. */ + +#ifndef PerfStats_h +#define PerfStats_h + +#include "mozilla/TimeStamp.h" +#include "mozilla/StaticMutex.h" +#include "mozilla/StaticPtr.h" +#include "mozilla/MozPromise.h" +#include <memory> +#include <string> +#include <limits> + +namespace mozilla { + +class PerfStats { + public: + typedef MozPromise<nsCString, bool, true> PerfStatsPromise; + + enum class Metric : uint32_t { + DisplayListBuilding = 0, + Rasterizing, + LayerBuilding, + LayerTransactions, + Compositing, + Reflowing, + Styling, + Max + }; + + // MetricMask is a bitmask based on 'Metric', i.e. Metric::LayerBuilding (2) + // is synonymous to 1 << 2 in MetricMask. + using MetricMask = uint64_t; + + static void RecordMeasurementStart(Metric aMetric) { + if (!(sCollectionMask & (1 << static_cast<uint64_t>(aMetric)))) { + return; + } + RecordMeasurementStartInternal(aMetric); + } + + static void RecordMeasurementEnd(Metric aMetric) { + if (!(sCollectionMask & (1 << static_cast<uint64_t>(aMetric)))) { + return; + } + RecordMeasurementEndInternal(aMetric); + } + + template <Metric N> + class AutoMetricRecording { + public: + AutoMetricRecording() { PerfStats::RecordMeasurementStart(N); } + ~AutoMetricRecording() { PerfStats::RecordMeasurementEnd(N); } + }; + + static void SetCollectionMask(MetricMask aMask); + + static RefPtr<PerfStatsPromise> CollectPerfStatsJSON() { + return GetSingleton()->CollectPerfStatsJSONInternal(); + } + + static nsCString CollectLocalPerfStatsJSON() { + return GetSingleton()->CollectLocalPerfStatsJSONInternal(); + } + + private: + static PerfStats* GetSingleton(); + static void RecordMeasurementStartInternal(Metric aMetric); + static void RecordMeasurementEndInternal(Metric aMetric); + + RefPtr<PerfStatsPromise> CollectPerfStatsJSONInternal(); + nsCString CollectLocalPerfStatsJSONInternal(); + + static MetricMask sCollectionMask; + static StaticMutex sMutex; + static StaticAutoPtr<PerfStats> sSingleton; + TimeStamp mRecordedStarts[static_cast<size_t>(Metric::Max)]; + double mRecordedTimes[static_cast<size_t>(Metric::Max)]; +}; + +static_assert(1 << (static_cast<uint64_t>(PerfStats::Metric::Max) - 1) <= + std::numeric_limits<PerfStats::MetricMask>::max(), + "More metrics than can fit into sCollectionMask bitmask"); + +} // namespace mozilla + +#endif // PerfStats_h |