Cockatrice/libcockatrice_protocol/libcockatrice/protocol/pending_command.cpp
Lukas Brübach eddbbf2d7b [Network] Measure real server round-trip times
Time each command container from send to response with QElapsedTimer,
aggregate samples in a fixed-size ring buffer (last/median/p95/max),
and emit aggregated pingStatsUpdated at most once per second so the
hot path stays free of signal traffic. Stats are cleared on
disconnect. Forward the signal through ConnectionController for UI
consumers. Unit-tested in latency_tracker_test.

Took 37 minutes

Took 4 minutes

# Commit time for manual adjustment:
# Took 8 minutes
2026-08-22 19:10:37 +02:00

41 lines
823 B
C++

#include "pending_command.h"
PendingCommand::PendingCommand(const CommandContainer &_commandContainer, QVariant _extraData)
: commandContainer(_commandContainer), extraData(_extraData), ticks(0)
{
}
CommandContainer &PendingCommand::getCommandContainer()
{
return commandContainer;
}
void PendingCommand::setExtraData(const QVariant &_extraData)
{
extraData = _extraData;
}
QVariant PendingCommand::getExtraData() const
{
return extraData;
}
void PendingCommand::processResponse(const Response &response)
{
emit finished(response, commandContainer, extraData);
}
int PendingCommand::tick()
{
return ++ticks;
}
void PendingCommand::startTiming()
{
startTime.start();
}
qint64 PendingCommand::elapsedMs() const
{
return startTime.isValid() ? startTime.nsecsElapsed() / 1000000 : -1;
}