⬢ DragonFlyBSD Kernel Audit
DF-2438 / delaytime.c
← back to finding ↓ download raw
/* DF-2438: measure completion latency of a 4KB write on dm-delay volumes */
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <time.h>
#include <string.h>
int main(int argc, char **argv) {
    int fd = open(argv[1], O_WRONLY);
    char buf[4096]; memset(buf, 0x41, sizeof(buf));
    if (fd < 0) { perror("open"); return 1; }
    struct timespec a, b;
    clock_gettime(CLOCK_MONOTONIC, &a);
    if (write(fd, buf, 4096) != 4096) { perror("write"); return 1; }
    clock_gettime(CLOCK_MONOTONIC, &b);
    double ms = (b.tv_sec - a.tv_sec) * 1000.0 + (b.tv_nsec - a.tv_nsec) / 1e6;
    printf("%s: write completed in %.2f ms\n", argv[1], ms);
    close(fd);
    return 0;
}