StormByte 2.0.0
C++26 foundation 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.
5 *
6 * StormByte 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 source in this repository.
20 * They do not cover other StormByte modules or any third-party material
21 * shipped with this repository (including everything under thirdparty/),
22 * which remains under its own license.
23 *
24 * Neither license grants any patent rights. Any patent licenses required
25 * to use this software or third-party components must be obtained separately
26 * from the patent holders.
27 *
28 * StormByte is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU Lesser General Public License for more details.
32 *
33 * You should have received a copy of the GNU Lesser General Public License
34 * version 3 along with StormByte. If not, see
35 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
36 *
37 * SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-StormByte-Commercial
38 */
39
40#pragma once
41
43#include <StormByte/platform.h>
46
47#include <chrono>
48#include <cstdint>
49#include <optional>
50#include <string>
51#include <string_view>
52
57namespace StormByte {
68 class STORMBYTE_PUBLIC Clock final {
69 public:
73 Clock() noexcept;
74
78 Clock(const Clock&) = delete;
79
83 Clock(Clock&&) noexcept;
84
89 Clock& operator=(const Clock&) = delete;
90
95 Clock& operator=(Clock&&) noexcept;
96
100 ~Clock() noexcept;
101
108 void Start() noexcept;
109
116 void Stop() noexcept;
117
122 std::uint64_t Count() const noexcept;
123
128 std::chrono::microseconds Time() const noexcept;
129
134 std::chrono::microseconds MeanDuration() const noexcept;
135
136 private:
137 std::optional<std::chrono::steady_clock::time_point> m_start;
138 std::chrono::microseconds m_time;
139 std::uint64_t m_count;
140 };
141
151 public:
155 virtual ~Telemetry() noexcept;
156
161 virtual operator Safe::String() const = 0;
162
167 STORMBYTE_FORCE_INLINE operator std::string() const {
168 return static_cast<std::string>(static_cast<Safe::String>(*this));
169 }
170
171 protected:
175 Telemetry() noexcept;
176
180 Telemetry(const Telemetry&) = delete;
181
186 Telemetry(Telemetry&& other) noexcept;
187
192 Telemetry& operator=(const Telemetry&) = delete;
193
199 Telemetry& operator=(Telemetry&& other) noexcept;
200
206 class Clock& Clock(std::string_view name) noexcept;
207
213 const class Clock& Clock(std::string_view name) const noexcept;
214
215 private:
216 struct Store;
217 Safe::Unique<Store> m_store;
218 };
219}
Stopwatch for measuring execution time of operations.
Definition telemetry.hxx:68
Clock() noexcept
Construct zeroed clock counters.
Owned UTF-8 text composed of StormByte::Safe::CString.
Definition string.hxx:97
Abstract session telemetry base with a protected clock drawer.
Definition telemetry.hxx:150
Telemetry() noexcept
Construct an empty telemetry drawer.
virtual ~Telemetry() noexcept
Virtual destructor.
Root namespace of the StormByte suite.
STL namespace.
#define STORMBYTE_FORCE_INLINE
Definition platform.h:89
DLL-safe shared and unique owners.
#define STORMBYTE_PUBLIC
Definition visibility.h:52