summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2022-06-22 16:44:30 +0200
committerSimon Rettberg2022-06-22 16:44:30 +0200
commit880fbb84acf853be8ac0c5a23ff0475e8ce6dff0 (patch)
tree5869e19b02f5698ed7c47cf9a8240fc46e37bc71
parentSet maximum to ~120MB/s, about matches theoretical maximum of GBit NIC (diff)
downloadspeedcheck-880fbb84acf853be8ac0c5a23ff0475e8ce6dff0.tar.gz
speedcheck-880fbb84acf853be8ac0c5a23ff0475e8ce6dff0.tar.xz
speedcheck-880fbb84acf853be8ac0c5a23ff0475e8ce6dff0.zip
Add --console mode, to be used remotely
-rw-r--r--src/consoleworker.cpp66
-rw-r--r--src/consoleworker.h34
-rw-r--r--src/copythread.cpp10
-rw-r--r--src/copythread.h12
-rw-r--r--src/main.cpp38
-rw-r--r--src/speedcheck.cpp4
-rw-r--r--src/speedcheck.h3
-rw-r--r--src/ui/speedcheck.ui13
8 files changed, 156 insertions, 24 deletions
diff --git a/src/consoleworker.cpp b/src/consoleworker.cpp
new file mode 100644
index 0000000..a869725
--- /dev/null
+++ b/src/consoleworker.cpp
@@ -0,0 +1,66 @@
+#include "consoleworker.h"
+#include "copythread.h"
+#include "datasource/cpuload.h"
+#include "datasource/networkspeed.h"
+
+#include <QFile>
+#include <QCoreApplication>
+#include <cstdio>
+
+ConsoleWorker::ConsoleWorker(QString fileName) :
+ _thread(nullptr),
+ _fileName(fileName),
+ _networkSource(nullptr)
+{
+ _timer.setInterval(200);
+ connect(&_timer, &QTimer::timeout, this, &ConsoleWorker::updateTimer);
+ QTimer::singleShot(1, [this]() {
+ QFile *file = new QFile(_fileName);
+ if (!file->open(QIODevice::ReadOnly)) {
+ puts(tr("Could not open %1 for reading.").arg(_fileName).toLocal8Bit().constData());
+ return;
+ }
+ _networkSource = new NetworkSpeed();
+ _thread = new CopyThread(file, this);
+ connect(_thread, &CopyThread::logMessage, this, &ConsoleWorker::logMessage, Qt::QueuedConnection);
+ connect(_thread, &CopyThread::finished, this, &ConsoleWorker::testFinished, Qt::QueuedConnection);
+ _timer.start();
+ _thread->start();
+ });
+}
+
+ConsoleWorker::~ConsoleWorker()
+{
+ delete _networkSource;
+}
+
+void ConsoleWorker::logMessage(CopyThread::LogMessageId msgId, QString message)
+{
+ if (msgId == CopyThread::TestRandomStart) {
+ printf("+SEQ");
+ } else if (msgId == CopyThread::TestFinished) {
+ printf("+RND");
+ }
+ if (msgId == CopyThread::TestRandomStart || msgId == CopyThread::TestFinished) {
+ for (int i : _series) {
+ printf(",%i", i);
+ }
+ putchar('\n');
+ }
+ _series.clear();
+ puts(message.toLocal8Bit().constData());
+}
+
+void ConsoleWorker::testFinished()
+{
+ _timer.stop();
+ delete _thread;
+ _thread = NULL;
+ QCoreApplication::instance()->quit();
+}
+
+void ConsoleWorker::updateTimer()
+{
+ int i = (int)_networkSource->read();
+ _series.append(i);
+}
diff --git a/src/consoleworker.h b/src/consoleworker.h
new file mode 100644
index 0000000..276f987
--- /dev/null
+++ b/src/consoleworker.h
@@ -0,0 +1,34 @@
+#ifndef _CONSOLEWORKER_H_
+#define _CONSOLEWORKER_H_
+
+#include "datasource/idatasource.h"
+#include "copythread.h"
+
+#include <QString>
+#include <QTimer>
+#include <QVector>
+
+class CopyThread;
+
+class ConsoleWorker : public QObject
+{
+ Q_OBJECT
+
+public:
+ ConsoleWorker(QString fileName);
+ virtual ~ConsoleWorker();
+
+private slots:
+ void logMessage(CopyThread::LogMessageId msgId, QString message);
+ void testFinished();
+ void updateTimer();
+
+private:
+ CopyThread *_thread;
+ QString _fileName;
+ QTimer _timer;
+ IDataSource* _networkSource;
+ QVector<int> _series;
+};
+
+#endif
diff --git a/src/copythread.cpp b/src/copythread.cpp
index 21aadbb..7fda016 100644
--- a/src/copythread.cpp
+++ b/src/copythread.cpp
@@ -38,22 +38,22 @@ void CopyThread::run()
qint64 seqSum = 0, rndSum = 0;
qint64 seqTime, rndTime = -1;
- const qint64 size = _file->size() - BUFFER_SIZE;
+ const qint64 size = _file->size();
// Sequential read
- emit logMessage(tr("Starting sequential read test"));
+ emit logMessage(CopyThread::TestSequentialStart, tr("Starting sequential read test"));
timer.start();
do {
ret = _file->read(buffer, BUFFER_SIZE);
seqSum += ret;
if (ret == 0)
break; // EOF
- } while (!_doStop && ret >= 0 && timer.elapsed() < TEST_LENGTH);
+ } while (!_doStop && ret > 0 && timer.elapsed() < TEST_LENGTH);
seqTime = timer.elapsed();
// Random read
if (size > 0) {
- emit logMessage(tr("Starting random read test"));
+ emit logMessage(CopyThread::TestRandomStart, tr("Starting random read test"));
timer.restart();
do {
_file->seek(BIGRAND % size);
@@ -66,7 +66,7 @@ void CopyThread::run()
// All done
const qint64 seqSpeed = seqSum / (seqTime * 1024 + 1);
const qint64 rndSpeed = rndSum / (rndTime * 1024 + 1);
- emit logMessage(tr("Seq: %1MiB/s, Random: %2MiB/s - [%3s / %4s]")
+ emit logMessage(CopyThread::TestFinished, tr("Seq: %1MiB/s, Random: %2MiB/s - [%3s / %4s]")
.arg(QString::number(seqSpeed), QString::number(rndSpeed),
QString::number(seqTime / 1000), QString::number(rndTime / 1000)));
delete[] buffer;
diff --git a/src/copythread.h b/src/copythread.h
index 428c7fa..ce6be83 100644
--- a/src/copythread.h
+++ b/src/copythread.h
@@ -2,6 +2,7 @@
#define COPYTHREAD_H_
#include <QThread>
+#include <QMetaType>
class QFile;
@@ -12,6 +13,13 @@ public:
virtual ~CopyThread();
void stop();
+ enum LogMessageId {
+ None,
+ TestSequentialStart,
+ TestRandomStart,
+ TestFinished,
+ };
+
protected:
virtual void run();
@@ -20,7 +28,9 @@ private:
volatile bool _doStop;
signals:
- void logMessage(QString message);
+ void logMessage(LogMessageId msgId, QString message);
};
+Q_DECLARE_METATYPE(CopyThread::LogMessageId);
+
#endif /* COPYTHREAD_H_ */
diff --git a/src/main.cpp b/src/main.cpp
index 5d9a396..8d60fe2 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,22 +1,34 @@
#include "speedcheck.h"
+#include "consoleworker.h"
+#include "copythread.h"
+
#include <QApplication>
#include <QMessageBox>
+#include <QMetaType>
int main(int argc, char **argv)
{
- QApplication app(argc, argv);
- bool autoStart = false;
- if (argc < 2) {
- QMessageBox::critical(NULL, "Error", "Need one argument: file name");
- return 1;
- }
- if (argc >= 3 && strcmp(argv[1], "--auto") == 0) {
- autoStart = true;
- argc--;
- argv++;
+ if (argc >= 2 && strcmp(argv[1], "--console") == 0) {
+ QCoreApplication app(argc, argv);
+ qRegisterMetaType<CopyThread::LogMessageId>();
+ ConsoleWorker main(QString::fromLocal8Bit(argv[2]));
+ app.exec();
+ } else {
+ QApplication app(argc, argv);
+ qRegisterMetaType<CopyThread::LogMessageId>();
+ bool autoStart = false;
+ if (argc < 2) {
+ QMessageBox::critical(NULL, "Error", "Need one argument: file name");
+ return 1;
+ }
+ if (argc >= 3 && strcmp(argv[1], "--auto") == 0) {
+ autoStart = true;
+ argc--;
+ argv++;
+ }
+ SpeedCheck main(QString::fromLocal8Bit(argv[1]), autoStart);
+ main.show();
+ app.exec();
}
- SpeedCheck main(QString::fromLocal8Bit(argv[1]), autoStart);
- main.show();
- app.exec();
return 0;
}
diff --git a/src/speedcheck.cpp b/src/speedcheck.cpp
index 428be75..1248323 100644
--- a/src/speedcheck.cpp
+++ b/src/speedcheck.cpp
@@ -3,6 +3,7 @@
#include "copythread.h"
#include "datasource/cpuload.h"
#include "datasource/networkspeed.h"
+#include "copythread.h"
#include <QCoreApplication>
#include <QMessageBox>
@@ -22,7 +23,6 @@ SpeedCheck::SpeedCheck(QString fileName, bool autoStart)
_timer.setInterval(200);
connect(&_timer, SIGNAL(timeout()), this, SLOT(updateTimer()));
if (autoStart) {
- _doQuit = true;
QTimer::singleShot(1, [this]() {
this->startClicked(true);
});
@@ -34,7 +34,7 @@ SpeedCheck::~SpeedCheck()
}
-void SpeedCheck::logMessage(QString message)
+void SpeedCheck::logMessage(CopyThread::LogMessageId, QString message)
{
qDebug() << message;
_ui->statusBar->showMessage(message);
diff --git a/src/speedcheck.h b/src/speedcheck.h
index c89e3f1..c665ff0 100644
--- a/src/speedcheck.h
+++ b/src/speedcheck.h
@@ -3,6 +3,7 @@
#include <QMainWindow>
#include <QTimer>
+#include "copythread.h"
namespace Ui
{
@@ -18,7 +19,7 @@ public:
virtual ~SpeedCheck();
private slots:
- void logMessage(QString message);
+ void logMessage(CopyThread::LogMessageId msgId, QString message);
void startClicked(bool);
void quitClicked(bool);
void testFinished();
diff --git a/src/ui/speedcheck.ui b/src/ui/speedcheck.ui
index 4e59fc1..d9dae26 100644
--- a/src/ui/speedcheck.ui
+++ b/src/ui/speedcheck.ui
@@ -24,7 +24,7 @@
</sizepolicy>
</property>
<property name="text">
- <string>Network (100MBit / 1000GBit)</string>
+ <string>Network (100MBit / 1000MBit)</string>
</property>
</widget>
</item>
@@ -83,7 +83,16 @@
<property name="spacing">
<number>3</number>
</property>
- <property name="margin">
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
<number>0</number>
</property>
<item>