Backed out changeset b71c8c052463 (bug 1943846) for causing mass failures. CLOSED...
[gecko.git] / tools / profiler / public / ProfilerBandwidthCounter.h
blobb9fb4a5aa2b1c7f9a71617fc812bcec58cb5dc29
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
10 namespace mozilla {
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
17 #else
19 # include "mozilla/ProfilerMarkers.h"
20 # include "mozilla/ProfilerCounts.h"
22 class ProfilerBandwidthCounter final : public AtomicProfilerCount {
23 public:
24 ProfilerBandwidthCounter()
25 : AtomicProfilerCount("bandwidth", &mCounter, &mNumber, "Bandwidth",
26 "Amount of data transfered") {
27 Register();
30 void Register() {
31 profiler_add_sampled_counter(this);
32 mRegistered = true;
35 bool IsRegistered() { return mRegistered; }
36 void MarkUnregistered() { mRegistered = false; }
38 void Add(int64_t aNumber) {
39 if (!mRegistered) {
40 Register();
42 mCounter += aNumber;
43 mNumber++;
46 ProfilerAtomicSigned mCounter;
47 ProfilerAtomicUnsigned mNumber;
48 bool mRegistered;
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) {
61 if (aRead) {
62 aWriter.IntProperty("read", aRead);
64 if (aWritten) {
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);
76 return schema;
80 } // namespace geckoprofiler::markers
82 void profiler_count_bandwidth_bytes(int64_t aCount);
84 namespace mozilla {
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