4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2017, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
37 #include <sys/types.h>
48 static void usage(char *prog)
50 printf("usage: %s {-w|-a|-r} filenamefmt count seconds\n"
53 "-r : read mode\n", prog);
57 int main(int argc, char **argv)
59 int do_read = 0, do_append = 0;
62 long end = ~0UL >> 1, count = ~0UL >> 1;
63 int c, i, fd, rc = 0, len, mode = 0;
67 while ((c = getopt(argc, argv, "war")) != -1) {
74 mode = O_RDWR | O_APPEND;
81 printf("Unknown option '%c'\n", optopt);
86 if (optind + 3 != argc) {
88 "missing filenamebase, total_files, or seconds\n");
93 if (strlen(base) > 4080) {
94 fprintf(stderr, "filenamebase too long\n");
98 count = strtoul(argv[optind + 1], NULL, 0);
100 end = strtoul(argv[optind + 2], &endp, 0);
101 if (end <= 0 && *endp != '\0') {
102 fprintf(stderr, "%s: error: bad number of seconds '%s'\n",
103 argv[0], argv[optind + 2]);
109 start = last = time(0);
112 for (i = 0; i < count && time(0) < end; i++) {
115 snprintf(filename, sizeof(filename), "%s%d", base, i);
117 fd = open(filename, mode, 0666);
119 fprintf(stderr, "fail to open %s\n", filename);
124 len = random() % 4096;
127 c = write(fd, buf, len);
129 fprintf(stderr, "fail to write %s, len %d,"
130 " written %d\n", filename, len, c);
135 c = read(fd, buf, len);
140 fprintf(stderr, "can't close %s\n", filename);
145 if (i && (i % 10000) == 0) {
146 printf(" - %ld bytes (time %ld total %ld last %ld)"
147 "\n", nbytes, time(0), time(0) - start,
152 printf("total: %s %ld bytes in %ld seconds: %.2f bytes/second\n",
153 do_read ? "read" : do_append ? "append" : "write", nbytes,
154 time(0) - start, ((double)nbytes / (time(0) - start)));