StormByte-Buffer 4.0.0
C++26 buffer module of the StormByte suite
Loading...
Searching...
No Matches
telemetry.hxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024-2026 David C. Manuelda (StormBytePP)
3 *
4 * This file is part of StormByte-Buffer.
5 *
6 * StormByte-Buffer original source is dual-licensed:
7 *
8 * 1. GNU Lesser General Public License v3.0 (or later)
9 * You may redistribute and/or modify this file under the terms of the
10 * GNU Lesser General Public License as published by the Free Software
11 * Foundation, either version 3 of the License, or (at your option)
12 * any later version.
13 *
14 * 2. Commercial license
15 * Alternatively, this file may be used under the terms of a commercial
16 * license agreement with the copyright holder
17 * (David C. Manuelda <StormByte@gmail.com>).
18 *
19 * Both licenses apply only to original StormByte-Buffer source in this
20 * repository. They do not cover other StormByte modules or any third-party
21 * material shipped with this repository (including everything under
22 * thirdparty/, and in particular the bundled StormByte-Logger tree and
23 * the rest of the StormByte suite it vendors), which remains under its own
24 * license.
25 *
26 * Neither license grants any patent rights. Any patent licenses required
27 * to use this software or third-party components must be obtained separately
28 * from the patent holders.
29 *
30 * StormByte-Buffer is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU Lesser General Public License for more details.
34 *
35 * You should have received a copy of the GNU Lesser General Public License
36 * version 3 along with StormByte-Buffer. If not, see
37 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
38 *
39 * SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-StormByte-Commercial
40 */
41
42#pragma once
43
44#include <StormByte/type_traits/safe.hxx>
45
47#include <StormByte/byte_size.hxx>
48#include <StormByte/safe/string.hxx>
49#include <StormByte/telemetry.hxx>
50#include <StormByte/type_traits.hxx>
51
52#include <atomic>
53#include <chrono>
54#include <cstdint>
55#include <string_view>
56#include <string>
57
62namespace StormByte {
67 namespace Buffer {
71 class Bridge;
72
94 public:
101 public:
119
124
129 void Commit(StormByte::ByteSize bytes) noexcept;
130
131 private:
132 friend class Telemetry;
133
138 explicit OperationSample(Telemetry& owner) noexcept;
139
143 Telemetry& m_owner;
147 StormByte::Clock::Sample m_sample;
151 StormByte::ByteSize m_bytes {0};
155 bool m_committed {false};
156 };
157
161 virtual ~Telemetry() noexcept;
162
169 StormByte::ByteSize MeanRate() const noexcept;
170
176
181 virtual operator StormByte::Safe::String() const = 0;
182
187 STORMBYTE_FORCE_INLINE operator std::string() const {
188 return static_cast<std::string>(static_cast<StormByte::Safe::String>(*this));
189 }
190
191 protected:
195 Telemetry() noexcept;
196
200 Telemetry(const Telemetry&) = delete;
204 Telemetry(Telemetry&&) = delete;
208 Telemetry& operator=(const Telemetry&) = delete;
212 Telemetry& operator=(Telemetry&&) = delete;
213
219 void RecordOperation(StormByte::ByteSize bytes, std::chrono::microseconds elapsed) noexcept;
220
221 private:
222 friend class Bridge;
223
227 std::atomic<std::uint64_t> m_rate_bytes;
231 std::atomic<std::uint64_t> m_op_us;
235 std::atomic<std::uint64_t> m_mean_rate;
236 };
237
243 public:
247 ReadTelemetry() noexcept;
248
252 ReadTelemetry(const ReadTelemetry&) = delete;
257
261 virtual ~ReadTelemetry() noexcept override;
262
266 ReadTelemetry& operator=(const ReadTelemetry&) = delete;
270 ReadTelemetry& operator=(ReadTelemetry&&) = delete;
271
276 StormByte::ByteSize Delivered() const noexcept;
277
282 operator StormByte::Safe::String() const override;
283
284 protected:
285 friend class Bridge;
286
291 };
292
298 public:
302 WriteTelemetry() noexcept;
303
312
316 virtual ~WriteTelemetry() noexcept override;
317
321 WriteTelemetry& operator=(const WriteTelemetry&) = delete;
325 WriteTelemetry& operator=(WriteTelemetry&&) = delete;
326
331 StormByte::ByteSize Accepted() const noexcept;
332
337 operator StormByte::Safe::String() const override;
338
339 protected:
340 friend class Bridge;
341
346 };
347 }
348}
349
356
368STORMBYTE_DECLARE_MAYBE_SAFE(StormByte::Buffer::Telemetry::OperationSample);
Manual bridge between two StormByte-Buffer ends.
Definition bridge.hxx:129
friend class Bridge
Definition telemetry.hxx:285
StormByte::ByteSize Delivered() const noexcept
Octets delivered to the caller.
ReadTelemetry() noexcept
Construct all counters at 0.
StormByte::ByteSize m_delivered
Octets delivered.
Definition telemetry.hxx:290
operator StormByte::Safe::String() const override
Flatten base read counters.
Measures one operation with an independent Base clock sample.
Definition telemetry.hxx:100
void Commit(StormByte::ByteSize bytes) noexcept
Includes this sample in the rate calculation.
friend class Telemetry
Definition telemetry.hxx:132
OperationSample(OperationSample &&other) noexcept
Transfers the active sample.
~OperationSample() noexcept
Stops the sample and records a committed operation.
OperationSample & operator=(const OperationSample &)=delete
Copy assignment is disabled.
OperationSample & operator=(OperationSample &&)=delete
Move assignment is disabled.
OperationSample(const OperationSample &)=delete
Copy construction is disabled.
virtual ~Telemetry() noexcept
Virtual destructor.
StormByte::ByteSize MeanRate() const noexcept
Effective mean rate of requested user operations.
void RecordOperation(StormByte::ByteSize bytes, std::chrono::microseconds elapsed) noexcept
Accumulate committed bytes and duration from a Base sample.
friend class Bridge
Definition telemetry.hxx:222
OperationSample MeasureOperation() noexcept
Starts an independent measurement on the aggregate operation clock.
Telemetry() noexcept
Construct all counters at 0.
virtual operator StormByte::Safe::String() const =0
Flatten counters.
operator StormByte::Safe::String() const override
Flatten base write counters.
friend class Bridge
Definition telemetry.hxx:340
StormByte::ByteSize Accepted() const noexcept
Octets accepted by a successful write.
WriteTelemetry() noexcept
Construct all counters at 0.
StormByte::ByteSize m_accepted
Octets accepted.
Definition telemetry.hxx:345
class Clock & Clock(std::string_view name)
STORMBYTE_DECLARE_MAYBE_SAFE(class StormByte::System::Device::Access)
Buffer module of the StormByte suite.
Root namespace of the StormByte C++ suite.
STL namespace.
#define STORMBYTE_FORCE_INLINE
#define STORMBYTE_BUFFER_PUBLIC
Definition visibility.h:54