Skip to content

Commit

Permalink
Code Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Ace-Krypton committed Aug 17, 2023
1 parent 3129cd3 commit 81315c0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 208 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt.user
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 11.0.0, 2023-08-16T23:15:05. -->
<!-- Written by QtCreator 11.0.0, 2023-08-17T22:38:04. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
Expand Down
25 changes: 6 additions & 19 deletions include/builder.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#pragma once

#include <unordered_map>

#include <QString>
#include <QObject>


#include "../include/benchmark.hpp"

class Builder : public QObject {
Expand All @@ -13,26 +16,10 @@ class Builder : public QObject {

Q_INVOKABLE void sequential(const QString &size, const QString &testCount,
Benchmark *benchmark, bool isAll,
QString blockSize, QString mode);
const QString &blockSize, const QString &mode);

Q_INVOKABLE void random(const QString &size, const QString &testCount,
Benchmark *benchmark, bool isAll,
QString queue, QString mode, QString allocationSize);

// Q_INVOKABLE void seq1mq8t1Read(const QString &size, const QString &testCount,
// Benchmark *benchmark, bool isAll);
// Q_INVOKABLE void seq1mq8t1Write(const QString &size, const QString &testCount,
// Benchmark *benchmark, bool isAll);
// Q_INVOKABLE void seq128Kq8t1Read(const QString &size, const QString &testCount,
// Benchmark *benchmark, bool isAll);
// Q_INVOKABLE void seq128Kq8t1Write(const QString &size, const QString &testCount,
// Benchmark *benchmark, bool isAll);
// Q_INVOKABLE void rnd4kq32t1Read(const QString &size, const QString &testCount,
// Benchmark *benchmark, bool isAll);
// Q_INVOKABLE void rnd4kq32t1Write(const QString &size, const QString &testCount,
// Benchmark *benchmark, bool isAll);
// Q_INVOKABLE void rnd4kq1t1Read(const QString &size, const QString &testCount,
// Benchmark *benchmark, bool isAll);
// Q_INVOKABLE void rnd4kq1t1Write(const QString &size, const QString &testCount,
// Benchmark *benchmark, bool isAll);
const QString &queue, const QString &mode,
const QString &allocationSize);
};
214 changes: 26 additions & 188 deletions src/builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,206 +4,44 @@ Builder::Builder(QObject *parent) : QObject(parent) { }

void Builder::sequential(const QString &size, const QString &testCount,
Benchmark *benchmark, bool isAll,
QString blockSize, QString mode) {
const QString &blockSize, const QString &mode) {

QString command = "sync;fio --loops=" + testCount + " --size=32m --stonewall --zero_buffers=0 "
"--randrepeat=1 --ioengine=libaio --direct=1 "
"--name=test --filename=test "
"--bs=" + blockSize + " --size=" + size + "G --readwrite=" + mode + " --ramp_time=4 "
"--iodepth=8 --numjobs=1 > fio_results.txt";
static const std::map<QString, std::map<QString, QString>> detectMap = {
{"read", {{"1M", "SMREAD"}, {"128K", "SKREAD"}}},
{"write", {{"1M", "SMWRITE"}, {"128K", "SKWRITE"}}}
};

QString detect;
QString detect = detectMap.at(mode).at(blockSize);

if (mode == "read" && blockSize == "1M") {
detect = "SMREAD";
} else if (mode == "read" && blockSize == "128K") {
detect = "SKREAD";
} else if (mode == "write" && blockSize == "1M") {
detect = "SMWRITE";
} else if (mode == "write" && blockSize == "128K") {
detect = "SKWRITE";
}
QString command = QString::fromUtf8(
"sync;fio --loops=%1 --size=32m --stonewall --zero_buffers=0 "
"--randrepeat=1 --ioengine=libaio --direct=1 "
"--name=test --filename=test "
"--bs=%2 --size=%3G --readwrite=%4 --ramp_time=4 "
"--iodepth=8 --numjobs=1 > fio_results.txt")
.arg(testCount, blockSize, size, mode);

benchmark->start(command, detect, isAll);
}

void Builder::random(const QString &size, const QString &testCount,
Benchmark *benchmark, bool isAll,
QString queue, QString mode, QString allocationSize) {
const QString &queue, const QString &mode,
const QString &allocationSize) {

QString command = "sync;fio --loops=" + testCount + " --size=" + allocationSize
+ "m --stonewall --zero_buffers=0 "
"--randrepeat=1 --ioengine=libaio --direct=1 --name=test "
"--filename=test --iodepth=" + queue + " --bs=4K --size=" + size +
"G --readwrite=rand" + mode + " --ramp_time=1 --numjobs=1 > fio_results.txt";
static const std::map<QString, std::map<QString, QString>> detectMap = {
{"read", {{"32", "RGREAD"}, {"1", "RLREAD"}}},
{"write", {{"32", "RGWRITE"}, {"1", "RLWRITE"}}}
};

QString detect;
QString detect = detectMap.at(mode).at(queue);

if (mode == "read" && queue == "32") {
detect = "RGREAD";
} else if (mode == "read" && queue == "1") {
detect = "RLREAD";
} else if (mode == "write" && queue == "32") {
detect = "RGWRITE";
} else if (mode == "write" && queue == "1") {
detect = "RLWRITE";
}
QString command = QString::fromUtf8(
"sync;fio --loops=%1 --size=%2m --stonewall --zero_buffers=0 "
"--randrepeat=1 --ioengine=libaio --direct=1 --name=test "
"--filename=test --iodepth=%3 --bs=4K --size=%4G --readwrite=rand%5 "
"--ramp_time=1 --numjobs=1 > fio_results.txt")
.arg(testCount, allocationSize, queue, size, mode);

benchmark->start(command, detect, isAll);
}

///**
// * @brief Runs a sequential read with 1M 8 Queues and 1 Thread.
// *
// * @param size The size of the data to read in gigabytes.
// * @param testCount The number of tests that will be done.
// * @param benchmark A pointer to the Benchmark object to record the results.
// * @param isAll If true, the benchmark includes all data;
// * otherwise, it includes important data only.
// */
//void Builder::seq1mq8t1Read(const QString &size, const QString &testCount,
// Benchmark *benchmark, bool isAll) {
// QString command = "sync;fio --loops=" + testCount + " --size=32m --stonewall --zero_buffers=0 "
// "--randrepeat=1 --ioengine=libaio --direct=1 "
// "--name=test --filename=test "
// "--bs=1M --size=" + size + "G --readwrite=read --ramp_time=4 "
// "--iodepth=8 --numjobs=1 > fio_results.txt";

// benchmark->start(command, "SMREAD", isAll);
//}

///**
// * @brief Runs a sequential write with 1M 8 Queues and 1 Thread.
// *
// * @param size The size of the data to read in gigabytes.
// * @param testCount The number of tests that will be done.
// * @param benchmark A pointer to the Benchmark object to record the results.
// * @param isAll If true, the benchmark includes all data;
// * otherwise, it includes important data only.
// */
//void Builder::seq1mq8t1Write(const QString &size, const QString &testCount,
// Benchmark *benchmark, bool isAll) {
// QString command = "sync;fio --loops=" + testCount + " --size=32m --stonewall --zero_buffers=0 "
// "--randrepeat=1 --ioengine=libaio --direct=1 "
// "--name=test --filename=test "
// "--bs=1M --size=" + size + "G --readwrite=write --ramp_time=4 "
// "--iodepth=8 --numjobs=1 > fio_results.txt";

// benchmark->start(command, "SMWRITE", isAll);
//}

///**
// * @brief Runs a sequential read with 128K 8 Queues and 1 Thread.
// *
// * @param size The size of the data to read in gigabytes.
// * @param testCount The number of tests that will be done.
// * @param benchmark A pointer to the Benchmark object to record the results.
// * @param isAll If true, the benchmark includes all data;
// * otherwise, it includes important data only.
// */
//void Builder::seq128Kq8t1Read(const QString &size, const QString &testCount,
// Benchmark *benchmark, bool isAll) {
// QString command = "sync;fio --loops=" + testCount + " --size=32m --stonewall --zero_buffers=0 "
// "--randrepeat=1 --ioengine=libaio --direct=1 "
// "--name=test --filename=test "
// "--bs=128K --size=" + size + "G --readwrite=read --ramp_time=4 "
// "--iodepth=8 --numjobs=1 > fio_results.txt";

// benchmark->start(command, "SKREAD", isAll);
//}

///**
// * @brief Runs a sequential write with 128K 8 Queues and 1 Thread.
// *
// * @param size The size of the data to read in gigabytes.
// * @param testCount The number of tests that will be done.
// * @param benchmark A pointer to the Benchmark object to record the results.
// * @param isAll If true, the benchmark includes all data;
// * otherwise, it includes important data only.
// */
//void Builder::seq128Kq8t1Write(const QString &size, const QString &testCount,
// Benchmark *benchmark, bool isAll) {
// QString command = "sync;fio --loops=" + testCount + " --size=32m --stonewall --zero_buffers=0 "
// "--randrepeat=1 --ioengine=libaio --direct=1 "
// "--name=test --filename=test "
// "--bs=128K --size=" + size + "G --readwrite=write --ramp_time=4 "
// "--iodepth=8 --numjobs=1 > fio_results.txt";

// benchmark->start(command, "SKWRITE", isAll);
//}

///**
// * @brief Runs a random read with 4K 32 Queues and 1 Thread.
// *
// * @param size The size of the data to read in gigabytes.
// * @param testCount The number of tests that will be done.
// * @param benchmark A pointer to the Benchmark object to record the results.
// * @param isAll If true, the benchmark includes all data;
// * otherwise, it includes important data only.
// */
//void Builder::rnd4kq32t1Read(const QString &size, const QString &testCount,
// Benchmark *benchmark, bool isAll) {
// QString command = "sync;fio --loops=" + testCount + " --size=8m --stonewall --zero_buffers=0 "
// "--randrepeat=1 --ioengine=libaio --direct=1 --name=test "
// "--filename=test --iodepth=32 --bs=4K --size=" + size +
// "G --readwrite=randread --ramp_time=1 --numjobs=1 > fio_results.txt";

// benchmark->start(command, "RGREAD", isAll);
//}

///**
// * @brief Runs a random write with 4K 32 Queues and 1 Thread.
// *
// * @param size The size of the data to read in gigabytes.
// * @param testCount The number of tests that will be done.
// * @param benchmark A pointer to the Benchmark object to record the results.
// * @param isAll If true, the benchmark includes all data;
// * otherwise, it includes important data only.
// */
//void Builder::rnd4kq32t1Write(const QString &size, const QString &testCount,
// Benchmark *benchmark, bool isAll) {
// QString command = "sync;fio --loops=" + testCount + " --size=8m --stonewall --zero_buffers=0 "
// "--randrepeat=1 --ioengine=libaio --direct=1 --name=test "
// "--filename=test --iodepth=32 --bs=4K --size=" + size +
// "G --readwrite=randwrite --ramp_time=1 --numjobs=1 > fio_results.txt";

// benchmark->start(command, "RGWRITE", isAll);
//}

///**
// * @brief Runs a random read with 4K 1 Queue and 1 Thread.
// *
// * @param size The size of the data to read in gigabytes.
// * @param testCount The number of tests that will be done.
// * @param benchmark A pointer to the Benchmark object to record the results.
// * @param isAll If true, the benchmark includes all data;
// * otherwise, it includes important data only.
// */
//void Builder::rnd4kq1t1Read(const QString &size, const QString &testCount,
// Benchmark *benchmark, bool isAll) {
// QString command = "sync;fio --loops=" + testCount + " --size=256m --stonewall --zero_buffers=0 "
// "--randrepeat=1 --ioengine=libaio --direct=1 --name=test "
// "--filename=test --iodepth=1 --bs=4K --size=" + size +
// "G --readwrite=randread --ramp_time=1 --numjobs=1 > fio_results.txt";

// benchmark->start(command, "RLREAD", isAll);
//}

///**
// * @brief Runs a random write with 4K 1 Queue and 1 Thread.
// *
// * @param size The size of the data to read in gigabytes.
// * @param testCount The number of tests that will be done.
// * @param benchmark A pointer to the Benchmark object to record the results.
// * @param isAll If true, the benchmark includes all data;
// * otherwise, it includes important data only.
// */
//void Builder::rnd4kq1t1Write(const QString &size, const QString &testCount,
// Benchmark *benchmark, bool isAll) {
// QString command = "sync;fio --loops=" + testCount + " --size=256m --stonewall --zero_buffers=0 "
// "--randrepeat=1 --ioengine=libaio --direct=1 --name=test "
// "--filename=test --iodepth=1 --bs=4K --size=" + size +
// "G --readwrite=randwrite --ramp_time=1 --numjobs=1 > fio_results.txt";

// benchmark->start(command, "RLWRITE", isAll);
//}

0 comments on commit 81315c0

Please sign in to comment.