diff options
author | Simon Rettberg | 2022-07-01 14:22:20 +0200 |
---|---|---|
committer | Simon Rettberg | 2022-07-01 14:22:20 +0200 |
commit | 3eb3af1b8a63347ddfe89f5942811c07074ed5f5 (patch) | |
tree | 766747d2dd896ff5254a00d9db228e05152df5f2 | |
parent | Fix signal-slot connections by using new method (diff) | |
download | speedcheck-29r2.tar.gz speedcheck-29r2.tar.xz speedcheck-29r2.zip |
-rw-r--r-- | src/consoleworker.cpp | 28 | ||||
-rw-r--r-- | src/consoleworker.h | 4 |
2 files changed, 22 insertions, 10 deletions
diff --git a/src/consoleworker.cpp b/src/consoleworker.cpp index a869725..3335047 100644 --- a/src/consoleworker.cpp +++ b/src/consoleworker.cpp @@ -4,15 +4,18 @@ #include "datasource/networkspeed.h" #include <QFile> +#include <QDateTime> #include <QCoreApplication> #include <cstdio> ConsoleWorker::ConsoleWorker(QString fileName) : _thread(nullptr), _fileName(fileName), - _networkSource(nullptr) + _networkSource(nullptr), + _cpuLoadSource(nullptr), + _startTimeMs(0) { - _timer.setInterval(200); + _timer.setInterval(250); connect(&_timer, &QTimer::timeout, this, &ConsoleWorker::updateTimer); QTimer::singleShot(1, [this]() { QFile *file = new QFile(_fileName); @@ -21,6 +24,7 @@ ConsoleWorker::ConsoleWorker(QString fileName) : return; } _networkSource = new NetworkSpeed(); + _cpuLoadSource = new CpuLoad(); _thread = new CopyThread(file, this); connect(_thread, &CopyThread::logMessage, this, &ConsoleWorker::logMessage, Qt::QueuedConnection); connect(_thread, &CopyThread::finished, this, &ConsoleWorker::testFinished, Qt::QueuedConnection); @@ -32,18 +36,22 @@ ConsoleWorker::ConsoleWorker(QString fileName) : ConsoleWorker::~ConsoleWorker() { delete _networkSource; + delete _cpuLoadSource; } void ConsoleWorker::logMessage(CopyThread::LogMessageId msgId, QString message) { - if (msgId == CopyThread::TestRandomStart) { - printf("+SEQ"); + if (msgId == CopyThread::TestSequentialStart) { + _startTimeMs = QDateTime::currentMSecsSinceEpoch(); + } else if (msgId == CopyThread::TestRandomStart) { + printf("+SEQ:%lld", (long long)_startTimeMs); + _startTimeMs = QDateTime::currentMSecsSinceEpoch(); } else if (msgId == CopyThread::TestFinished) { - printf("+RND"); + printf("+RND:%lld", (long long)_startTimeMs); } if (msgId == CopyThread::TestRandomStart || msgId == CopyThread::TestFinished) { - for (int i : _series) { - printf(",%i", i); + for (const auto& i : _series) { + printf(",%s", i.toLocal8Bit().constData()); } putchar('\n'); } @@ -61,6 +69,8 @@ void ConsoleWorker::testFinished() void ConsoleWorker::updateTimer() { - int i = (int)_networkSource->read(); - _series.append(i); + int net = (int)_networkSource->read(); + int cpu = (int)_cpuLoadSource->read(); + int t = (int)(QDateTime::currentMSecsSinceEpoch() - _startTimeMs); + _series.append(QString::asprintf("%d+%d+%d", t, net, cpu)); } diff --git a/src/consoleworker.h b/src/consoleworker.h index 276f987..0f11fda 100644 --- a/src/consoleworker.h +++ b/src/consoleworker.h @@ -28,7 +28,9 @@ private: QString _fileName; QTimer _timer; IDataSource* _networkSource; - QVector<int> _series; + IDataSource* _cpuLoadSource; + QVector<QString> _series; + qint64 _startTimeMs; }; #endif |