Fix CompositeFileTransferJob speed calculation
The `QElapsedTimer` was never started. Clean it up somewhat and use a dedicated 250ms timer for reporting transferred bytes periodically (like KIO does it) and 1000ms for calculating speed so it's not as erratic. Furthermore, report final numbers in `slotResult` rather than complicating `slotProcessedAmount` for that. Also, fix typo "send" -> "sent"
This commit is contained in:
parent
daa6f7fc14
commit
8dae6772e0
2 changed files with 28 additions and 18 deletions
|
@ -17,11 +17,11 @@ CompositeFileTransferJob::CompositeFileTransferJob(const QString& deviceId)
|
||||||
, m_running(false)
|
, m_running(false)
|
||||||
, m_currentJobNum(1)
|
, m_currentJobNum(1)
|
||||||
, m_totalJobs(0)
|
, m_totalJobs(0)
|
||||||
, m_currentJobSendPayloadSize(0)
|
, m_currentJobSentPayloadSize(0)
|
||||||
, m_totalSendPayloadSize(0)
|
, m_totalSentPayloadSize(0)
|
||||||
|
, m_oldTotalSentPayloadSize(0)
|
||||||
, m_totalPayloadSize(0)
|
, m_totalPayloadSize(0)
|
||||||
, m_currentJob(nullptr)
|
, m_currentJob(nullptr)
|
||||||
, m_prevElapsedTime(0)
|
|
||||||
{
|
{
|
||||||
setCapabilities(Killable);
|
setCapabilities(Killable);
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ void CompositeFileTransferJob::start()
|
||||||
void CompositeFileTransferJob::startNextSubJob()
|
void CompositeFileTransferJob::startNextSubJob()
|
||||||
{
|
{
|
||||||
m_currentJob = qobject_cast<FileTransferJob*>(subjobs().at(0));
|
m_currentJob = qobject_cast<FileTransferJob*>(subjobs().at(0));
|
||||||
m_currentJobSendPayloadSize = 0;
|
m_currentJobSentPayloadSize = 0;
|
||||||
|
|
||||||
Q_EMIT description(this, i18ncp("@title job", "Receiving file", "Receiving files", m_totalJobs),
|
Q_EMIT description(this, i18ncp("@title job", "Receiving file", "Receiving files", m_totalJobs),
|
||||||
{i18nc("The source of a file operation", "Source"), Daemon::instance()->getDevice(this->m_deviceId)->name()},
|
{i18nc("The source of a file operation", "Source"), Daemon::instance()->getDevice(this->m_deviceId)->name()},
|
||||||
|
@ -95,17 +95,25 @@ bool CompositeFileTransferJob::doKill()
|
||||||
void CompositeFileTransferJob::slotProcessedAmount(KJob *job, KJob::Unit unit, qulonglong amount)
|
void CompositeFileTransferJob::slotProcessedAmount(KJob *job, KJob::Unit unit, qulonglong amount)
|
||||||
{
|
{
|
||||||
Q_UNUSED(job);
|
Q_UNUSED(job);
|
||||||
m_currentJobSendPayloadSize = amount;
|
|
||||||
quint64 uploaded = m_totalSendPayloadSize + m_currentJobSendPayloadSize;
|
|
||||||
|
|
||||||
if (uploaded == m_totalPayloadSize || m_prevElapsedTime == 0 || m_timer.elapsed() - m_prevElapsedTime >= 100) {
|
m_currentJobSentPayloadSize = amount;
|
||||||
m_prevElapsedTime = m_timer.elapsed();
|
const auto totalSent = m_totalSentPayloadSize + m_currentJobSentPayloadSize;
|
||||||
setProcessedAmount(unit, uploaded);
|
|
||||||
|
|
||||||
const auto elapsed = m_timer.elapsed();
|
if (!m_reportTimer.isValid()) {
|
||||||
if (elapsed > 0) {
|
m_reportTimer.start();
|
||||||
emitSpeed((1000 * uploaded) / elapsed);
|
|
||||||
}
|
}
|
||||||
|
if (m_reportTimer.hasExpired(250)) {
|
||||||
|
setProcessedAmount(unit, totalSent);
|
||||||
|
m_reportTimer.restart();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!m_speedTimer.isValid()) {
|
||||||
|
m_speedTimer.start();
|
||||||
|
}
|
||||||
|
if (m_speedTimer.hasExpired(1000)) {
|
||||||
|
emitSpeed(1000 * (totalSent - m_oldTotalSentPayloadSize) / m_speedTimer.elapsed());
|
||||||
|
m_oldTotalSentPayloadSize = totalSent;
|
||||||
|
m_speedTimer.restart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,8 +126,9 @@ void CompositeFileTransferJob::slotResult(KJob *job)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_totalSendPayloadSize += m_currentJobSendPayloadSize;
|
m_totalSentPayloadSize += m_currentJobSentPayloadSize;
|
||||||
|
|
||||||
|
setProcessedAmount(Bytes, m_totalSentPayloadSize);
|
||||||
setProcessedAmount(Files, m_currentJobNum);
|
setProcessedAmount(Files, m_currentJobNum);
|
||||||
|
|
||||||
if (m_currentJobNum < m_totalJobs) {
|
if (m_currentJobNum < m_totalJobs) {
|
||||||
|
|
|
@ -38,12 +38,13 @@ private:
|
||||||
bool m_running;
|
bool m_running;
|
||||||
int m_currentJobNum;
|
int m_currentJobNum;
|
||||||
int m_totalJobs;
|
int m_totalJobs;
|
||||||
quint64 m_currentJobSendPayloadSize;
|
quint64 m_currentJobSentPayloadSize;
|
||||||
quint64 m_totalSendPayloadSize;
|
quint64 m_totalSentPayloadSize;
|
||||||
|
quint64 m_oldTotalSentPayloadSize; // for speed calculation
|
||||||
quint64 m_totalPayloadSize;
|
quint64 m_totalPayloadSize;
|
||||||
FileTransferJob *m_currentJob;
|
FileTransferJob *m_currentJob;
|
||||||
QElapsedTimer m_timer;
|
QElapsedTimer m_reportTimer;
|
||||||
quint64 m_prevElapsedTime;
|
QElapsedTimer m_speedTimer;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue