2
Copyright (C) 2009- The University of Notre Dame
3
This software is distributed under the GNU General Public License.
4
See the file COPYING for details.
14
#include <sys/types.h>
29
#define BUFFER_SIZE 8192
31
const char *OP_STRINGS[NOPS] = { "stat ", "open ", "write", "read ", "fsync", "close" };
33
static int OPEN_FLAGS = O_RDONLY;
35
static void show_help(const char *cmd)
37
printf("Use: %s <path> <runs> [write]\n", cmd);
40
static void do_stat(const char *path)
46
result = stat(path, &buf);
50
printf("could not stat %s: %s\n", path, strerror(errno));
55
static void do_open(const char *path, int *fd)
58
*fd = open(path, OPEN_FLAGS);
62
printf("could not open %s: %s\n", path, strerror(errno));
67
static void do_write(int fd)
69
char buffer[BUFFER_SIZE];
70
int result, count = 0;
72
timer_start(OP_WRITE);
74
result = write(fd, &buffer[count], BUFFER_SIZE - count);
76
} while (result != -1 && count < BUFFER_SIZE);
80
printf("could not write: %s\n", strerror(errno));
85
static void do_read(int fd)
87
char buffer[BUFFER_SIZE];
91
result = read(fd, buffer, BUFFER_SIZE);
95
printf("could not read: %s\n", strerror(errno));
100
static void do_fsync(int fd)
104
timer_start(OP_FSYNC);
106
timer_stop(OP_FSYNC);
109
printf("could not fsync: %s\n", strerror(errno));
114
static void do_close(int fd)
116
timer_start(OP_CLOSE);
118
timer_stop(OP_CLOSE);
121
int main(int argc, char *argv[])
128
return (EXIT_FAILURE);
132
runs = atoi(argv[2]);
134
if (4 == argc && 0 == strcmp(argv[3], "write")) {
138
timer_init(NOPS, OP_STRINGS);
141
timer_reset(OP_STAT);
143
for (i = 0; i < runs; i++) {
146
if (O_RDWR == OPEN_FLAGS) do_write(fd);
152
timer_print_summary(0);
155
return (EXIT_SUCCESS);
159
* vim: sts=8 sw=8 ts=8 ft=c