/***************************************************************************** * * read_random_big.c 2012.07.04 Smythies * This program needs to also work when compiled and executed on 32 bit * computers. Try to make 64 or 32 bit independent. * Troubles with fseek on 32 bit, try lseek. * * read_random_big.c 2012.07.03 Smythies * Change the method of printing information away from per number of seeks * and to some delta time. The seek time is highly inconsistant. * * read_random_big.c 2012.07.02 Smythies * Read random locations of blocks of data in a big file. * The file was likely created by trandbig.c * The purpose is to create a situation of large amount of time spent * doing seeks, or a lrage percentgae of time in an IO wait state. * This seems to be pretty slow at doing seeks, but the point is to create * IO wait time, so O.K. * Smythies *****************************************************************************/ #define _FILE_OFFSET_BITS 64 #include #include #include #include #include #include #include #include //#include #define GIGS 8 #define WRITE_SIZE 1048576 #define PRINT_INTERVAL 60.0 #define THRESHOLD 0.1 char buffer[WRITE_SIZE]; main(){ clock_t start, end, last; struct tms t_start, t_end; char temp; int the_byte; long j, tps, multiplier, old_seeks; long long i, old_i, total_bytes, the_return_code; double elapsed, next, delta, longest; unsigned inf; if((inf = open("big",O_RDONLY)) == -1){ printf("Unable to open input file\n"); exit(-1); } /* endif */ srand(31); total_bytes = (long long) GIGS * (long long) WRITE_SIZE * (long long) 1024; multiplier = total_bytes / RAND_MAX; j = 0; old_seeks = 0; // printf("read_random_big: LONG_MAX: %ld RAND_MAX: %d\n", 7l, RAND_MAX); printf("read_random_big: total bytes in file \"big\" (a compile time number): %lld multiplier: %ld\n", total_bytes, multiplier); tps = sysconf(_SC_CLK_TCK); start = times(&t_start); /* */ end = start; next = PRINT_INTERVAL; old_i = 0; longest = 0.0; while(1){ /* forever */ i = (long long) rand(); i = i * multiplier; the_return_code = lseek(inf, i, SEEK_SET); // printf("read_random_big: %ld %d\n", i, the_return_code); if(the_return_code == -1){ printf("some file seek error\n"); exit(1); } /* endif */ if(the_return_code != i){ printf("seek offset not as asked for: %lld %lld\n", the_return_code, i); exit(1); } /* endif */ the_byte = read(inf, buffer, 1); /* fetch an actual byte from the location */ j++; last = end; end = times(&t_end); /* */ delta = (double)(end - last) / (double)(tps); /* */ elapsed = (double)(end - start) / (double)(tps); /* */ if(delta > longest){ longest = delta; printf("read_random_big: New longest seek time: %5.2lf seconds. Seek number: %7ld (%lld %lld)\n", delta, j, i, old_i); } /* endif */ if(delta >= THRESHOLD){ printf("read_random_big: Excessive seek time: %5.2lf seconds. Seek number: %7ld (%lld %lld)\n", delta, j, i, old_i); } /* endif */ if(elapsed >= next){ printf("read_random_big:%7ld seeks: (%5.0lf /s (last)) elapsed time: %7.1lf seconds ", j, (double) (j - old_seeks) / (PRINT_INTERVAL + elapsed - next), elapsed); printf("user cpu:%7.2f s. ", ((float)(t_end.tms_utime) / (float) (tps))); printf("sys cpu:%7.2f s. ", ((float)(t_end.tms_stime) / (float) (tps))); printf("longest seek: %6.3f s. ", longest); printf("\n"); next = next + PRINT_INTERVAL; /* prevents accumulation of errors */ old_seeks = j; } /* endif */ old_i = i; } /* endwhile */ close(inf); /* it never actually gets here */ return(0); } /* endprogram */