1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef ProfilerBandwidthCounter_h
6 #define ProfilerBandwidthCounter_h
8 #ifndef MOZ_GECKO_PROFILER
12 inline void profiler_count_bandwidth_read_bytes(int64_t aCount
) {}
13 inline void profiler_count_bandwidth_written_bytes(int64_t aCount
) {}
15 } // namespace mozilla
19 # include "mozilla/ProfilerMarkers.h"
20 # include "mozilla/ProfilerCounts.h"
22 class ProfilerBandwidthCounter final
: public AtomicProfilerCount
{
24 ProfilerBandwidthCounter()
25 : AtomicProfilerCount("bandwidth", &mCounter
, &mNumber
, "Bandwidth",
26 "Amount of data transfered") {
31 profiler_add_sampled_counter(this);
35 bool IsRegistered() { return mRegistered
; }
36 void MarkUnregistered() { mRegistered
= false; }
38 void Add(int64_t aNumber
) {
46 ProfilerAtomicSigned mCounter
;
47 ProfilerAtomicUnsigned mNumber
;
51 namespace geckoprofiler::markers
{
53 using namespace mozilla
;
55 struct NetworkIOMarker
{
56 static constexpr Span
<const char> MarkerTypeName() {
57 return MakeStringSpan("NetIO");
59 static void StreamJSONMarkerData(baseprofiler::SpliceableJSONWriter
& aWriter
,
60 int64_t aRead
, int64_t aWritten
) {
62 aWriter
.IntProperty("read", aRead
);
65 aWriter
.IntProperty("written", aWritten
);
69 static MarkerSchema
MarkerTypeDisplay() {
70 using MS
= MarkerSchema
;
71 MS schema
{MS::Location::MarkerChart
, MS::Location::MarkerTable
};
73 schema
.AddKeyLabelFormat("read", "Read", MS::Format::Bytes
);
74 schema
.AddKeyLabelFormat("written", "Written", MS::Format::Bytes
);
80 } // namespace geckoprofiler::markers
82 void profiler_count_bandwidth_bytes(int64_t aCount
);
86 inline void profiler_count_bandwidth_read_bytes(int64_t aCount
) {
87 if (MOZ_UNLIKELY(profiler_feature_active(ProfilerFeature::Bandwidth
))) {
88 profiler_count_bandwidth_bytes(aCount
);
90 // This marker will appear on the Socket Thread.
91 PROFILER_MARKER("Read", NETWORK
, {}, NetworkIOMarker
, aCount
, 0);
94 inline void profiler_count_bandwidth_written_bytes(int64_t aCount
) {
95 if (MOZ_UNLIKELY(profiler_feature_active(ProfilerFeature::Bandwidth
))) {
96 profiler_count_bandwidth_bytes(aCount
);
98 // This marker will appear on the Socket Thread.
99 PROFILER_MARKER("Write", NETWORK
, {}, NetworkIOMarker
, 0, aCount
);
102 } // namespace mozilla
104 #endif // !MOZ_GECKO_PROFILER
106 #endif // ProfilerBandwidthCounter_h