QtCraft API C++ classes QML types Handbook

QcTickPhaseTimer Class

Permanent, cheap phase counters of the server tick (decision E-225): one monotonic clock read per phase, no allocation per tick. More...

Header: #include <server/tick/QcTickPhaseTimer.h>

Public Types

class MessageScope
Clock
Durations

Public Functions

void addMessageTime(qint64 ns)
void beginTick()
void endTick(qint64 lateNs)
void lap(QcTickPhase phase)
const QcTickPhaseTimer::Durations &lastTick() const
qint64 now() const
std::optional<QString> stall(qint64 limitNs) const
const QcPhaseWindow &window() const

Static Public Members

const int durationSeries
const int lateSeries
const int seriesCount
qint64 steadyNow()
const int windowTicks

Detailed Description

The time since the previous lap goes to the phase named by lap(), so the phases of a tick add up to its duration; the time spent on client messages between ticks is collected separately. The latest ticks stay in a window (mean and maximum per phase, the tick's duration and lateness) for the debug display. Lives in the server's thread; not thread-safe, except stall(), which other threads may call (tick watchdog, decision E-834).

Member Type Documentation

[alias] QcTickPhaseTimer::Clock

Monotonic time in nanoseconds; replaceable for tests.

[alias] QcTickPhaseTimer::Durations

Nanoseconds per phase of one tick.

Member Function Documentation

void QcTickPhaseTimer::addMessageTime(qint64 ns)

Adds ns spent handling client messages outside the tick.

void QcTickPhaseTimer::beginTick()

Begins a tick: the phase durations start at zero and the first lap starts now.

void QcTickPhaseTimer::endTick(qint64 lateNs)

Ends the tick that started lateNs after it was due: the message time collected since the previous tick joins it, and the tick enters the window.

void QcTickPhaseTimer::lap(QcTickPhase phase)

The time since beginTick() or the previous lap belongs to phase (a phase may get several laps).

const QcTickPhaseTimer::Durations &QcTickPhaseTimer::lastTick() const

Returns the nanoseconds per phase of the last finished tick.

qint64 QcTickPhaseTimer::now() const

Returns the clock's time in nanoseconds.

std::optional<QString> QcTickPhaseTimer::stall(qint64 limitNs) const

Returns, when the tick running now has run for longer than limitNs, a line with how long and the phase that finished last (the next one hangs); std::nullopt between ticks or before the limit. Safe from any thread.

[static] qint64 QcTickPhaseTimer::steadyNow()

Returns the steady clock's time in nanoseconds (the default clock).

const QcPhaseWindow &QcTickPhaseTimer::window() const

Returns the window of the latest ticks.

Member Variable Documentation

const int QcTickPhaseTimer::windowTicks

Five seconds of ticks.