![]() |
Cockatrice 2026-09-01-Development-3.1.0-beta.10
A virtual tabletop for multiplayer card games
|
Detects main-thread event loop stalls ("UI freezes") from the inside. More...
#include <lag_monitor.h>
Classes | |
| struct | StallRecord |
Public Member Functions | |
| LagMonitor (QObject *parent=nullptr) | |
| QList< StallRecord > | recentStalls () const |
| Stalls recorded during this session, oldest first. | |
| void | clearStalls () |
| void | recordGap (qint64 gapMs) |
| Feeds a measured tick-to-tick gap through the detection logic. | |
Static Public Attributes | |
| static constexpr int | TICK_INTERVAL_MS = 500 |
| static constexpr int | STALL_THRESHOLD_MS = 2000 |
| static constexpr int | MAX_RECORDED_STALLS = 32 |
| static constexpr qint64 | MAX_PLAUSIBLE_STALL_MS = 600000 |
| Gaps beyond this are treated as suspend artifacts rather than stalls. | |
Protected Member Functions | |
| bool | eventFilter (QObject *obj, QEvent *event) override |
Private Slots | |
| void | checkTick () |
Private Attributes | |
| QTimer * | timer |
| QElapsedTimer | tickClock |
| monotonic clock, so wall clock steps do not fabricate stalls | |
| QList< StallRecord > | stalls |
Detects main-thread event loop stalls ("UI freezes") from the inside.
A timer is expected to fire every TICK_INTERVAL_MS of wall time. When the observed gap greatly exceeds that interval, some other task blocked the event loop for roughly the overshooting duration. This is what separates "my client froze" from "the network is lagging" in user reports.
Gaps that span an application state change (suspend, minimize, focus loss) are discarded, and implausibly huge gaps are dropped, so operating system power events do not fabricate stalls. This handling is load-bearing on Windows, where the monotonic clock used by Qt counts sleep time.
Healthy operation costs one timer wakeup per tick and two integer comparisons. Allocations happen only when a stall is actually recorded.
|
explicit |
|
privateslot |
| void LagMonitor::clearStalls | ( | ) |
|
overrideprotected |
| QList< LagMonitor::StallRecord > LagMonitor::recentStalls | ( | ) | const |
Stalls recorded during this session, oldest first.
Intended consumers are log output and the diagnostics export. The list holds at most MAX_RECORDED_STALLS entries.
| void LagMonitor::recordGap | ( | qint64 | gapMs | ) |
Feeds a measured tick-to-tick gap through the detection logic.
Split out of checkTick so threshold, plausibility, and trim behavior stay unit-testable without real timing.
|
staticconstexpr |
Gaps beyond this are treated as suspend artifacts rather than stalls.
|
staticconstexpr |
|
staticconstexpr |
|
private |
|
staticconstexpr |
|
private |
monotonic clock, so wall clock steps do not fabricate stalls
|
private |