From 3eb3af1b8a63347ddfe89f5942811c07074ed5f5 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 1 Jul 2022 14:22:20 +0200 Subject: Output timing and CPU info too in console mode --- src/consoleworker.cpp | 28 +++++++++++++++++++--------- src/consoleworker.h | 4 +++- 2 files changed, 22 insertions(+), 10 deletions(-) (limited to 'src') 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 +#include #include #include 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 _series; + IDataSource* _cpuLoadSource; + QVector _series; + qint64 _startTimeMs; }; #endif -- cgit v1.2.3-55-g7522