93 lines
2.7 KiB
C
Executable File
93 lines
2.7 KiB
C
Executable File
#include "test_utils.h"
|
|
|
|
static int test_single_file_perf(const char *path)
|
|
{
|
|
size_t io_size = 128 * 1024;
|
|
size_t max_size = 2ULL * 1024 * 1024 * 1024;
|
|
size_t max_count = max_size / io_size;
|
|
int test_sec = 10;
|
|
int direct = 0;
|
|
|
|
printf("\n=== test_single_file_perf ===\n");
|
|
printf("Path : %s\n", path);
|
|
printf("IO size : %zu KB\n", io_size / 1024);
|
|
printf("Max file: %zu MB\n", max_size / 1024 / 1024);
|
|
printf("Duration: %d sec\n", test_sec);
|
|
|
|
unlink(path);
|
|
char *buf = aligned_alloc(4096, io_size);
|
|
if (!buf) { perror("aligned_alloc"); return 1; }
|
|
memset(buf, 'A', io_size);
|
|
|
|
struct timespec t1, t2, now;
|
|
|
|
int fd = open(path, O_CREAT | O_RDWR | direct, 0644);
|
|
if (fd < 0) { perror("open write"); free(buf); return 1; }
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &t1);
|
|
size_t wcount = 0;
|
|
size_t wpos = 0;
|
|
do {
|
|
if (wpos >= max_count) {
|
|
lseek(fd, 0, SEEK_SET);
|
|
wpos = 0;
|
|
}
|
|
if (write(fd, buf, io_size) != (ssize_t)io_size) {
|
|
perror("write");
|
|
close(fd);
|
|
free(buf);
|
|
return 2;
|
|
}
|
|
wcount++;
|
|
wpos++;
|
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
|
} while (time_diff_sec(t1, now) < test_sec);
|
|
clock_gettime(CLOCK_MONOTONIC, &t2);
|
|
close(fd);
|
|
|
|
double wsec = time_diff_sec(t1, t2);
|
|
double wmb = (double)(wcount * io_size) / (1024.0 * 1024.0);
|
|
printf("\nWRITE:\n");
|
|
printf(" total : %.1f MB\n", wmb);
|
|
printf(" time : %.3f sec\n", wsec);
|
|
printf(" IOPS : %.0f ops/sec\n", wcount / wsec);
|
|
printf(" BW : %.2f MB/s\n", wmb / wsec);
|
|
|
|
fd = open(path, O_RDONLY | direct);
|
|
if (fd < 0) { perror("open read"); free(buf); return 3; }
|
|
|
|
clock_gettime(CLOCK_MONOTONIC, &t1);
|
|
size_t rcount = 0;
|
|
do {
|
|
ssize_t r = read(fd, buf, io_size);
|
|
if (r <= 0) {
|
|
lseek(fd, 0, SEEK_SET);
|
|
continue;
|
|
}
|
|
rcount++;
|
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
|
} while (time_diff_sec(t1, now) < test_sec);
|
|
clock_gettime(CLOCK_MONOTONIC, &t2);
|
|
close(fd);
|
|
|
|
double rsec = time_diff_sec(t1, t2);
|
|
double rmb = (double)(rcount * io_size) / (1024.0 * 1024.0);
|
|
printf("\nREAD:\n");
|
|
printf(" total : %.1f MB\n", rmb);
|
|
printf(" time : %.3f sec\n", rsec);
|
|
printf(" IOPS : %.0f ops/sec\n", rcount / rsec);
|
|
printf(" BW : %.2f MB/s\n", rmb / rsec);
|
|
|
|
unlink(path);
|
|
free(buf);
|
|
return 0;
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
char path[PATH_MAX];
|
|
make_path(path, sizeof(path), argc >= 2 ? argv[1] : NULL, "file.dat");
|
|
int rc = test_single_file_perf(path);
|
|
return report_result("test_single_file_perf", rc);
|
|
}
|