78 std::atomic<std::uint64_t>
count{0};
80 std::atomic<std::uint64_t>
minTicks{std::numeric_limits<std::uint64_t>::max()};
113 std::array<ScopeSummary, k_maxScopes>
scopes{};
139extern std::atomic<bool>
enabled;
163void tickEnd(std::uint64_t tickWallNs)
noexcept;
173inline std::uint64_t
ticksToNs(std::uint64_t ticks)
noexcept
175 static const std::uint64_t k_freq = SDL_GetPerformanceFrequency();
178 return (ticks / k_freq) * 1'000'000'000ULL + ((ticks % k_freq) * 1'000'000'000ULL) / k_freq;
195 const std::uint64_t end = SDL_GetPerformanceCounter();
217#define GROUP2_PROF_CAT2(a, b) a##b
218#define GROUP2_PROF_CAT(a, b) GROUP2_PROF_CAT2(a, b)
238#define GROUP2_PROF_SCOPE(label) \
239 ::group2::perf::ScopeTimer GROUP2_PROF_CAT(_gpScope, __LINE__) \
241 []() noexcept -> ::group2::perf::ScopeId { \
242 static const ::group2::perf::ScopeId k_id = ::group2::perf::registerScope(label); \
ScopeTimer(ScopeId id) noexcept
Definition Profiler.hpp:186
std::uint64_t startCounter
Definition Profiler.hpp:207
ScopeTimer(const ScopeTimer &)=delete
ScopeId scopeId
Definition Profiler.hpp:205
bool recording
Definition Profiler.hpp:206
~ScopeTimer() noexcept
Definition Profiler.hpp:191
ScopeTimer & operator=(const ScopeTimer &)=delete
ScopeTimer & operator=(ScopeTimer &&)=delete
ScopeTimer(ScopeTimer &&)=delete
Definition Parallel.hpp:43
constexpr std::size_t k_histogramBuckets
Histogram bucket count.
Definition Profiler.hpp:56
void initFromEnv()
Initialize from environment variables.
Definition Profiler.cpp:255
std::uint64_t ticksToNs(std::uint64_t ticks) noexcept
Convenience: convert SDL performance-counter ticks to nanoseconds.
Definition Profiler.hpp:173
std::size_t scopeCount()
Returns the highest registered id + 1.
Definition Profiler.cpp:217
constexpr std::size_t k_maxScopes
Compile-time caps.
Definition Profiler.hpp:50
void recordSample(ScopeId id, std::uint64_t ticks) noexcept
Recording entry point — public so unit tests can invoke it directly without a real ScopeTimer.
Definition Profiler.cpp:222
constexpr ScopeId k_invalidScope
Definition Profiler.hpp:60
void startAggregator(std::function< void(const Snapshot &)> cb)
Spawn the 1 Hz aggregator thread.
Definition Profiler.cpp:263
void tickEnd(std::uint64_t tickWallNs) noexcept
Tick boundary marker — call once per server tick() end.
Definition Profiler.cpp:242
ScopeId registerScope(const char *name)
Register (or look up) a scope name and return its dense id.
Definition Profiler.cpp:189
void stopAggregator()
Stop the aggregator and join its thread. Idempotent.
Definition Profiler.cpp:286
std::atomic< bool > enabled
Master switch.
Definition Profiler.cpp:187
std::uint16_t ScopeId
Dense small id used to index the global stats table.
Definition Profiler.hpp:59
NetworkCounters & net()
Network counter accessor. Hot-path code increments these directly.
Definition Profiler.hpp:166
const char * scopeName(ScopeId id)
Returns the human-readable name a ScopeId was registered with, or "" if id is out of range.
Definition Profiler.cpp:209
Per-tick network counters maintained by the network code.
Definition Profiler.hpp:88
std::atomic< std::uint32_t > peakBacklog
Definition Profiler.hpp:94
std::atomic< std::uint64_t > bytesSent
Definition Profiler.hpp:89
std::atomic< std::uint32_t > clientCount
Definition Profiler.hpp:95
std::atomic< std::uint64_t > packetsSent
Definition Profiler.hpp:92
std::atomic< std::uint64_t > bytesRecv
Definition Profiler.hpp:90
std::atomic< std::uint64_t > snapshotsSent
Definition Profiler.hpp:91
std::atomic< std::uint64_t > packetsRecv
Definition Profiler.hpp:93
Per-scope, all-thread atomic counters.
Definition Profiler.hpp:77
std::atomic< std::uint64_t > maxTicks
Definition Profiler.hpp:81
std::array< std::atomic< std::uint32_t >, k_histogramBuckets > hist
Definition Profiler.hpp:82
std::atomic< std::uint64_t > minTicks
Definition Profiler.hpp:80
std::atomic< std::uint64_t > count
Definition Profiler.hpp:78
std::atomic< std::uint64_t > sumTicks
Definition Profiler.hpp:79
Per-scope summary, filled for [0, scopeCount).
Definition Profiler.hpp:103
std::uint64_t p50Ns
Definition Profiler.hpp:107
std::uint64_t count
Definition Profiler.hpp:105
std::uint64_t maxNs
Definition Profiler.hpp:109
const char * name
Definition Profiler.hpp:104
std::uint64_t p99Ns
Definition Profiler.hpp:108
std::uint64_t meanNs
Definition Profiler.hpp:110
std::uint64_t minNs
Definition Profiler.hpp:106
Globally-visible snapshot returned to the aggregator callback.
Definition Profiler.hpp:100
std::uint64_t bytesRecv
Definition Profiler.hpp:124
std::uint64_t packetsSent
Definition Profiler.hpp:126
std::uint64_t bytesSent
Network totals over the window.
Definition Profiler.hpp:123
std::uint64_t snapshotsSent
Definition Profiler.hpp:125
std::uint64_t tickP99Ns
Definition Profiler.hpp:120
std::uint64_t windowEndMs
Definition Profiler.hpp:133
std::uint64_t tickMaxNs
Definition Profiler.hpp:119
std::size_t scopeNum
Definition Profiler.hpp:114
std::uint32_t peakBacklog
Definition Profiler.hpp:128
std::uint64_t packetsRecv
Definition Profiler.hpp:127
std::array< ScopeSummary, k_maxScopes > scopes
Definition Profiler.hpp:113
std::uint64_t windowStartMs
Wall-clock window covered (POSIX millis since epoch).
Definition Profiler.hpp:132
std::uint32_t clientCount
Definition Profiler.hpp:129
std::uint64_t tickCount
Per-tick wall time over the aggregation window.
Definition Profiler.hpp:117
std::uint64_t tickSumNs
Definition Profiler.hpp:118