Skip to content

Commit

Permalink
Improve DiskBenchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
dnzbk committed Sep 3, 2024
1 parent 92df53b commit 28d57b9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
6 changes: 3 additions & 3 deletions daemon/remote/XmlRpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,10 @@ class TestServerSpeedXmlCommand: public SafeXmlCommand
virtual void Execute();
};

class TestDiskSpeedXmlCommand: public SafeXmlCommand
class TestDiskSpeedXmlCommand final : public SafeXmlCommand
{
public:
virtual void Execute();
void Execute();

std::string ToJsonStr(const std::pair<uint64_t, double>& res)
{
Expand Down Expand Up @@ -855,7 +855,7 @@ std::unique_ptr<XmlCommand> XmlRpcProcessor::CreateCommand(const char* methodNam
{
command = std::make_unique<TestServerSpeedXmlCommand>();
}
else if (!strcasecmp(methodName, "testdiskspeed"))
else if (!strcasecmp(methodName, "testdiskspeed"))
{
command = std::make_unique<TestDiskSpeedXmlCommand>();
}
Expand Down
18 changes: 7 additions & 11 deletions daemon/util/Benchmark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,16 @@ namespace Benchmark
uint64_t maxFileSizeBytes,
std::chrono::seconds timeout) const noexcept(false)
{
const char* dataToWrite = data.data();
size_t dataSize = data.size();
uint64_t totalWritten = 0;

auto start = high_resolution_clock::now();
auto timeoutNS = duration_cast<nanoseconds>(timeout);
auto start = steady_clock::now();
try
{
while (
totalWritten < maxFileSizeBytes &&
duration_cast<seconds>(high_resolution_clock::now() - start) < timeout)
while (totalWritten < maxFileSizeBytes && (steady_clock::now() - start) < timeoutNS)
{
file.write(dataToWrite, dataSize);
totalWritten += dataSize;
file.write(data.data(), data.size());
totalWritten += data.size();
}
}
catch (const std::exception& e)
Expand All @@ -77,12 +74,11 @@ namespace Benchmark
std::string errMsg = "Failed to write data to file " + filename + ". " + e.what();
throw std::runtime_error(errMsg);
}
auto finish = high_resolution_clock::now();
auto finish = steady_clock::now();
double elapsed = duration<double, std::milli>(finish - start).count();

CleanUp(file, filename);

double elapsed = duration<double, std::milli>(finish - start).count();

return { totalWritten, elapsed };
}

Expand Down
4 changes: 2 additions & 2 deletions webui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -677,8 +677,8 @@ <h3>Disk speed test</h3>
<div class="controls">
<div class="input-append">
<select class="dist-speedtest__select--width" id="SysInfo_DiskSpeedTestTimeout">
<option value="1" selected>1</option>
<option value="2">2</option>
<option value="1">1</option>
<option value="2" selected>2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
Expand Down

0 comments on commit 28d57b9

Please sign in to comment.