2
Copyright (C) 2003-2004 Douglas Thain and the University of Wisconsin
3
Copyright (C) 2005- The University of Notre Dame
4
This software is distributed under the GNU General Public License.
5
See the file COPYING for details.
8
#include "chirp_reli.h"
23
#ifndef CCTOOLS_OPSYS_CYGWIN
24
#include <sys/syscall.h>
30
double measure[10000];
37
int measure_bandwidth = 0;
39
#ifdef CCTOOLS_OPSYS_DARWIN
42
#define do_sync (getenv("CHIRP_SYNC") ? O_SYNC : 0)
45
long do_open( const char *file, int flags, int mode )
48
return (long) chirp_reli_open(host,file,flags,mode,stoptime);
50
return open(file,flags,mode);
54
int do_close( long fd )
57
return chirp_reli_close((struct chirp_file*)fd,stoptime);
63
int do_fsync( long fd )
72
int do_pread( long fd, char *buffer, int length, int offset )
75
return chirp_reli_pread((struct chirp_file*)fd,buffer,length,offset,stoptime);
77
return full_pread(fd,buffer,length,offset);
81
int do_pwrite( long fd, const char *buffer, int length, int offset )
84
return chirp_reli_pwrite((struct chirp_file*)fd,buffer,length,offset,stoptime);
86
return full_pwrite(fd,buffer,length,offset);
90
int do_stat( const char *file, struct stat *buf )
93
struct chirp_stat lbuf;
94
return chirp_reli_stat(host,file,&lbuf,stoptime);
96
return stat(file,buf);
100
int do_bandwidth( const char *file, int bytes, int blocksize, int do_write )
104
char *buffer = malloc(blocksize);
107
for(i=0;i<blocksize;i++) buffer[i] = (char)i;
109
fd = do_open(file,(do_write ? O_WRONLY : O_RDONLY)|O_CREAT|do_sync,0777);
111
printf("couldn't open %s: %s",file,strerror(errno));
117
do_pwrite(fd,buffer,blocksize,offset);
119
do_pread(fd,buffer,blocksize,offset);
135
for(j=0;j<cycles;j++) total += measure[j];
136
average = total/cycles;
137
for(j=0;j<cycles;j++) variance += (measure[j]-average)*(measure[j]-average);
138
stddev = sqrt(variance/(cycles-1));
140
printf("%9.4f +/- %9.4f ",average,stddev);
142
if(measure_bandwidth) {
149
#define RUN_LOOP( name, test ) \
150
printf("%s\t",name);\
151
for(j=0;j<cycles;j++) {\
152
gettimeofday( &start, 0 );\
153
for( i=0; i<loops; i++ ) {\
156
gettimeofday( &stop, 0 );\
157
runtime = (stop.tv_sec-start.tv_sec)*1000000 + (stop.tv_usec-start.tv_usec);\
158
if(measure_bandwidth) {\
159
measure[j] = (filesize*loops/(double)runtime);\
161
measure[j] = ((double)(runtime))/loops;\
167
int main( int argc, char *argv[] )
176
struct timeval start, stop;
177
stoptime = time(0)+3600;
178
int filesize = 16*1024*1024;
181
printf("use: %s <host> <file> <loops> <cycles> <bwloops>\n",argv[0]);
189
loops = atoi(argv[3]);
190
cycles = atoi(argv[4]);
191
bwloops = atoi(argv[5]);
193
if(!strcmp(host,"unix")) {
200
RUN_LOOP("getpid",syscall(SYS_getpid));
202
RUN_LOOP("getpid",getpid());
205
fd = do_open(fname,O_WRONLY|O_CREAT|do_sync,0777);
211
RUN_LOOP("write1",do_pwrite(fd,data,1,0));
212
RUN_LOOP("write8",do_pwrite(fd,data,8192,0));
216
fd = do_open(fname,O_RDONLY|do_sync,0777);
222
RUN_LOOP("read1",do_pread(fd,data,1,0));
223
RUN_LOOP("read8",do_pread(fd,data,8192,0));
227
RUN_LOOP("stat",do_stat(fname,&buf));
228
RUN_LOOP("open",fd = do_open(fname,O_RDONLY|do_sync,0777); do_close(fd); );
230
if(bwloops==0) return 0;
233
measure_bandwidth = 1;
235
for(k=filesize;k>=(4*1024);k=k/2) {
236
printf("%4d ",k/1024);
237
RUN_LOOP("write",do_bandwidth(fname,filesize,k,1));
239
printf("%4d ",k/1024);
240
RUN_LOOP("read",do_bandwidth(fname,filesize,k,0));