Skip to content

Commit

Permalink
Added Size Check
Browse files Browse the repository at this point in the history
  • Loading branch information
Ace-Krypton committed Aug 22, 2023
1 parent 0d818ef commit ee6607e
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 28 deletions.
5 changes: 5 additions & 0 deletions include/system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#include <QString>
#include <QIODevice>
#include <QTextStream>
#include <QStorageInfo>
#include <QRegularExpression>
#include <QRegularExpressionMatch>

class System : public QObject {
Q_OBJECT
Expand All @@ -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);
};
81 changes: 53 additions & 28 deletions qml/MainPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}
}
Expand Down Expand Up @@ -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")
}
}
}
}
Expand Down Expand Up @@ -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")
}
}
}
}
Expand Down Expand Up @@ -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")
}
}
}
}
Expand Down
35 changes: 35 additions & 0 deletions src/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QString, qint64> 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.
*
Expand Down

0 comments on commit ee6607e

Please sign in to comment.