diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-11-05 19:37:23 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-11-05 19:37:23 +0100 |
commit | 173ae370db1a3aa398c26cf7f5b1ecf150292856 (patch) | |
tree | 07c5029373941942f0dedfda7ef1f048fee1827b | |
parent | 59ed235c857692c427777465ad55f4157e0f44da (diff) | |
download | serenity-173ae370db1a3aa398c26cf7f5b1ecf150292856.zip |
disk_benchmark: Add a -c flag to enable use of disk caches
By default, disk_benchmark will now use the O_DIRECT flag, causing it
to bypass the kernel's disk caches. This gives you "disk performance"
numbers rather than "disk cache performance" numbers.
You can use "disk_benchmark -c" to enable the caches.
Fixes #703.
-rw-r--r-- | Userland/disk_benchmark.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/Userland/disk_benchmark.cpp b/Userland/disk_benchmark.cpp index 932ae51f01..31cad04967 100644 --- a/Userland/disk_benchmark.cpp +++ b/Userland/disk_benchmark.cpp @@ -36,7 +36,7 @@ void exit_with_usage(int rc) exit(rc); } -Result benchmark(const String& filename, int file_size, int block_size, ByteBuffer& buffer); +Result benchmark(const String& filename, int file_size, int block_size, ByteBuffer& buffer, bool allow_cache); int main(int argc, char** argv) { @@ -44,13 +44,17 @@ int main(int argc, char** argv) int time_per_benchmark = 10; Vector<int> file_sizes; Vector<int> block_sizes; + bool allow_cache = false; int opt; - while ((opt = getopt(argc, argv, "hd:t:f:b:")) != -1) { + while ((opt = getopt(argc, argv, "chd:t:f:b:")) != -1) { switch (opt) { case 'h': exit_with_usage(0); break; + case 'c': + allow_cache = true; + break; case 'd': directory = strdup(optarg); break; @@ -94,7 +98,7 @@ int main(int argc, char** argv) while (timer.elapsed() < time_per_benchmark * 1000) { printf("."); fflush(stdout); - results.append(benchmark(filename, file_size, block_size, buffer)); + results.append(benchmark(filename, file_size, block_size, buffer, allow_cache)); usleep(100); } auto average = average_result(results); @@ -110,9 +114,13 @@ int main(int argc, char** argv) } } -Result benchmark(const String& filename, int file_size, int block_size, ByteBuffer& buffer) +Result benchmark(const String& filename, int file_size, int block_size, ByteBuffer& buffer, bool allow_cache) { - int fd = open(filename.characters(), O_CREAT | O_TRUNC | O_WRONLY); + int flags = O_CREAT | O_TRUNC | O_WRONLY; + if (!allow_cache) + flags |= O_DIRECT; + + int fd = open(filename.characters(), flags); if (fd == -1) { perror("open"); exit(1); |