diff options
author | dzwdz | 2023-09-22 23:42:30 +0200 |
---|---|---|
committer | dzwdz | 2023-09-22 23:42:30 +0200 |
commit | 6a4d4a41a664e6a4c406a449ea847abd4a224bcf (patch) | |
tree | 0a637697c8697929beb8f4b7ff69d8b74f9e28bb /src/cmd/iostress.c | |
parent | a3d6aa9f8d427b86a33dc05bed98a2e88229a285 (diff) |
build: support single file commands
Diffstat (limited to 'src/cmd/iostress.c')
-rw-r--r-- | src/cmd/iostress.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/cmd/iostress.c b/src/cmd/iostress.c new file mode 100644 index 0000000..ac555de --- /dev/null +++ b/src/cmd/iostress.c @@ -0,0 +1,43 @@ +#include <camellia/syscalls.h> +#include <errno.h> +#include <stdio.h> +#include <string.h> +#include <x86intrin.h> + +int main(int argc, char **argv) { + long num_runs = 4; + long num_calls = 512; + long num_bytes = 1; + uint64_t *results; + char *inbuf; + + if (argc > 1) num_runs = strtol(argv[1], NULL, 0); + if (argc > 2) num_calls = strtol(argv[2], NULL, 0); + if (argc > 3) num_bytes = strtol(argv[3], NULL, 0); + if (argc > 4 || num_runs == 0 || num_calls == 0) { + fprintf(stderr, "usage: %s [num_runs] [num_calls] [num_bytes]\n", argv[0]); + return 1; + } + + results = malloc(sizeof(*results) * num_runs); + inbuf = malloc(num_bytes); + memset(inbuf, '.', num_bytes); + + for (long i = 0; i < num_runs; i++) { + uint64_t time = __rdtsc(); + for (long j = 0; j < num_calls; j++) + _sys_write(1, inbuf, num_bytes, -1, 0); + results[i] = __rdtsc() - time; + _sys_write(1, "\n", 1, -1, 0); + } + + uint64_t total = 0; + for (long i = 0; i < num_runs; i++) { + uint64_t scaled = results[i] / 3000; + total += scaled; + fprintf(stderr, "run %ld: %lu\n", i, scaled); + } + fprintf(stderr, "%lu calls, %lu bytes. avg %lu\n", num_calls, num_bytes, total / num_runs); + + return 0; +} |