qt: add RPCConsole::TimeDurationField helper, call systime only once

This commit is contained in:
Jon Atack 2021-02-24 16:12:43 +01:00
parent b54a10e777
commit 4dc2fd6c37
No known key found for this signature in database
GPG key ID: 4F5721B3D0E3921D
2 changed files with 9 additions and 3 deletions

View file

@ -1120,11 +1120,12 @@ void RPCConsole::updateDetailWidget()
if (stats->nodeStats.m_bip152_highbandwidth_from) bip152_hb_settings += (bip152_hb_settings == "" ? "From" : "/From");
if (bip152_hb_settings == "") bip152_hb_settings = "No";
ui->peerHighBandwidth->setText(bip152_hb_settings);
ui->peerLastSend->setText(stats->nodeStats.nLastSend ? GUIUtil::formatDurationStr(GetSystemTimeInSeconds() - stats->nodeStats.nLastSend) : tr("never"));
ui->peerLastRecv->setText(stats->nodeStats.nLastRecv ? GUIUtil::formatDurationStr(GetSystemTimeInSeconds() - stats->nodeStats.nLastRecv) : tr("never"));
const int64_t time_now{GetSystemTimeInSeconds()};
ui->peerConnTime->setText(GUIUtil::formatDurationStr(time_now - stats->nodeStats.nTimeConnected));
ui->peerLastSend->setText(TimeDurationField(time_now, stats->nodeStats.nLastSend));
ui->peerLastRecv->setText(TimeDurationField(time_now, stats->nodeStats.nLastRecv));
ui->peerBytesSent->setText(GUIUtil::formatBytes(stats->nodeStats.nSendBytes));
ui->peerBytesRecv->setText(GUIUtil::formatBytes(stats->nodeStats.nRecvBytes));
ui->peerConnTime->setText(GUIUtil::formatDurationStr(GetSystemTimeInSeconds() - stats->nodeStats.nTimeConnected));
ui->peerPingTime->setText(GUIUtil::formatPingTime(stats->nodeStats.m_ping_usec));
ui->peerMinPing->setText(GUIUtil::formatPingTime(stats->nodeStats.m_min_ping_usec));
ui->timeoffset->setText(GUIUtil::formatTimeOffset(stats->nodeStats.nTimeOffset));

View file

@ -168,6 +168,11 @@ private:
/** Update UI with latest network info from model. */
void updateNetworkState();
/** Helper for the output of a time duration field. Inputs are UNIX epoch times. */
QString TimeDurationField(uint64_t time_now, uint64_t time_at_event) const {
return time_at_event ? GUIUtil::formatDurationStr(time_now - time_at_event) : tr("Never");
}
private Q_SLOTS:
void updateAlerts(const QString& warnings);
};