diff --git a/include/system.hpp b/include/system.hpp index c1c0037..7ecc5ec 100644 --- a/include/system.hpp +++ b/include/system.hpp @@ -11,6 +11,9 @@ #include #include #include +#include +#include +#include class System : public QObject { Q_OBJECT @@ -23,6 +26,8 @@ class System : public QObject { Q_INVOKABLE QString extractCPU(); Q_INVOKABLE QString extractStorage(); Q_INVOKABLE QString checkFIOVersion(); + Q_INVOKABLE bool hasEnoughSpace(const QString &testSize); + Q_INVOKABLE qint64 parseTestSize(const QString &testSize); Q_INVOKABLE bool isSSD(const std::filesystem::path &path); Q_INVOKABLE void writeToAFile(const QString &data, const QString &fileUrl); }; diff --git a/qml/MainPage.qml b/qml/MainPage.qml index f5e8306..a760ce3 100644 --- a/qml/MainPage.qml +++ b/qml/MainPage.qml @@ -537,15 +537,22 @@ Item { } onClicked: { - utils.resetBenchmarking( - mainPage, - ["seq1MRead", "seq1MReadIOPS", "seq1MReadGB", "seq1MWrite", "seq1MWriteIOPS", "seq1MWriteGB"]) - - isBenchmarkingInProgress = true const gibText = comboGiB.currentText.match(/\d+/)[0] const comboText = combo.currentText - builder.sequential(parseInt(gibText), comboText, benchmark, - false, "1M", "read") + + if (system.hasEnoughSpace(comboGiB.currentText)) { + utils.resetBenchmarking( + mainPage, + ["seq1MRead", "seq1MReadIOPS", "seq1MReadGB", "seq1MWrite", "seq1MWriteIOPS", "seq1MWriteGB"]) + + isBenchmarkingInProgress = true + + builder.sequential(parseInt(gibText), comboText, + benchmark, false, "1M", "read") + } else { + console.log( + "You don't have enough space on your system, please lower the test size") + } } } } @@ -667,15 +674,21 @@ Item { } onClicked: { - utils.resetBenchmarking( - mainPage, - ["seq128KRead", "seq128KReadIOPS", "seq128KReadGB", "seq128KWrite", "seq128KWriteIOPS", "seq128KWriteGB"]) - - isBenchmarkingInProgress = true const gibText = comboGiB.currentText.match(/\d+/)[0] const comboText = combo.currentText - builder.sequential(parseInt(gibText), comboText, benchmark, - false, "128K", "read") + + if (system.hasEnoughSpace(comboGiB.currentText)) { + const benchmarks = ["seq128KRead", "seq128KReadIOPS", "seq128KReadGB", "seq128KWrite", "seq128KWriteIOPS", "seq128KWriteGB"] + + utils.resetBenchmarking(mainPage, benchmarks) + isBenchmarkingInProgress = true + + builder.sequential(parseInt(gibText), comboText, + benchmark, false, "128K", "read") + } else { + console.log( + "You don't have enough space on your system, please lower the test size") + } } } } @@ -795,15 +808,21 @@ Item { } onClicked: { - utils.resetBenchmarking( - mainPage, - ["rand4KQ32T1Read", "rand4KQ32T1ReadIOPS", "rand4KQ32T1ReadGB", "rand4KQ32T1Write", "rand4KQ32T1WriteIOPS", "rand4KQ32T1WriteGB"]) - - isBenchmarkingInProgress = true const gibText = comboGiB.currentText.match(/\d+/)[0] const comboText = combo.currentText - builder.random(parseInt(gibText), comboText, benchmark, - false, "32", "read", "8") + + if (system.hasEnoughSpace(comboGiB.currentText)) { + const benchmarks = ["rand4KQ32T1Read", "rand4KQ32T1ReadIOPS", "rand4KQ32T1ReadGB", "rand4KQ32T1Write", "rand4KQ32T1WriteIOPS", "rand4KQ32T1WriteGB"] + + utils.resetBenchmarking(mainPage, benchmarks) + isBenchmarkingInProgress = true + + builder.random(parseInt(gibText), comboText, benchmark, + false, "32", "read", "8") + } else { + console.log( + "You don't have enough space on your system, please lower the test size") + } } } } @@ -924,15 +943,21 @@ Item { } onClicked: { - utils.resetBenchmarking( - mainPage, - ["rand4KQ1T1Read", "rand4KQ1T1ReadIOPS", "rand4KQ1T1ReadGB", "rand4KQ1T1Write", "rand4KQ1T1WriteIOPS", "rand4KQ1T1WriteGB"]) - - isBenchmarkingInProgress = true const gibText = comboGiB.currentText.match(/\d+/)[0] const comboText = combo.currentText - builder.random(parseInt(gibText), comboText, benchmark, - false, "1", "read", "256") + + if (system.hasEnoughSpace(comboGiB.currentText)) { + const benchmarks = ["rand4KQ1T1Read", "rand4KQ1T1ReadIOPS", "rand4KQ1T1ReadGB", "rand4KQ1T1Write", "rand4KQ1T1WriteIOPS", "rand4KQ1T1WriteGB"] + + utils.resetBenchmarking(mainPage, benchmarks) + isBenchmarkingInProgress = true + + builder.random(parseInt(gibText), comboText, benchmark, + false, "1", "read", "256") + } else { + console.log( + "You don't have enough space on your system, please lower the test size") + } } } } diff --git a/src/system.cpp b/src/system.cpp index aa7a262..1bbc57c 100644 --- a/src/system.cpp +++ b/src/system.cpp @@ -32,6 +32,41 @@ QString System::extractCPU() { return QString::fromStdString(cpuInfo); } +bool System::hasEnoughSpace(const QString &testSize) { + qDebug() << testSize << '\n'; + qint64 requiredBytes = parseTestSize(testSize); + + QStorageInfo storageInfo = QStorageInfo::root(); + qDebug() << storageInfo.bytesAvailable() << '\n'; + + return storageInfo.isReadOnly() || storageInfo.bytesAvailable() >= requiredBytes; +} + +qint64 System::parseTestSize(const QString &testSize) { + static QRegularExpression sizePattern("(\\d+)\\s*(MB|GiB)?", + QRegularExpression::CaseInsensitiveOption); + QRegularExpressionMatch match = sizePattern.match(testSize); + + if (match.hasMatch()) { + qint64 size = match.captured(1).toLongLong(); + QString unit = match.captured(2).toUpper(); + + qDebug() << "Captured size:" << match.captured(1); + qDebug() << "Captured unit:" << match.captured(2); + + static const QHash unitMultipliers = { + {"MB", 1024 * 1024}, + {"GIB", 1024 * 1024 * 1024} + }; + + qDebug() << "Returned value" << size * unitMultipliers.value(unit, 1); + + return size * unitMultipliers.value(unit, 1); + } + + return 0; +} + /** * @brief Checks if the device at the specified path is an SSD. *