/********************************************************************** * * Disk Speed TEST Ver.Z * **********************************************************************/ #include #include #include #include #include #define BLOCK_SIZE 512 static char buffd[0xfff * 512]; /* Data Buffer */ int main(argc,argv) int argc; char *argv[]; { int fd; /*fildes*/ int wr_times; int bpa; /*blocks per access*/ int Bytes; /*bytes per access*/ int i; /* work counter */ time_t tloc0,tloc1;/* Access start, end time */ int w_time, r_time; /* Write, Read Access time */ float w_rate, r_rate; /* Write, Read Transefer Rate */ int tds; /* Total Data Size */ char sfname[256]; /* Special Device or File name */ /*argument check*/ if(argc <= 3) { fprintf(stderr, "usage : %s <1 Step Blocks> \n", argv[0]); exit(0); } /* Set Paramaters */ strcpy(sfname, argv[1]); strcat(sfname, "\0"); wr_times = atoi(argv[3]); bpa = atoi(argv[2]); Bytes = bpa * BLOCK_SIZE; tds = wr_times * Bytes; /* open file or special device */ if((fd=open(sfname,O_RDWR|O_CREAT,0666)) < 0){ fprintf(stderr, "Can not open Write/Read file\n"); exit(-1); } if( argc == 4 ) { fprintf(stdout, "*-------------------**-------------------*-------------------*\n"); fprintf(stdout, "| Transfer size || Write | Read |\n"); fprintf(stdout, "* **---------------------------------------*\n"); fprintf(stdout, "| (File Size) || MB/s | sec | MB/s | sec |\n"); fprintf(stdout, "*-------------------**----------*--------*----------*--------*\n"); } /* fprintf(stdout, "%d Bytes Write/Read(Step : %d Bytes)\n", tds, Bytes); */ fprintf(stdout, "| %3dKB (%4dMB) ||", (Bytes / 1024), (tds / (1024 *1024))); /* Write Speed Test */ time(&tloc0); /* Start time */ for( i = 0 ; i < wr_times ; i++) { if(write(fd,buffd,Bytes) != Bytes) { fprintf(stderr, "Write Error!!\n"); exit(-1); } } time(&tloc1); /* End time */ w_time = tloc1 - tloc0; w_rate = (float)tds/(float )(w_time * 1024 * 1024); /* fprintf(stdout," sequence Write time is %d sec\n",w_time); fprintf(stdout," Write Speed is %.1fMBytes/sec\n", w_rate ); */ fprintf(stdout, " %4.1f | %3d |", w_rate, w_time); /* if((fd=open(sfname,O_RDWR)) < 0){ fprintf(stderr, "!!! Can't Read File Open !!!!\n"); exit(-1); } */ lseek(fd,0L,0); /* Zero Seek */ /* Read Speed Test */ time(&tloc0); /* Start time */ for( i = 0; i < wr_times; i++) { if(read(fd,buffd,Bytes) != Bytes) { fprintf(stderr, "Read Error !!\n"); exit(-1); } } time(&tloc1); /* End time */ r_time = tloc1 - tloc0; r_rate = (float )tds / (float )(r_time * 1024 * 1024); /* fprintf(stdout," sequence Read time is %d sec\n", r_time); fprintf(stdout," Read Speed is %.1fMBytes/sec\n", r_rate); */ fprintf(stdout, " %4.1f | %3d |\n", r_rate, r_time); close(fd); fprintf(stdout, "*-------------------**----------*--------*----------*--------*\n"); return(0); }