From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- tools/profiler/public/ProfilerBandwidthCounter.h | 106 +++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 tools/profiler/public/ProfilerBandwidthCounter.h (limited to 'tools/profiler/public/ProfilerBandwidthCounter.h') diff --git a/tools/profiler/public/ProfilerBandwidthCounter.h b/tools/profiler/public/ProfilerBandwidthCounter.h new file mode 100644 index 0000000000..c83fd02f32 --- /dev/null +++ b/tools/profiler/public/ProfilerBandwidthCounter.h @@ -0,0 +1,106 @@ +/* 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 ProfilerBandwidthCounter_h +#define ProfilerBandwidthCounter_h + +#ifndef MOZ_GECKO_PROFILER + +namespace mozilla { + +inline void profiler_count_bandwidth_read_bytes(int64_t aCount) {} +inline void profiler_count_bandwidth_written_bytes(int64_t aCount) {} + +} // namespace mozilla + +#else + +# include "mozilla/ProfilerMarkers.h" +# include "mozilla/ProfilerCounts.h" + +class ProfilerBandwidthCounter final : public BaseProfilerCount { + public: + ProfilerBandwidthCounter() + : BaseProfilerCount("bandwidth", &mCounter, &mNumber, "Bandwidth", + "Amount of data transfered") { + Register(); + } + + void Register() { + profiler_add_sampled_counter(this); + mRegistered = true; + } + + bool IsRegistered() { return mRegistered; } + void MarkUnregistered() { mRegistered = false; } + + void Add(int64_t aNumber) { + if (!mRegistered) { + Register(); + } + mCounter += aNumber; + mNumber++; + } + + ProfilerAtomicSigned mCounter; + ProfilerAtomicUnsigned mNumber; + bool mRegistered; +}; + +namespace geckoprofiler::markers { + +using namespace mozilla; + +struct NetworkIOMarker { + static constexpr Span MarkerTypeName() { + return MakeStringSpan("NetIO"); + } + static void StreamJSONMarkerData(baseprofiler::SpliceableJSONWriter& aWriter, + int64_t aRead, int64_t aWritten) { + if (aRead) { + aWriter.IntProperty("read", aRead); + } + if (aWritten) { + aWriter.IntProperty("written", aWritten); + } + } + + static MarkerSchema MarkerTypeDisplay() { + using MS = MarkerSchema; + MS schema{MS::Location::MarkerChart, MS::Location::MarkerTable}; + + schema.AddKeyLabelFormat("read", "Read", MS::Format::Bytes); + schema.AddKeyLabelFormat("written", "Written", MS::Format::Bytes); + + return schema; + } +}; + +} // namespace geckoprofiler::markers + +void profiler_count_bandwidth_bytes(int64_t aCount); + +namespace mozilla { + +inline void profiler_count_bandwidth_read_bytes(int64_t aCount) { + if (MOZ_UNLIKELY(profiler_feature_active(ProfilerFeature::Bandwidth))) { + profiler_count_bandwidth_bytes(aCount); + } + // This marker will appear on the Socket Thread. + PROFILER_MARKER("Read", NETWORK, {}, NetworkIOMarker, aCount, 0); +} + +inline void profiler_count_bandwidth_written_bytes(int64_t aCount) { + if (MOZ_UNLIKELY(profiler_feature_active(ProfilerFeature::Bandwidth))) { + profiler_count_bandwidth_bytes(aCount); + } + // This marker will appear on the Socket Thread. + PROFILER_MARKER("Write", NETWORK, {}, NetworkIOMarker, 0, aCount); +} + +} // namespace mozilla + +#endif // !MOZ_GECKO_PROFILER + +#endif // ProfilerBandwidthCounter_h -- cgit v1.2.3