2 * Copyright (c) 2000-2003 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
33 #include <sys/param.h>
43 typedef void *(*fpi_t)(void);
44 typedef void (*fpt_t)(int, void *);
45 typedef void (*fpd_t)(void *);
54 static void d_readdir(void *);
55 static void *i_readdir(void);
56 static void t_readdir(int, void *);
57 static void crfiles(char **, int, char *);
58 static void d_chown(void *);
59 static void d_create(void *);
60 static void d_linkun(void *);
61 static void d_open(void *);
62 static void d_rename(void *);
63 static void d_stat(void *);
64 static void delflist(char **);
65 static void dotest(tdesc_t *);
66 static void *i_chown(void);
67 static void *i_create(void);
68 static void *i_linkun(void);
69 static void *i_open(void);
70 static void *i_rename(void);
71 static void *i_stat(void);
72 static char **mkflist(int, int, char);
73 static double now(void);
74 static void prtime(char *, int, double);
75 static void rmfiles(char **);
76 static void t_chown(int, void *);
77 static void t_create(int, void *);
78 static void t_crunlink(int, void *);
79 static void t_linkun(int, void *);
80 static void t_open(int, void *);
81 static void t_rename(int, void *);
82 static void t_stat(int, void *);
83 static void usage(void);
86 { "chown", i_chown, t_chown, d_chown },
87 { "create", i_create, t_create, d_create },
88 { "crunlink", (fpi_t)0, t_crunlink, (fpd_t)0 },
89 { "readdir", i_readdir, t_readdir, d_readdir },
90 { "linkun", i_linkun, t_linkun, d_linkun },
91 { "open", i_open, t_open, d_open },
92 { "rename", i_rename, t_rename, d_rename },
93 { "stat", i_stat, t_stat, d_stat },
113 main(int argc, char **argv)
119 testdir = getenv("TMPDIR");
122 while ((c = getopt(argc, argv, "cd:i:l:L:n:N:s:t:v")) != -1) {
131 iters = atoi(optarg);
134 fnlen_op = atoi(optarg);
137 fnlen_bg = atoi(optarg);
140 files_op = atoi(optarg);
143 files_bg = atoi(optarg);
146 fsize = atoi(optarg);
149 totsec = atoi(optarg);
155 fprintf(stderr, "bad option\n");
159 if (!iters && !totsec)
161 if (chdir(testdir) < 0) {
165 if (mkdir("metaperf", 0777) < 0 || chdir("metaperf") < 0) {
169 for (; optind < argc; optind++) {
170 for (tp = tests; tp->name; tp++) {
171 if (strcmp(argv[optind], tp->name) == 0) {
183 crfiles(char **flist, int fsize, char *buf)
188 for (fnp = flist; *fnp; fnp++) {
189 fd = creat(*fnp, 0666);
191 write(fd, buf, fsize);
236 delflist((char **)v);
247 delflist(char **flist)
251 for (fnp = flist; *fnp; fnp++)
264 flist_bg = mkflist(files_bg, fnlen_bg, 'b');
265 flist_op = mkflist(files_op, fnlen_op, 'o');
267 buffer = calloc(fsize, 1);
270 crfiles(flist_bg, 0, (char *)0);
271 n = iters ? iters : 1;
283 gotsec = time_end - time_start;
284 if (!totsec || gotsec >= 0.9 * totsec)
287 prtime(tp->name, n, gotsec);
289 gotsec = 1.0 / (2 * HZ);
290 if (gotsec < 0.001 * totsec)
291 dn = n * (0.01 * totsec / gotsec);
292 else if (gotsec < 0.01 * totsec)
293 dn = n * (0.1 * totsec / gotsec);
295 dn = n * (totsec / gotsec);
301 prtime(tp->name, n, gotsec);
314 crfiles(flist_op, 0, (char *)0);
315 for (fnp = flist_op; *fnp; fnp++)
323 crfiles(flist_op, fsize, buffer);
330 crfiles(flist_op, 0, (char *)0);
337 close(creat("a", 0666));
344 crfiles(flist_op, 0, (char *)0);
351 crfiles(flist_op, 0, (char *)0);
352 return (void *)mkflist(files_op, fnlen_op, 'r');
358 crfiles(flist_op, 0, (char *)0);
363 mkflist(int files, int fnlen, char start)
368 rval = calloc(files + 1, sizeof(char *));
369 for (i = 0; i < files; i++) {
370 rval[i] = malloc(fnlen + 1);
371 sprintf(rval[i], "%0*d%c", fnlen - 1, i, start);
381 gettimeofday(&t, (void *)0);
382 return (double)t.tv_sec + 1.0e-6 * (double)t.tv_usec;
386 prtime(char *name, int n, double t)
391 ops_per_sec = (double)n * (double)files_op / t;
392 usec_per_op = t * 1.0e6 / ((double)n * (double)files_op);
394 printf("%s %d %d %d %d %d %d %f %f %f\n",
395 name, n, files_op, fnlen_op, fsize, files_bg, fnlen_bg,
396 t, ops_per_sec, usec_per_op);
398 printf("%s: %d times, %d file(s) namelen %d",
399 name, n, files_op, fnlen_op);
401 printf(" size %d", fsize);
403 printf(", bg %d file(s) namelen %d",
405 printf(", time = %f sec, ops/sec=%f, usec/op = %f\n",
406 t, ops_per_sec, usec_per_op);
411 rmfiles(char **flist)
415 for (fnp = flist; *fnp; fnp++)
421 t_chown(int n, void *v)
426 for (i = 0; i < n; i++) {
427 for (fnp = flist_op; *fnp; fnp++) {
438 t_create(int n, void *v)
442 for (i = 0; i < n; i++)
443 crfiles(flist_op, fsize, buffer);
448 t_crunlink(int n, void *v)
452 for (i = 0; i < n; i++) {
453 crfiles(flist_op, fsize, buffer);
459 t_readdir(int n, void *v)
464 for (dir = (DIR *)v, i = 0; i < n; i++) {
466 while ((readdir(dir)) != NULL);
472 t_linkun(int n, void *v)
477 for (i = 0; i < n; i++) {
478 for (fnp = flist_op; *fnp; fnp++)
486 t_open(int n, void *v)
491 for (i = 0; i < n; i++) {
492 for (fnp = flist_op; *fnp; fnp++)
493 close(open(*fnp, O_RDWR));
498 t_rename(int n, void *v)
505 for (rflist = (char **)v, i = 0; i < n; i++) {
506 for (fnp = flist_op, rfp = rflist; *fnp; fnp++, rfp++) {
517 t_stat(int n, void *v)
523 for (i = 0; i < n; i++) {
524 for (fnp = flist_op; *fnp; fnp++)
533 "Usage: metaperf [-d dname] [-i iters|-t seconds] [-s fsize]\n"
534 "\t[-l opfnamelen] [-L bgfnamelen]\n"
535 "\t[-n opfcount] [-N bgfcount] test...\n");
537 "Tests: chown create crunlink linkun open rename stat readdir\n");