summaryrefslogtreecommitdiff
path: root/Userland/Utilities
diff options
context:
space:
mode:
authorKenneth Myhra <kennethmyhra@gmail.com>2022-03-25 22:17:12 +0100
committerTim Flynn <trflynn89@pm.me>2022-03-27 08:33:24 -0400
commitc0f15ebcbbb33da96a437fcf998d2ea917850db5 (patch)
tree13f579dd0e5e21bf3e7fe12c23b49442c64cb213 /Userland/Utilities
parent23a87a41ff16e0197b77ba1f80a75dec48addd19 (diff)
downloadserenity-c0f15ebcbbb33da96a437fcf998d2ea917850db5.zip
disk_benchmark: Core::ArgsParser to parse arguments
Diffstat (limited to 'Userland/Utilities')
-rw-r--r--Userland/Utilities/disk_benchmark.cpp39
1 files changed, 8 insertions, 31 deletions
diff --git a/Userland/Utilities/disk_benchmark.cpp b/Userland/Utilities/disk_benchmark.cpp
index 3d2b8d674a..74239f1b73 100644
--- a/Userland/Utilities/disk_benchmark.cpp
+++ b/Userland/Utilities/disk_benchmark.cpp
@@ -9,6 +9,7 @@
#include <AK/String.h>
#include <AK/Types.h>
#include <AK/Vector.h>
+#include <LibCore/ArgsParser.h>
#include <LibCore/ElapsedTimer.h>
#include <LibMain/Main.h>
#include <fcntl.h>
@@ -38,12 +39,6 @@ static Result average_result(const Vector<Result>& results)
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);
ErrorOr<int> serenity_main(Main::Arguments arguments)
@@ -54,31 +49,13 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
Vector<size_t> block_sizes;
bool allow_cache = false;
- int opt;
- while ((opt = getopt(arguments.argc, arguments.argv, "chd:t:f:b:")) != -1) {
- switch (opt) {
- case 'h':
- exit_with_usage(0);
- break;
- case 'c':
- 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;
- }
- }
+ Core::ArgsParser args_parser;
+ args_parser.add_option(allow_cache, "Allow using disk cache", "cache", 'c');
+ args_parser.add_option(directory, "Path to a directory where we can store the disk benchmark temp file", "directory", 'd', "directory");
+ args_parser.add_option(time_per_benchmark, "Time elapsed per benchmark", "time-per-benchmark", 't', "time-per-benchmark");
+ args_parser.add_option(file_sizes, "A comma-separated list of file sizes", "file-size", 'f', "file-size");
+ args_parser.add_option(block_sizes, "A comma-separated list of block sizes", "block-size", 'b', "block-size");
+ args_parser.parse(arguments);
if (file_sizes.size() == 0) {
file_sizes = { 131072, 262144, 524288, 1048576, 5242880 };