Cockatrice 2026-09-01-Development-3.1.0-beta.10
A virtual tabletop for multiplayer card games
Loading...
Searching...
No Matches
lag_monitor.h
Go to the documentation of this file.
1
5
6#ifndef LAG_MONITOR_H
7#define LAG_MONITOR_H
8
9#include <QDateTime>
10#include <QElapsedTimer>
11#include <QList>
12#include <QLoggingCategory>
13#include <QObject>
14
15inline Q_LOGGING_CATEGORY(LagMonitorLog, "lag_monitor");
16
17class QEvent;
18class QTimer;
19
36class LagMonitor : public QObject
37{
38 Q_OBJECT
39
40public:
42 {
44 qint64 durationMs = 0;
46 };
47
48 static constexpr int TICK_INTERVAL_MS = 500;
49 static constexpr int STALL_THRESHOLD_MS = 2000;
50 static constexpr int MAX_RECORDED_STALLS = 32;
51
53 static constexpr qint64 MAX_PLAUSIBLE_STALL_MS = 600000;
54
55 explicit LagMonitor(QObject *parent = nullptr);
56
63 QList<StallRecord> recentStalls() const;
64
65 void clearStalls();
66
73 void recordGap(qint64 gapMs);
74
75protected:
76 bool eventFilter(QObject *obj, QEvent *event) override;
77
78private slots:
79 void checkTick();
80
81private:
82 QTimer *timer;
83 QElapsedTimer tickClock;
84 QList<StallRecord> stalls;
85};
86
87#endif
QList< StallRecord > recentStalls() const
Stalls recorded during this session, oldest first.
Definition lag_monitor.cpp:18
void checkTick()
Definition lag_monitor.cpp:38
LagMonitor(QObject *parent=nullptr)
Definition lag_monitor.cpp:7
QElapsedTimer tickClock
monotonic clock, so wall clock steps do not fabricate stalls
Definition lag_monitor.h:83
void recordGap(qint64 gapMs)
Feeds a measured tick-to-tick gap through the detection logic.
Definition lag_monitor.cpp:43
bool eventFilter(QObject *obj, QEvent *event) override
Definition lag_monitor.cpp:28
static constexpr int MAX_RECORDED_STALLS
Definition lag_monitor.h:50
QList< StallRecord > stalls
Definition lag_monitor.h:84
void clearStalls()
Definition lag_monitor.cpp:23
static constexpr qint64 MAX_PLAUSIBLE_STALL_MS
Gaps beyond this are treated as suspend artifacts rather than stalls.
Definition lag_monitor.h:53
QTimer * timer
Definition lag_monitor.h:82
static constexpr int STALL_THRESHOLD_MS
Definition lag_monitor.h:49
static constexpr int TICK_INTERVAL_MS
Definition lag_monitor.h:48
Q_LOGGING_CATEGORY(LagMonitorLog, "lag_monitor")
Definition lag_monitor.h:42
qint64 durationMs
Definition lag_monitor.h:44
qint64 timestampMsSinceEpoch
when the stalled period ended
Definition lag_monitor.h:43