diff options
author | Ioannis Christoforidis | 2019-11-27 20:13:13 +0100 |
---|---|---|
committer | Ioannis Christoforidis | 2019-11-27 20:13:13 +0100 |
commit | 21a9a3442bc1d0c197ef2314fa2649569ebceab4 (patch) | |
tree | 3962d32ae624e56dd4b768afa0b487d05a0a390c | |
parent | fix wrong comment (diff) | |
download | speedcheck-21a9a3442bc1d0c197ef2314fa2649569ebceab4.tar.gz speedcheck-21a9a3442bc1d0c197ef2314fa2649569ebceab4.tar.xz speedcheck-21a9a3442bc1d0c197ef2314fa2649569ebceab4.zip |
update output to also show KiB if connection gets slow
-rw-r--r-- | src/copythread.cpp | 28 | ||||
-rw-r--r-- | src/speedcheck.cpp | 13 | ||||
-rw-r--r-- | src/speedcheck.h | 1 | ||||
-rw-r--r-- | src/ui/speedcheck.ui | 45 |
4 files changed, 75 insertions, 12 deletions
diff --git a/src/copythread.cpp b/src/copythread.cpp index 7ecc2a3..775de7f 100644 --- a/src/copythread.cpp +++ b/src/copythread.cpp @@ -35,16 +35,16 @@ void CopyThread::run() QElapsedTimer timer; qint64 ret; qint64 seqSum = 0, rndSum = 0; - qint64 seqTime, rndTime = -1; + qint64 seqTime = 0, rndTime = 1; const qint64 size = _file->size() - BUFFER_SIZE; // Sequential read emit logMessage(trUtf8("Starting sequential read test")); - if (size > 0) { + if (size > 0) { _file->seek(BIGRAND % size); } - timer.start(); + timer.start(); do { ret = _file->read(buffer, BUFFER_SIZE); seqSum += ret; @@ -65,13 +65,21 @@ void CopyThread::run() } while (!_doStop && ret > 0 && timer.elapsed() < TEST_LENGTH); rndTime = timer.elapsed(); } - - // All done - const qint64 seqSpeed = seqSum / (seqTime * 1024 + 1); - const qint64 rndSpeed = rndSum / (rndTime * 1024 + 1); - emit logMessage(trUtf8("Seq: %1MiB/s, Random: %2MiB/s - [%3s / %4s]") - .arg(QString::number(seqSpeed), QString::number(rndSpeed), - QString::number(seqTime / 1000), QString::number(rndTime / 1000))); + if (seqSum / (seqTime * 1024 + 1) >= 1) { + const qint64 seqSpeed = seqSum / (seqTime * 1024 + 1); + const qint64 rndSpeed = rndSum / (rndTime * 1024 + 1); + emit logMessage(trUtf8("Seq: %1MiB/s, Random: %2MiB/s - [%3s / %4s]") + .arg(QString::number(seqSpeed), QString::number(rndSpeed), + QString::number(seqTime / 1000), QString::number(rndTime / 1000))); + } else { + const qint64 seqSpeed = seqSum / (seqTime + 1); + const qint64 rndSpeed = rndSum / (rndTime + 1); + qDebug() << seqSum / seqTime << " " << rndSum / rndTime; + emit logMessage(trUtf8("Seq: %1KiB/s, Random: %2KiB/s - [%3s / %4s]") + .arg(QString::number(seqSpeed), QString::number(rndSpeed), + QString::number(seqTime / 1000), QString::number(rndTime / 1000))); + } + // All done delete[] buffer; _file->close(); } diff --git a/src/speedcheck.cpp b/src/speedcheck.cpp index 882eeab..45a5c85 100644 --- a/src/speedcheck.cpp +++ b/src/speedcheck.cpp @@ -8,6 +8,7 @@ #include <QMessageBox> #include <QNetworkInterface> #include <QFile> +#include <QFileDialog> #include <QDebug> #include <QTimer> @@ -27,6 +28,8 @@ SpeedCheck::SpeedCheck(QString fileName) connect(_ui->btnStart, SIGNAL(clicked(bool)), this, SLOT(startClicked(bool))); connect(_ui->btnQuit, SIGNAL(clicked(bool)), this, SLOT(quitClicked(bool))); + connect(_ui->btnselect, SIGNAL(clicked(bool)), this, SLOT(selectClicked(bool))); + _ui->filelabel->setText("Selected File: " + _fileName); _timer.setInterval(200); connect(&_timer, SIGNAL(timeout()), this, SLOT(updateTimer())); qsrand((uint)QCoreApplication::applicationPid()); @@ -42,10 +45,14 @@ void SpeedCheck::logMessage(QString message) qDebug() << message; _ui->statusBar->showMessage(message); } +void SpeedCheck::selectClicked(bool) { + _fileName = QFileDialog::getOpenFileName(this, tr("Select benchmark file")); + _ui->filelabel->setText("Selected File: " + _fileName); +} void SpeedCheck::startClicked(bool) { - QFile *file = new QFile(_fileName); + QFile *file = new QFile(_fileName); if (!file->open(QIODevice::ReadOnly)) { QMessageBox::critical(this, trUtf8("Error"), trUtf8("Could not open %1 for reading.").arg(_fileName)); return; @@ -53,6 +60,8 @@ void SpeedCheck::startClicked(bool) _ui->picCpu->setDataSource(new CpuLoad()); _ui->picSpeed->setDataSource(new NetworkSpeed(_ui->comboBox->currentText())); _ui->btnStart->setDisabled(true); + _ui->btnselect->setDisabled(true); + _ui->comboBox->setDisabled(true); delete _thread; _thread = new CopyThread(file, this); connect(_thread, SIGNAL(logMessage(QString)), this, SLOT(logMessage(QString)), Qt::QueuedConnection); @@ -81,6 +90,8 @@ void SpeedCheck::testFinished() QCoreApplication::instance()->quit(); } _ui->btnStart->setEnabled(true); + _ui->btnselect->setEnabled(true); + _ui->comboBox->setEnabled(true); } void SpeedCheck::updateTimer() diff --git a/src/speedcheck.h b/src/speedcheck.h index fd54605..79ceb28 100644 --- a/src/speedcheck.h +++ b/src/speedcheck.h @@ -20,6 +20,7 @@ public: private slots: void logMessage(QString message); void startClicked(bool); + void selectClicked(bool); void quitClicked(bool); void testFinished(); void updateTimer(); diff --git a/src/ui/speedcheck.ui b/src/ui/speedcheck.ui index b82c3d7..2188b31 100644 --- a/src/ui/speedcheck.ui +++ b/src/ui/speedcheck.ui @@ -55,7 +55,14 @@ </widget> </item> <item> - <widget class="GraphWidget" name="picCpu" native="true"/> + <widget class="GraphWidget" name="picCpu" native="true"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> </item> <item> <widget class="QFrame" name="frame_3"> @@ -113,6 +120,26 @@ </widget> </item> <item> + <spacer name="horizontalSpacer_2"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QPushButton" name="btnselect"> + <property name="text"> + <string>Select File</string> + </property> + </widget> + </item> + <item> <spacer name="horizontalSpacer"> <property name="orientation"> <enum>Qt::Horizontal</enum> @@ -135,6 +162,22 @@ </layout> </widget> </item> + <item> + <widget class="QLabel" name="filelabel"> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string/> + </property> + </widget> + </item> </layout> </widget> <widget class="QStatusBar" name="statusBar"/> |