mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:58:11 +00:00
disk_benchmark: Core::ArgsParser to parse arguments
This commit is contained in:
parent
23a87a41ff
commit
c0f15ebcbb
1 changed files with 8 additions and 31 deletions
|
@ -9,6 +9,7 @@
|
||||||
#include <AK/String.h>
|
#include <AK/String.h>
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <LibCore/ElapsedTimer.h>
|
#include <LibCore/ElapsedTimer.h>
|
||||||
#include <LibMain/Main.h>
|
#include <LibMain/Main.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
@ -38,12 +39,6 @@ static Result average_result(const Vector<Result>& results)
|
||||||
return average;
|
return average;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void exit_with_usage(int rc)
|
|
||||||
{
|
|
||||||
warnln("Usage: disk_benchmark [-h] [-d directory] [-t time_per_benchmark] [-f file_size1,file_size2,...] [-b block_size1,block_size2,...]");
|
|
||||||
exit(rc);
|
|
||||||
}
|
|
||||||
|
|
||||||
static Optional<Result> benchmark(const String& filename, int file_size, int block_size, ByteBuffer& buffer, bool allow_cache);
|
static Optional<Result> benchmark(const String& filename, int file_size, int block_size, ByteBuffer& buffer, bool allow_cache);
|
||||||
|
|
||||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
|
@ -54,31 +49,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
Vector<size_t> block_sizes;
|
Vector<size_t> block_sizes;
|
||||||
bool allow_cache = false;
|
bool allow_cache = false;
|
||||||
|
|
||||||
int opt;
|
Core::ArgsParser args_parser;
|
||||||
while ((opt = getopt(arguments.argc, arguments.argv, "chd:t:f:b:")) != -1) {
|
args_parser.add_option(allow_cache, "Allow using disk cache", "cache", 'c');
|
||||||
switch (opt) {
|
args_parser.add_option(directory, "Path to a directory where we can store the disk benchmark temp file", "directory", 'd', "directory");
|
||||||
case 'h':
|
args_parser.add_option(time_per_benchmark, "Time elapsed per benchmark", "time-per-benchmark", 't', "time-per-benchmark");
|
||||||
exit_with_usage(0);
|
args_parser.add_option(file_sizes, "A comma-separated list of file sizes", "file-size", 'f', "file-size");
|
||||||
break;
|
args_parser.add_option(block_sizes, "A comma-separated list of block sizes", "block-size", 'b', "block-size");
|
||||||
case 'c':
|
args_parser.parse(arguments);
|
||||||
allow_cache = true;
|
|
||||||
break;
|
|
||||||
case 'd':
|
|
||||||
directory = optarg;
|
|
||||||
break;
|
|
||||||
case 't':
|
|
||||||
time_per_benchmark = atoi(optarg);
|
|
||||||
break;
|
|
||||||
case 'f':
|
|
||||||
for (const auto& size : String(optarg).split(','))
|
|
||||||
file_sizes.append(atoi(size.characters()));
|
|
||||||
break;
|
|
||||||
case 'b':
|
|
||||||
for (const auto& size : String(optarg).split(','))
|
|
||||||
block_sizes.append(atoi(size.characters()));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (file_sizes.size() == 0) {
|
if (file_sizes.size() == 0) {
|
||||||
file_sizes = { 131072, 262144, 524288, 1048576, 5242880 };
|
file_sizes = { 131072, 262144, 524288, 1048576, 5242880 };
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue