mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-23 17:52:26 -05:00
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.
This commit is contained in:
parent
59ed235c85
commit
173ae370db
Notes:
sideshowbarker
2024-07-19 11:22:07 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/173ae370db1
1 changed files with 13 additions and 5 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue