Debian Codegraph @

util/bench/diskio/diskio.c

raw symbols SCIP
1 /*===========================================================================
2 Copyright (C) 1995-2005 European Southern Observatory (ESO)
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2 of
7 the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public
15 License along with this program; if not, write to the Free
16 Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
17 MA 02139, USA.
18
19 Correspondence concerning ESO-MIDAS should be addressed as follows:
20 Internet e-mail: [email protected]
21 Postal address: European Southern Observatory
22 Data Management Division
23 Karl-Schwarzschild-Strasse 2
24 D 85748 Garching bei Muenchen
25 GERMANY
26 ===========================================================================*/
27
28 /*
29
30 .VERSION
31 051021 last modif
32
33 */
34
35 #include <sys/file.h>
36 #include <sys/types.h>
37 #include <stdlib.h>
38 #include <string.h>
39
40 #ifdef SYSV_V2
41 #include <sys/times.h>
42 #else /* BSD */
43 #include <sys/timeb.h>
44 #endif
45
46 #ifndef CLK_TCK
47 #define CLK_TCK 60
48 #endif
49
50 #include <sys/stat.h>
51 /*
52 * Size of test file.
53 * Should make this large with respect
54 * to size of buffer cache.
55 */
56 #define MBYTES 16
57
58 /*
59 * Size of memory allocated to remove cache
60 */
61 #define MAX_MEM 512
62
63 /*
64 * Sleep time, to let other system to recover
65 */
66 #define SLEEP_TIME 10
67
68
69 main( argc, argv)
70 char **argv;
71 {
72 register int i, j;
73 register char *buf;
74 #ifdef SYSV_V2
75 struct tms buffer;
76 int start, end;
77 #else /* BSD */
78 struct timeb start, end;
79 #endif
80 float writetime, readtime;
81 struct stat sbuf;
82 int nblocks;
83 float filesize;
84 register char * max_mem_ptr;
85
86 /**/
87 printf("Allocating %d MB RAM to remove cache...\n",MAX_MEM);
88 max_mem_ptr = calloc(1024*1024*MAX_MEM,1);
89 free(max_mem_ptr);
90 printf("and freeing it\n");
91
92 printf("Sleeping %d second to let system to recover\n", SLEEP_TIME);
93 sleep(SLEEP_TIME);
94 /**/
95
96 printf("Run this on an idle system.\n");
97 if (argc < 2) {
98 printf("Give filename as argument.\n");
99 exit(1);
100 }
101
102 /*
103 * Write test.
104 */
105 j = creat(argv[1], 0666);
106 fstat(j, &sbuf); /* find optimum blocksize */
107 printf("blocksize = %d\n", sbuf.st_blksize);
108 buf = (char *) malloc((size_t)sbuf.st_blksize);
109 nblocks = (MBYTES*1024*1000)/sbuf.st_blksize;
110 filesize = (nblocks * sbuf.st_blksize)/(1024*1000);
111 #ifdef SYSV_V2
112 start=times(&buffer);
113 for (i = 0; i < nblocks; i++) write(j, buf, sbuf.st_blksize);
114 end=times(&buffer);
115 writetime = (float)(end - start)/(float)CLK_TCK;
116 #else /* BSD */
117 ftime(&start);
118 for (i = 0; i < nblocks; i++) write(j, buf, sbuf.st_blksize);
119 ftime(&end);
120 writetime = ((end.time - 1) - start.time) +
121 ((end.millitm + 1000) - start.millitm)/1000.0;
122 #endif
123 printf("write time = %.3f, speed = %.3f Mbytes/sec\n",
124 writetime, filesize/writetime);
125 close(j);
126
127 /*
128 * Read test.
129 */
130 j = open(argv[2], 0);
131 #ifdef SYSV_V2
132 start=times(&buffer);
133 for (i = 0; i < nblocks; i++) read(j, buf, sbuf.st_blksize);
134 end=times(&buffer);
135 readtime = (float)(end - start)/(float)CLK_TCK;
136 #else /* BSD */
137 ftime(&start);
138 for (i = 0; i < nblocks; i++) read(j, buf, sbuf.st_blksize);
139 ftime(&end);
140 readtime = ((end.time - 1) - start.time) +
141 ((end.millitm + 1000) - start.millitm)/1000.0;
142 #endif
143 printf("read time = %.3f, speed = %.3f Mbytes/sec\n",
144 readtime, filesize/readtime);
145 close(j);
146
147 /*
148 * Get rid of junk lying around.
149 */
150 /*
151 unlink(argv[1]);
152 */
153
154 printf("Average I/O performance = %.3f Mbytes/sec\n",
155 filesize/((writetime + readtime)/2));
156 exit(0);
157 }