Ejemplo n.º 1
0
void
dir_create(int x)
{
    int i,j;
    int ret;
    char buf[100];
    stats[_STAT_DIR_CREATE].best=(double)99999.9;
    stats[_STAT_DIR_CREATE].worst=(double)0.00000000;
    for(i=0; i<x; i++)
    {
        sprintf(buf,"iozone_L1_%d",i);
        stats[_STAT_DIR_CREATE].starttime=time_so_far();
        ret=mkdir(buf,0777);
        if(ret < 0)
        {
            printf("Mkdir failed\n");
            exit(1);
        }
        stats[_STAT_DIR_CREATE].endtime=time_so_far();
        stats[_STAT_DIR_CREATE].speed=stats[_STAT_DIR_CREATE].endtime-stats[_STAT_DIR_CREATE].starttime;
        if(stats[_STAT_DIR_CREATE].speed < (double)0.0)
            stats[_STAT_DIR_CREATE].speed=(double)0.0;
        stats[_STAT_DIR_CREATE].total_time+=stats[_STAT_DIR_CREATE].speed;
        stats[_STAT_DIR_CREATE].counter++;
        if(stats[_STAT_DIR_CREATE].speed < stats[_STAT_DIR_CREATE].best)
            stats[_STAT_DIR_CREATE].best=stats[_STAT_DIR_CREATE].speed;
        if(stats[_STAT_DIR_CREATE].speed > stats[_STAT_DIR_CREATE].worst)
            stats[_STAT_DIR_CREATE].worst=stats[_STAT_DIR_CREATE].speed;
        chdir(buf);
        for(j=0; j<x; j++)
        {
            sprintf(buf,"iozone_L1_%d_L2_%d",i,j);
            stats[_STAT_DIR_CREATE].starttime=time_so_far();
            ret=mkdir(buf,0777);
            if(ret < 0)
            {
                printf("Mkdir failed\n");
                exit(1);
            }
            stats[_STAT_DIR_CREATE].endtime=time_so_far();
            stats[_STAT_DIR_CREATE].speed=stats[_STAT_DIR_CREATE].endtime-stats[_STAT_DIR_CREATE].starttime;
            if(stats[_STAT_DIR_CREATE].speed < (double)0.0)
                stats[_STAT_DIR_CREATE].speed=(double) 0.0;
            stats[_STAT_DIR_CREATE].total_time+=stats[_STAT_DIR_CREATE].speed;
            stats[_STAT_DIR_CREATE].counter++;
            if(stats[_STAT_DIR_CREATE].speed < stats[_STAT_DIR_CREATE].best)
                stats[_STAT_DIR_CREATE].best=stats[_STAT_DIR_CREATE].speed;
            if(stats[_STAT_DIR_CREATE].speed > stats[_STAT_DIR_CREATE].worst)
                stats[_STAT_DIR_CREATE].worst=stats[_STAT_DIR_CREATE].speed;
            chdir(buf);
            chdir("..");
        }
        chdir("..");
    }
}
Ejemplo n.º 2
0
void
file_readdir(int x)
{
    int i,j,ret1;
    char buf[100];
    DIR *dirbuf;
    struct dirent *y;
    stats[_STAT_READDIR].best=(double)999999.9;
    stats[_STAT_READDIR].worst=(double)0.0;
    for(i=0; i<x; i++)
    {
        sprintf(buf,"iozone_L1_%d",i);
        chdir(buf);
        for(j=0; j<x; j++)
        {
            sprintf(buf,"iozone_L1_%d_L2_%d",i,j);
            chdir(buf);
            dirbuf=opendir(".");
            if(dirbuf==0)
            {
                printf("opendir failed\n");
                exit(1);
            }
            stats[_STAT_READDIR].starttime=time_so_far();
            y=readdir(dirbuf);
            if(y == 0)
            {
                printf("readdir failed\n");
                exit(1);
            }
            stats[_STAT_READDIR].endtime=time_so_far();
            stats[_STAT_READDIR].speed=stats[_STAT_READDIR].endtime-stats[_STAT_READDIR].starttime;
            if(stats[_STAT_READDIR].speed < (double)0.0)
                stats[_STAT_READDIR].speed=(double)0.0;
            stats[_STAT_READDIR].total_time+=stats[_STAT_READDIR].speed;
            stats[_STAT_READDIR].counter++;
            if(stats[_STAT_READDIR].speed < stats[_STAT_READDIR].best)
                stats[_STAT_READDIR].best=stats[_STAT_READDIR].speed;
            if(stats[_STAT_READDIR].speed > stats[_STAT_READDIR].worst)
                stats[_STAT_READDIR].worst=stats[_STAT_READDIR].speed;
            ret1=closedir(dirbuf);
            if(ret1 < 0)
            {
                printf("closedir failed\n");
                exit(1);
            }
            chdir("..");
        }
        chdir("..");
    }
}
Ejemplo n.º 3
0
void
file_read(int x)
{
    int i,j,k,y,fd;
    char buf[100];
    stats[_STAT_READ].best=(double)99999.9;
    stats[_STAT_READ].worst=(double)0.00000000;
    for(i=0; i<x; i++)
    {
        sprintf(buf,"iozone_L1_%d",i);
        chdir(buf);
        for(j=0; j<x; j++)
        {
            sprintf(buf,"iozone_L1_%d_L2_%d",i,j);
            chdir(buf);
            for(k=0; k<x; k++)
            {
                sprintf(buf,"iozone_file_%d_%d_%d",i,j,k);
                fd=open(buf,O_RDONLY);
                if(fd < 0)
                {
                    printf("Open failed\n");
                    exit(1);
                }
                stats[_STAT_READ].starttime=time_so_far();
                y=read(fd,mbuffer,sz);
                if(y < 0)
                {
                    printf("Read failed\n");
                    exit(1);
                }
                stats[_STAT_READ].endtime=time_so_far();
                close(fd);
                stats[_STAT_READ].speed=stats[_STAT_READ].endtime-stats[_STAT_READ].starttime;
                if(stats[_STAT_READ].speed < (double)0.0)
                    stats[_STAT_READ].speed=(double)0.0;
                stats[_STAT_READ].total_time+=stats[_STAT_READ].speed;
                stats[_STAT_READ].counter++;
                if(stats[_STAT_READ].speed < stats[_STAT_READ].best)
                    stats[_STAT_READ].best=stats[_STAT_READ].speed;
                if(stats[_STAT_READ].speed > stats[_STAT_READ].worst)
                    stats[_STAT_READ].worst=stats[_STAT_READ].speed;
            }
            chdir("..");
        }
        chdir("..");
    }
}
Ejemplo n.º 4
0
void
dir_delete(int x)
{
    int i,j;
    char buf[100];
    stats[_STAT_DIR_DELETE].best=(double)99999.9;
    stats[_STAT_DIR_DELETE].worst=(double)0.00000000;
    for(i=0; i<x; i++)
    {
        sprintf(buf,"iozone_L1_%d",i);
        chdir(buf);
        for(j=0; j<x; j++)
        {
            sprintf(buf,"iozone_L1_%d_L2_%d",i,j);
            chdir(buf);
            chdir("..");
            sprintf(buf,"iozone_L1_%d_L2_%d",i,j);
            stats[_STAT_DIR_DELETE].starttime=time_so_far();
            rmdir(buf);
            stats[_STAT_DIR_DELETE].endtime=time_so_far();
            stats[_STAT_DIR_DELETE].speed=stats[_STAT_DIR_DELETE].endtime-stats[_STAT_DIR_DELETE].starttime;
            if(stats[_STAT_DIR_DELETE].speed < (double)0.0)
                stats[_STAT_DIR_DELETE].speed=(double)0.0;
            stats[_STAT_DIR_DELETE].total_time+=stats[_STAT_DIR_DELETE].speed;
            stats[_STAT_DIR_DELETE].counter++;
            if(stats[_STAT_DIR_DELETE].speed < stats[_STAT_DIR_DELETE].best)
                stats[_STAT_DIR_DELETE].best=stats[_STAT_DIR_DELETE].speed;
            if(stats[_STAT_DIR_DELETE].speed > stats[_STAT_DIR_DELETE].worst)
                stats[_STAT_DIR_DELETE].worst=stats[_STAT_DIR_DELETE].speed;
        }
        chdir("..");
        sprintf(buf,"iozone_L1_%d",i);
        stats[_STAT_DIR_DELETE].starttime=time_so_far();
        rmdir(buf);
        stats[_STAT_DIR_DELETE].endtime=time_so_far();
        stats[_STAT_DIR_DELETE].speed=stats[_STAT_DIR_DELETE].endtime-stats[_STAT_DIR_DELETE].starttime;
        if(stats[_STAT_DIR_DELETE].speed < (double)0.0)
            stats[_STAT_DIR_DELETE].speed=(double)0.0;
        stats[_STAT_DIR_DELETE].total_time+=stats[_STAT_DIR_DELETE].speed;
        stats[_STAT_DIR_DELETE].counter++;
        if(stats[_STAT_DIR_DELETE].speed < stats[_STAT_DIR_DELETE].best)
            stats[_STAT_DIR_DELETE].best=stats[_STAT_DIR_DELETE].speed;
        if(stats[_STAT_DIR_DELETE].speed > stats[_STAT_DIR_DELETE].worst)
            stats[_STAT_DIR_DELETE].worst=stats[_STAT_DIR_DELETE].speed;
    }
}
Ejemplo n.º 5
0
void
file_unlink(int x)
{
    int i,j,k,y;
    char buf[100];
    char bufn[100];
    stats[_STAT_UNLINK].best=(double)999999.9;
    stats[_STAT_UNLINK].worst=(double)0.0;
    for(i=0; i<x; i++)
    {
        sprintf(buf,"iozone_L1_%d",i);
        chdir(buf);
        for(j=0; j<x; j++)
        {
            sprintf(buf,"iozone_L1_%d_L2_%d",i,j);
            chdir(buf);
            for(k=0; k<x; k++)
            {
                sprintf(buf,"iozone_file_%d_%d_%d",i,j,k);
                sprintf(bufn,"iozone_file_%d_%d_%dL",i,j,k);
                stats[_STAT_UNLINK].starttime=time_so_far();
                y=unlink(bufn);
                if(y < 0)
                {
                    printf("Unlink failed\n");
                    exit(1);
                }
                stats[_STAT_UNLINK].endtime=time_so_far();
                stats[_STAT_UNLINK].speed=stats[_STAT_UNLINK].endtime-stats[_STAT_UNLINK].starttime;
                if(stats[_STAT_UNLINK].speed < (double)0.0)
                    stats[_STAT_UNLINK].speed=(double)0.0;
                stats[_STAT_UNLINK].total_time+=stats[_STAT_UNLINK].speed;
                stats[_STAT_UNLINK].counter++;
                if(stats[_STAT_UNLINK].speed < stats[_STAT_UNLINK].best)
                    stats[_STAT_UNLINK].best=stats[_STAT_UNLINK].speed;
                if(stats[_STAT_UNLINK].speed > stats[_STAT_UNLINK].worst)
                    stats[_STAT_UNLINK].worst=stats[_STAT_UNLINK].speed;
            }
            chdir("..");
        }
        chdir("..");
    }
}
Ejemplo n.º 6
0
void 
file_access(int x)
{
	int i,j,k,y;
	char buf[100];
	stats[_STAT_ACCESS].best=(double)999999.9;
	stats[_STAT_ACCESS].worst=(double)0.0;
	for(i=0;i<x;i++)
	{
	  sprintf(buf,"fileop_L1_%d",i);
	  chdir(buf);
	  for(j=0;j<x;j++)
	  {
	    sprintf(buf,"fileop_L1_%d_L2_%d",i,j);
	    chdir(buf);
	    for(k=0;k<x;k++)
	    {
	      sprintf(buf,"fileop_file_%d_%d_%d",i,j,k);
	      stats[_STAT_ACCESS].starttime=time_so_far();
	      y=access(buf,W_OK|F_OK);
	      if(y < 0)
	      {
	        printf("access failed\n");
		perror("what");
	        exit(1);
	      }
	      stats[_STAT_ACCESS].endtime=time_so_far();
	      stats[_STAT_ACCESS].speed=stats[_STAT_ACCESS].endtime-stats[_STAT_ACCESS].starttime;
	      if(stats[_STAT_ACCESS].speed < (double)0.0)
		stats[_STAT_ACCESS].speed=(double)0.0;
	      stats[_STAT_ACCESS].total_time+=stats[_STAT_ACCESS].speed;
	      stats[_STAT_ACCESS].counter++;
	      if(stats[_STAT_ACCESS].speed < stats[_STAT_ACCESS].best)
		 stats[_STAT_ACCESS].best=stats[_STAT_ACCESS].speed;
	      if(stats[_STAT_ACCESS].speed > stats[_STAT_ACCESS].worst)
		 stats[_STAT_ACCESS].worst=stats[_STAT_ACCESS].speed;
	    }
	    chdir("..");
	  }
	  chdir("..");
	}
}
Ejemplo n.º 7
0
void
file_chmod(int x)
{
    int i,j,k,y;
    char buf[100];
    stats[_STAT_CHMOD].best=(double)999999.9;
    stats[_STAT_CHMOD].worst=(double)0.0;
    for(i=0; i<x; i++)
    {
        sprintf(buf,"iozone_L1_%d",i);
        chdir(buf);
        for(j=0; j<x; j++)
        {
            sprintf(buf,"iozone_L1_%d_L2_%d",i,j);
            chdir(buf);
            for(k=0; k<x; k++)
            {
                sprintf(buf,"iozone_file_%d_%d_%d",i,j,k);
                stats[_STAT_CHMOD].starttime=time_so_far();
                y=chmod(buf,0666);
                if(y < 0)
                {
                    printf("chmod failed\n");
                    perror("what");
                    exit(1);
                }
                stats[_STAT_CHMOD].endtime=time_so_far();
                stats[_STAT_CHMOD].speed=stats[_STAT_CHMOD].endtime-stats[_STAT_CHMOD].starttime;
                if(stats[_STAT_CHMOD].speed < (double)0.0)
                    stats[_STAT_CHMOD].speed=(double)0.0;
                stats[_STAT_CHMOD].total_time+=stats[_STAT_CHMOD].speed;
                stats[_STAT_CHMOD].counter++;
                if(stats[_STAT_CHMOD].speed < stats[_STAT_CHMOD].best)
                    stats[_STAT_CHMOD].best=stats[_STAT_CHMOD].speed;
                if(stats[_STAT_CHMOD].speed > stats[_STAT_CHMOD].worst)
                    stats[_STAT_CHMOD].worst=stats[_STAT_CHMOD].speed;
            }
            chdir("..");
        }
        chdir("..");
    }
}
Ejemplo n.º 8
0
void 
file_stat(int x)
{
	int i,j,k,y;
	char buf[100];
	struct stat mystat;
	stats[_STAT_STAT].best=(double)99999.9;
	stats[_STAT_STAT].worst=(double)0.00000000;
	for(i=0;i<x;i++)
	{
	  sprintf(buf,"fileop_L1_%d",i);
	  chdir(buf);
	  for(j=0;j<x;j++)
	  {
	    sprintf(buf,"fileop_L1_%d_L2_%d",i,j);
	    chdir(buf);
	    for(k=0;k<x;k++)
	    {
	      sprintf(buf,"fileop_file_%d_%d_%d",i,j,k);
	      stats[_STAT_STAT].starttime=time_so_far();
	      y=stat(buf,&mystat);
	      if(y < 0)
	      {
	        printf("Stat failed\n");
	        exit(1);
	      }
	      stats[_STAT_STAT].endtime=time_so_far();
	      stats[_STAT_STAT].speed=stats[_STAT_STAT].endtime-stats[_STAT_STAT].starttime;
	      if(stats[_STAT_STAT].speed < (double)0.0)
		stats[_STAT_STAT].speed=(double)0.0;
	      stats[_STAT_STAT].total_time+=stats[_STAT_STAT].speed;
	      stats[_STAT_STAT].counter++;
	      if(stats[_STAT_STAT].speed < stats[_STAT_STAT].best)
		 stats[_STAT_STAT].best=stats[_STAT_STAT].speed;
	      if(stats[_STAT_STAT].speed > stats[_STAT_STAT].worst)
		 stats[_STAT_STAT].worst=stats[_STAT_STAT].speed;
	    }
	    chdir("..");
	  }
	  chdir("..");
	}
}
Ejemplo n.º 9
0
void
file_delete(int x)
{
	int i,j,k;
	char buf[100];
	stats[_STAT_DELETE].best=(double)999999.9;
	stats[_STAT_DELETE].worst=(double)0.0;
	for(i=0;i<x;i++)
	{
	  sprintf(buf,"fileop_L1_%d",i);
	  chdir(buf);
	  for(j=0;j<x;j++)
	  {
	    sprintf(buf,"fileop_L1_%d_L2_%d",i,j);
	    chdir(buf);
	    for(k=0;k<x;k++)
	    {
	      sprintf(buf,"fileop_file_%d_%d_%d",i,j,k);
	      stats[_STAT_DELETE].starttime=time_so_far();
	      unlink(buf);
	      stats[_STAT_DELETE].endtime=time_so_far();
	      stats[_STAT_DELETE].speed=stats[_STAT_DELETE].endtime-stats[_STAT_DELETE].starttime;
	      if(stats[_STAT_DELETE].speed < (double)0.0)
		stats[_STAT_DELETE].speed=(double)0.0;
	      stats[_STAT_DELETE].total_time+=stats[_STAT_DELETE].speed;
	      stats[_STAT_DELETE].counter++;
	      if(stats[_STAT_DELETE].speed < stats[_STAT_DELETE].best)
		 stats[_STAT_DELETE].best=stats[_STAT_DELETE].speed;
	      if(stats[_STAT_DELETE].speed > stats[_STAT_DELETE].worst)
		 stats[_STAT_DELETE].worst=stats[_STAT_DELETE].speed;
	    }
	    chdir("..");
	    sprintf(buf,"fileop_L1_%d_L2_%d",i,j);
	    rmdir(buf);
	  }
	  chdir("..");
	  sprintf(buf,"fileop_L1_%d",i);
	  rmdir(buf);
	}
}
Ejemplo n.º 10
0
int main(int argc , char **argv)
{
#if PRINT_TIME
	double start, end;
#endif
	
	extract_arguments(argc, argv);

#if PRINT_TIME
	start = time_so_far();
#endif
	if(mr_init())
		exit(EXIT_FAILURE);

	start_threads();
	wait_threads();

	if(mr_reduce())
		exit(EXIT_FAILURE);

#if PRINT_TIME
	/* Done here, to avoid counting the printing... */
	end = time_so_far();
#endif

	if(mr_print())
		exit(EXIT_FAILURE);
	if(mr_destroy())
		exit(EXIT_FAILURE);

#if PRINT_TIME
	printf("Done in %g msec\n", end-start);
#endif

	exit(EXIT_SUCCESS);
}
Ejemplo n.º 11
0
void random_perf_test(off64_t kilo64,long long reclen,long long *data1,long long *data2)
{
	double randreadtime[2];
	double starttime2;
	double walltime[2], cputime[2];
	double compute_val = (double)0;
	unsigned long long big_rand;
	long long j;
	off64_t i,numrecs64;
	long long Index=0;
	int flags;
	unsigned long long randreadrate[2];
	off64_t filebytes64;
	off64_t lock_offset=0;
	volatile char *buffer1;
	char *wmaddr,*nbuff;
	char *maddr,*free_addr;
	int fd,wval;
	long long *recnum= 0;
	long long *gc=0;
	char *filename = "/mnt/ramdisk/test1";

	maddr=free_addr=0;
	numrecs64 = (kilo64*1024)/reclen;
        srand48(0);

        recnum = (long long *)malloc(sizeof(*recnum)*numrecs64);
        if (recnum){
             /* pre-compute random sequence based on 
		Fischer-Yates (Knuth) card shuffle */
            for(i = 0; i < numrecs64; i++){
                recnum[i] = i;
            }
            for(i = 0; i < numrecs64; i++) {
                long long tmp;
               big_rand = lrand48();
               big_rand = big_rand%numrecs64;
               tmp = recnum[i];
               recnum[i] = recnum[big_rand];
               recnum[big_rand] = tmp;
            }
        }
	else
	{
		fprintf(stderr,"Random uniqueness fallback.\n");
	}
	flags = O_RDWR;

	fd=0;
	filebytes64 = numrecs64*reclen;
	for( j=0; j<2; j++ )
	{
		if(j==0)
			flags |=O_CREAT;
	     if((fd = open(filename, ((int)flags),0640))<0){
			printf("\nCan not open temporary file for read/write\n");
			perror("open");
			exit(66);
	     }

	     nbuff=mainbuffer;
             srand48(0);

	     compute_val=(double)0;
	     starttime2 = time_so_far();
	     if ( j==0 ){
		for(i=0; i<numrecs64; i++) {
                        if (recnum) {
				offset64 = reclen * (long long)recnum[i];
                        }
			else
			{
			   offset64 = reclen * (lrand48()%numrecs64);
			}

			   if(lseek( fd, offset64, SEEK_SET )<0)
			   {
				perror("lseek");
				exit(68);
			   }
		  	
			     if(read(fd, (void *)nbuff, (size_t)reclen) != reclen)
		  	     {
#ifdef NO_PRINT_LLD
				 printf("\nError reading block at %ld\n",
					 offset64); 
#else
				 printf("\nError reading block at %lld\n",
					 offset64); 
#endif
				 perror("read");
				 exit(70);
		 	     }
		}
	     }
	     else
	     {
			for(i=0; i<numrecs64; i++) 
			{
                                if (recnum) {
				  offset64 = reclen * (long long)recnum[i];
                                }
			        else
			        {
				  offset64 = reclen * (lrand48()%numrecs64);
				}

				  lseek( fd, offset64, SEEK_SET );
			 	  wval=write(fd, nbuff,(size_t)reclen);
			  	  if(wval != reclen)
			  	  {
#ifdef NO_PRINT_LLD
					printf("\nError writing block at %ld\n",
						offset64); 
#else
					printf("\nError writing block at %lld\n",
						offset64); 
#endif
					if(wval==-1)
						perror("write");
		 		  }
			}
	     } 	/* end of modifications	*kcollins:2-5-96 */
	        randreadtime[j] = ((time_so_far() - starttime2))-
			compute_val;
	     if(randreadtime[j] < (double).000001) 
	     {
			randreadtime[j]=(double).000001;
	     }
	     		wval=fsync(fd);
			if(wval==-1){
				perror("fsync");
//				signal_handler();
			}
		wval=close(fd);
		if(wval==-1){
			perror("close");
//			signal_handler();
		}
    	}
        for(j=0;j<2;j++)
        {
                  randreadrate[j] = 
		      (unsigned long long) ((double) filebytes64 / randreadtime[j]);
		  printf("%s: ltest %d randomrate %llu\n", __func__, j, randreadrate[j]);
	}
	/* Must save walltime & cputime before calling store_value() for each/any cell.*/
	if(recnum)
		free(recnum);
}
Ejemplo n.º 12
0
/**
 * main program logic
 */
int main(int argc, char *argv[]) 
{
  
	FILE *fhProcStat;	// file handle for /proc/stat
	FILE *fhOutput;		// the file we want to write to


	// needed time values 
	double dOldTime = -1;	// will hold the time from the previous iteration
	double dNewTime = -1;	// will hold the current time
	

	char cpu_text[10];	// needed for running fscanf on the first row of /proc/stat

	int  bit_stream_dec[5]; // will hold the bit stream we want to send as decimal values
	char bit_stream_hex[10];// will hold the bit stream we want to send as hex values

	// previous iteration
	int iUserTimeOld;	// user: normal processes executing in user mode
	int iNiceTimeOld;	// nice: niced processes executing in user mode
	int iSystemTimeOld;	// system: processes executing in kernel mode

	// current iteration
	int iUserTimeNew; 	// user: normal processes executing in user mode
	int iNiceTimeNew;	// nice: niced processes executing in user mode
	int iSystemTimeNew;	// system: processes executing in kernel mode

	bool bIsFirstIteration = true;

	int iCpuTimeTotal   = -1;	
	int iCpuUsage       = -1;	// calculated cpu usage
	int iCpuUsageScaled = -1;	// cpu usage scaled to 40 since we have 40 leds


	// set up interrupt handler so we can exit gracefully	
	signal(SIGINT, intHandler);
	


	// check if the output file was supplied
	if(argc != 2)
	{
		/* We print argv[0] assuming it is the program name */
		printf( "usage: %s /some/file \n", argv[0] );
		return 0;
	}

	
	// open the output file for writing
	fhOutput = fopen(argv[1], "w");
	

	while(keepRunning)
	{
		
		// get the current time with microsecond accuracy (seconds.microseconds)
		dNewTime = time_so_far();
		
		// re-open the file to read the new values
		fhProcStat = fopen("/proc/stat", "r");
		
		/* we're only interested in the first line since it aggregates the values 
		 * from the individual cores
		 * 1st line example: cpu  54095 7770 22351 2252753 27278 0 1483 0 0 0
		 *
		 * we are only interested in the first 3 values. these represent CPU time spent for:
		 * - user: normal processes executing in user mode
		 * - nice: niced processes executing in user mode
		 * - system: processes executing in kernel mode
		 *
		 * more info at: http://kernel.org/doc/Documentation/filesystems/proc.txt
		 */
		fscanf(fhProcStat, "%s\t%d\t%d\t%d\n", cpu_text, 
			&iUserTimeNew, &iNiceTimeNew, &iSystemTimeNew);

		// close file again
		fclose(fhProcStat);

	
		// we can't calculate cpu usage in the first iteration
		if(bIsFirstIteration)
		{
			bIsFirstIteration = false;
		}
		else
		{
			// calculate the total cpu time for this iteration		
			iCpuTimeTotal = (iUserTimeNew + iNiceTimeNew + iSystemTimeNew) - (iUserTimeOld + iNiceTimeOld + iSystemTimeOld);
	
			// calculate cpu usage in percent
			iCpuUsage = (iCpuTimeTotal / ((dNewTime - dOldTime) * 100)) * 100;

			// write to stdout	
			//printf("cpu usage: %i%\n", iCpuUsage);
			printf("%i\n", iCpuUsage);

			// scale to 40 
			iCpuUsageScaled = scaleFromTo(iCpuUsage, 100, 40);
			//printf("cpu usage scaled: %i\n", iCpuUsageScaled);

			// create bitstream
			generateBitStream(iCpuUsageScaled, bit_stream_dec);

			// convert the values to hex
			bitStreamToHex(bit_stream_dec, bit_stream_hex);

			
			//fprintf(fhOutput, "%i\n", iCpuUsageScaled);

			// write to output file
			// we need a loop since c will print elements 0,1,...
			// but we need MSB first...
			int i;
			for(i = 9; i >= 0; i=i-2)
			{
				//printf("%c", bit_stream_hex[i-1]);
				//fprintf(fhOutput, "%c", bit_stream_hex[i-1]);
				//printf("%c", bit_stream_hex[i]);
				//fprintf(fhOutput, "%c", bit_stream_hex[i]);
			}
			//printf("\n");
			//fprintf(fhOutput, "\n");

		} //endif
		

		// set previous values for the next iteration
		dOldTime       = dNewTime;
		iUserTimeOld   = iUserTimeNew;
		iNiceTimeOld   = iNiceTimeNew;	
		iSystemTimeOld = iSystemTimeNew;


		// wait for one second
		sleep(1);
		
	} //endwhile true
	

	// close output file
		fclose(fhOutput);

	// app has finished successfully
	return 0;

} //endmethod main
Ejemplo n.º 13
0
void
file_create(int x)
{
    int i,j,k;
    int fd;
    int ret;
    char buf[100];
    stats[_STAT_CREATE].best=(double)999999.9;
    stats[_STAT_CREATE].worst=(double)0.0;
    stats[_STAT_WRITE].best=(double)999999.9;
    stats[_STAT_WRITE].worst=(double)0.0;
    stats[_STAT_CLOSE].best=(double)999999.9;
    stats[_STAT_CLOSE].worst=(double)0.0;
    for(i=0; i<x; i++)
    {
        sprintf(buf,"iozone_L1_%d",i);
        ret=mkdir(buf,0777);
        if(ret < 0)
        {
            printf("Mkdir failed\n");
            exit(1);
        }
        chdir(buf);
        for(j=0; j<x; j++)
        {
            sprintf(buf,"iozone_L1_%d_L2_%d",i,j);
            ret=mkdir(buf,0777);
            if(ret < 0)
            {
                printf("Mkdir failed\n");
                exit(1);
            }
            chdir(buf);
            for(k=0; k<x; k++)
            {
                sprintf(buf,"iozone_file_%d_%d_%d",i,j,k);
                stats[_STAT_CREATE].starttime=time_so_far();
                fd=creat(buf,O_RDWR|0600);
                if(fd < 0)
                {
                    printf("Create failed\n");
                    exit(1);
                }
                stats[_STAT_CREATE].endtime=time_so_far();
                stats[_STAT_CREATE].speed=stats[_STAT_CREATE].endtime-stats[_STAT_CREATE].starttime;
                if(stats[_STAT_CREATE].speed < (double)0.0)
                    stats[_STAT_CREATE].speed=(double)0.0;
                stats[_STAT_CREATE].total_time+=stats[_STAT_CREATE].speed;
                stats[_STAT_CREATE].counter++;
                if(stats[_STAT_CREATE].speed < stats[_STAT_CREATE].best)
                    stats[_STAT_CREATE].best=stats[_STAT_CREATE].speed;
                if(stats[_STAT_CREATE].speed > stats[_STAT_CREATE].worst)
                    stats[_STAT_CREATE].worst=stats[_STAT_CREATE].speed;

                stats[_STAT_WRITE].starttime=time_so_far();
                write(fd,mbuffer,sz);
                stats[_STAT_WRITE].endtime=time_so_far();
                stats[_STAT_WRITE].counter++;
                stats[_STAT_WRITE].speed=stats[_STAT_WRITE].endtime-stats[_STAT_WRITE].starttime;
                if(stats[_STAT_WRITE].speed < (double)0.0)
                    stats[_STAT_WRITE].speed=(double)0.0;
                stats[_STAT_WRITE].total_time+=stats[_STAT_WRITE].speed;
                if(stats[_STAT_WRITE].speed < stats[_STAT_WRITE].best)
                    stats[_STAT_WRITE].best=stats[_STAT_WRITE].speed;
                if(stats[_STAT_WRITE].speed > stats[_STAT_WRITE].worst)
                    stats[_STAT_WRITE].worst=stats[_STAT_WRITE].speed;

                fsync(fd);
                stats[_STAT_CLOSE].starttime=time_so_far();
                close(fd);
                stats[_STAT_CLOSE].endtime=time_so_far();
                stats[_STAT_CLOSE].speed=stats[_STAT_CLOSE].endtime-stats[_STAT_CLOSE].starttime;
                if(stats[_STAT_CLOSE].speed < (double)0.0)
                    stats[_STAT_CLOSE].speed=(double)0.0;
                stats[_STAT_CLOSE].total_time+=stats[_STAT_CLOSE].speed;
                stats[_STAT_CLOSE].counter++;
                if(stats[_STAT_CLOSE].speed < stats[_STAT_CLOSE].best)
                    stats[_STAT_CLOSE].best=stats[_STAT_CLOSE].speed;
                if(stats[_STAT_CLOSE].speed > stats[_STAT_CLOSE].worst)
                    stats[_STAT_CLOSE].worst=stats[_STAT_CLOSE].speed;
            }
            chdir("..");
        }
        chdir("..");
    }
}
Ejemplo n.º 14
0
main(
  int    argc,
  char * argv[])
{
  int    buf[Chunk / IntSize];
  int    bufindex;
  int    chars[256];
  int    child;
  char * dir;
  int    html = 0;
  int    fd;
  double first_start;
  double last_stop;
  int    lseek_count = 0;
  char * machine;
  char   name[Chunk];
  int    next;
  int    seek_control[2];
  int    seek_feedback[2];
  char   seek_tickets[Seeks + SeekProcCount];
  double seeker_report[3];
  off_t  size;
  FILE * stream;
  off_t  words;

  fd = -1;
  basetime = (int) time((time_t *) NULL);
  size = 100;
  dir = ".";
  machine = "";

  /* pick apart args */
  for (next = 1; next < argc; next++)
    if (strcmp(argv[next], "-d") == 0)
      dir = argv[++next];
    else if (strcmp(argv[next], "-s") == 0)
      size = atol(argv[++next]);
    else if (strcmp(argv[next], "-m") == 0)
      machine = argv[++next];
    else if (strcmp(argv[next], "-html") == 0)
      html = 1;
    else
      usage();

  if (size < 1)
    usage();

  /* sanity check - 32-bit machines can't handle more than 2047 Mb */
  if (sizeof(off_t) <= 4 && size > 2047)
  {
    fprintf(stderr, "File too large for 32-bit machine, sorry\n");
    exit(1);
  }

  sprintf(name, "%s/Bonnie.%d", dir, getpid());

  /* size is in meg, rounded down to multiple of Chunk */
  size *= (1024 * 1024);
  size = Chunk * (size / Chunk);
  fprintf(stderr, "File '%s', size: %ld\n", name, size);

  /* Fill up a file, writing it a char at a time with the stdio putc() call */
  fprintf(stderr, "Writing with putc()...");
  newfile(name, &fd, &stream, 1);
  timestamp();
  for (words = 0; words < size; words++)
    if (putc(words & 0x7f, stream) == EOF)
      io_error("putc");
  
  /*
   * note that we always close the file before measuring time, in an
   *  effort to force as much of the I/O out as we can
   */
  if (fclose(stream) == -1)
    io_error("fclose after putc");
  get_delta_t(Putc);
  fprintf(stderr, "done\n");

  /* Now read & rewrite it using block I/O.  Dirty one word in each block */
  newfile(name, &fd, &stream, 0);
  if (lseek(fd, (off_t) 0, 0) == (off_t) -1)
    io_error("lseek(2) before rewrite");
  fprintf(stderr, "Rewriting...");
  timestamp();
  bufindex = 0;
  if ((words = read(fd, (char *) buf, Chunk)) == -1)
    io_error("rewrite read");
  while (words == Chunk)
  { /* while we can read a block */
    if (bufindex == Chunk / IntSize)
      bufindex = 0;
    buf[bufindex++]++;
    if (lseek(fd, (off_t) -words, 1) == -1)
      io_error("relative lseek(2)");
    if (write(fd, (char *) buf, words) == -1)
      io_error("re write(2)");
    if ((words = read(fd, (char *) buf, Chunk)) == -1)
      io_error("rwrite read");
  } /* while we can read a block */
  if (close(fd) == -1)
    io_error("close after rewrite");
  get_delta_t(ReWrite);
  fprintf(stderr, "done\n");

  /* Write the whole file from scratch, again, with block I/O */
  newfile(name, &fd, &stream, 1);
  fprintf(stderr, "Writing intelligently...");
  for (words = 0; words < Chunk / IntSize; words++)
    buf[words] = 0;
  timestamp();
  for (words = bufindex = 0; words < (size / Chunk); words++)
  { /* for each word */
    if (bufindex == (Chunk / IntSize))
      bufindex = 0;
    buf[bufindex++]++;
    if (write(fd, (char *) buf, Chunk) == -1)
      io_error("write(2)");
  } /* for each word */
  if (close(fd) == -1)
    io_error("close after fast write");
  get_delta_t(FastWrite);
  fprintf(stderr, "done\n");

  /* read them all back with getc() */
  newfile(name, &fd, &stream, 0);
  for (words = 0; words < 256; words++)
    chars[words] = 0;
  fprintf(stderr, "Reading with getc()...");
  timestamp();
  for (words = 0; words < size; words++)
  { /* for each byte */
    if ((next = getc(stream)) == EOF)
      io_error("getc(3)");

    /* just to fool optimizers */
    chars[next]++;
  } /* for each byte */
  if (fclose(stream) == -1)
    io_error("fclose after getc");
  get_delta_t(Getc);
  fprintf(stderr, "done\n");

  /* use the frequency count */
  for (words = 0; words < 256; words++)
    sprintf((char *) buf, "%d", chars[words]);

  /* Now suck it in, Chunk at a time, as fast as we can */
  newfile(name, &fd, &stream, 0);
  if (lseek(fd, (off_t) 0, 0) == -1)
    io_error("lseek before read");
  fprintf(stderr, "Reading intelligently...");
  timestamp();
  do
  { /* per block */
    if ((words = read(fd, (char *) buf, Chunk)) == -1)
      io_error("read(2)");
    chars[buf[abs(buf[0]) % (Chunk / IntSize)] & 0x7f]++;
  } /* per block */
  while (words);
  if (close(fd) == -1)
    io_error("close after read");
  get_delta_t(FastRead);
  fprintf(stderr, "done\n");

  /* use the frequency count */
  for (words = 0; words < 256; words++)
    sprintf((char *) buf, "%d", chars[words]);

  /*
   * Now test random seeks; first, set up for communicating with children.
   * The object of the game is to do "Seeks" lseek() calls as quickly
   *  as possible.  So we'll farm them out among SeekProcCount processes.
   *  We'll control them by writing 1-byte tickets down a pipe which
   *  the children all read.  We write "Seeks" bytes with val 1, whichever
   *  child happens to get them does it and the right number of seeks get
   *  done.
   * The idea is that since the write() of the tickets is probably
   *  atomic, the parent process likely won't get scheduled while the
   *  children are seeking away.  If you draw a picture of the likely
   *  timelines for three children, it seems likely that the seeks will
   *  overlap very nicely with the process scheduling with the effect
   *  that there will *always* be a seek() outstanding on the file.
   * Question: should the file be opened *before* the fork, so that
   *  all the children are lseeking on the same underlying file object?
   */
  if (pipe(seek_feedback) == -1 || pipe(seek_control) == -1)
    io_error("pipe");
  for (next = 0; next < Seeks; next++)
    seek_tickets[next] = 1;
  for ( ; next < (Seeks + SeekProcCount); next++)
    seek_tickets[next] = 0;

  /* launch some parallel seek processes */
  for (next = 0; next < SeekProcCount; next++)
  { /* for each seek proc */
    if ((child = fork()) == -1)
      io_error("fork");
    else if (child == 0)
    { /* child process */

      /* set up and wait for the go-ahead */
      close(seek_feedback[0]);
      close(seek_control[1]);
      newfile(name, &fd, &stream, 0);
      srandom(getpid());
      fprintf(stderr, "Seeker %d...", next + 1);

      /* wait for the go-ahead */
      if (read(seek_control[0], seek_tickets, 1) != 1)
	io_error("read ticket");
      timestamp();
      seeker_report[StartTime] = time_so_far();

      /* loop until we read a 0 ticket back from our parent */
      while(seek_tickets[0])
      { /* until Mom says stop */
        doseek((long) (random() % (size / Chunk)), fd,
	  ((lseek_count++ % UpdateSeek) == 0));
	if (read(seek_control[0], seek_tickets, 1) != 1)
	  io_error("read ticket");
      } /* until Mom says stop */
      if (close(fd) == -1)
        io_error("close after seek");

      /* report to parent */
      get_delta_t(Lseek);
      seeker_report[EndTime] = time_so_far();
      seeker_report[CPU] = delta[(int) Lseek][CPU];
      if (write(seek_feedback[1], seeker_report, sizeof(seeker_report))
          != sizeof(seeker_report))
        io_error("pipe write");
      exit(0);
    } /* child process */
  } /* for each seek proc */

  /*
   * Back in the parent; in an effort to ensure the children get an even
   *  start, wait a few seconds for them to get scheduled, open their
   *  files & so on.
   */
  close(seek_feedback[1]);
  close(seek_control[0]);
  sleep(5);
  fprintf(stderr, "start 'em...");
  if (write(seek_control[1], seek_tickets, sizeof(seek_tickets)) 
      != sizeof(seek_tickets))
    io_error("write tickets");
  
  /* read back from children */
  for (next = 0; next < SeekProcCount; next++)
  { /* for each child */
    if (read(seek_feedback[0], (char *) seeker_report, sizeof(seeker_report))
        != sizeof(seeker_report))
      io_error("pipe read");

    /*
     * each child writes back its CPU, start & end times.  The elapsed time 
     *  to do all the seeks is the time the first child started until the 
     *  time the last child stopped
     */
    delta[(int) Lseek][CPU] += seeker_report[CPU];
    if (next == 0)
    { /* first time */
      first_start = seeker_report[StartTime];
      last_stop = seeker_report[EndTime];
    } /* first time */
    else
    { /* not first time */
      first_start = (first_start < seeker_report[StartTime]) ?
	first_start : seeker_report[StartTime]; 
      last_stop = (last_stop > seeker_report[EndTime]) ?
	last_stop : seeker_report[EndTime]; 
    } /* not first time */
    if (wait(&child) == -1)
      io_error("wait");
    fprintf(stderr, "done...");
  } /* for each child */
  fprintf(stderr, "\n");
  delta[(int) Lseek][Elapsed] = last_stop - first_start;

  if (html)
    write_html(machine, size);
  else
    report(machine, size);
  unlink(name);
}
Ejemplo n.º 15
0
void 
read_perf_test(unsigned long kilo64,long long reclen,long long *data1,long long *data2)
{
	double starttime2;
	double compute_val = (double)0;
	double readtime[2];
	double walltime[2], cputime[2];
	long long j;
	long long traj_size;
	unsigned long i,numrecs64,traj_offset;
	unsigned long lock_offset=0;
	long long Index = 0;
	unsigned long long readrate[2];
	unsigned long filebytes64;
	volatile char *buffer1;
	char *nbuff;
	int fd,open_flags;
	int test_foo,ltest;
	long wval;
	double qtime_start,qtime_stop;
	double hist_time;
	unsigned long r_traj_ops_completed=0;
	unsigned long r_traj_bytes_completed=0;
	long long *gc=0;
	char *filename = "/mnt/ramdisk/test1";
	size_t len = reclen;
	struct timespec start, end;
	long long time;

	hist_time=qtime_start=qtime_stop=0;
	traj_offset=0;
	test_foo=0;

	numrecs64 = (kilo64*1024)/reclen;

	open_flags = O_RDONLY;
	
	filebytes64 = numrecs64*reclen;
	fd = 0;

//	mainbuffer = (char *)malloc(4 * 1024 * 4096);

	/* 
	 * begin real testing
	 */
	ltest=3;
	printf("%s: filename %s, test %d, reclen %lld, numrecs64 %llu, filebytes64 %llu\n", __func__, filename, ltest, reclen, numrecs64, filebytes64);


//	fd = open(filename, open_flags,0640);

	for( j=0; j<ltest; j++ )
	{

//		lseek(fd,0,SEEK_SET);
		if((fd = open(filename, open_flags,0))<0)
		{
			printf("\nCan not open temporary file %s for read\n",filename);
			perror("open");
			exit(58);
		}

		printf("fd: %d, reclen %lu\n", fd, reclen);
		  fsync(fd);

		/* 
		 *  Need to prime the instruction cache & TLB
		 */
		nbuff=mainbuffer;
//		read(fd, (void *)nbuff, (size_t)reclen);
//		if(fetchon)
//			fetchit(nbuff,reclen);

		if(read(fd, (void *)nbuff, 4096) != reclen)
		{
#ifdef _64BIT_ARCH_
			printf("\nError reading block %d %llx\n", 0,
				(unsigned long long)nbuff);
#else
			printf("\nError reading block %d %lx\n", 0,
				(long)nbuff);
#endif
			perror("read");
			exit(60);
		}
		lseek(fd,0,SEEK_SET);

		nbuff=mainbuffer;

		starttime2 = time_so_far();

		compute_val=(double)0;
		r_traj_ops_completed=0;
		r_traj_bytes_completed=0;

		clock_gettime(CLOCK_MONOTONIC, &start);
		for(i=0; i<numrecs64; i++) 
		{
			    wval=read((int)fd, (void*)nbuff, 4096);
			    if(wval != reclen)
			    {
				printf("\nError reading block %lld %llx\n", i,
					(unsigned long long)nbuff);
				perror("read");
				exit(61);
			    }
		
		
			r_traj_ops_completed++;
			r_traj_bytes_completed+=reclen;
		}
		
		clock_gettime(CLOCK_MONOTONIC, &end);
		time = (end.tv_sec - start.tv_sec) * 1e9 + (end.tv_nsec - start.tv_nsec);
		printf("%lld ns\n", time);
		readtime[j] = ((time_so_far() - starttime2))-compute_val;
		if(readtime[j] < (double).000001) 
		{
			readtime[j]= (double)0.000001;
		}

		fsync(fd);
		close(fd);
	}

	filebytes64=r_traj_bytes_completed;
	printf("%s: completed %llu\n", __func__, filebytes64);

        for(j=0;j<ltest;j++)
        {
                  readrate[j] = 
                  (unsigned long long) ((double) filebytes64 / readtime[j]);
		  printf("%s: ltest %d readrate %llu\n", __func__, j, readrate[j]);
			
	}

}
Ejemplo n.º 16
0
void 
file_read(int x)
{
	int i,j,k,y,fd;
	char buf[100];
	char value;
	stats[_STAT_READ].best=(double)99999.9;
	stats[_STAT_READ].worst=(double)0.00000000;
	stats[_STAT_OPEN].best=(double)99999.9;
	stats[_STAT_OPEN].worst=(double)0.00000000;
	for(i=0;i<x;i++)
	{
	  sprintf(buf,"fileop_L1_%d",i);
	  chdir(buf);
	  for(j=0;j<x;j++)
	  {
	    sprintf(buf,"fileop_L1_%d_L2_%d",i,j);
	    chdir(buf);
	    for(k=0;k<x;k++)
	    {
	      sprintf(buf,"fileop_file_%d_%d_%d",i,j,k);
	      value=(char)((i^j^k) &0xff);
	      stats[_STAT_OPEN].starttime=time_so_far();
	      fd=open(buf,O_RDONLY);
	      if(fd < 0)
	      {
	        printf("Open failed\n");
	        exit(1);
	      }
	      stats[_STAT_OPEN].endtime=time_so_far();
	      stats[_STAT_OPEN].speed=stats[_STAT_OPEN].endtime-stats[_STAT_OPEN].starttime;
	      if(stats[_STAT_OPEN].speed < (double)0.0)
		stats[_STAT_OPEN].speed=(double)0.0;
	      stats[_STAT_OPEN].total_time+=stats[_STAT_OPEN].speed;
	      stats[_STAT_OPEN].counter++;
	      if(stats[_STAT_OPEN].speed < stats[_STAT_OPEN].best)
		 stats[_STAT_OPEN].best=stats[_STAT_OPEN].speed;
	      if(stats[_STAT_OPEN].speed > stats[_STAT_OPEN].worst)
		 stats[_STAT_OPEN].worst=stats[_STAT_OPEN].speed;

	      stats[_STAT_READ].starttime=time_so_far();
	      y=read(fd,mbuffer,sz);
	      if(y < 0)
	      {
	        printf("Read failed\n");
	        exit(1);
	      }
	      if(validate(mbuffer,sz, value) !=0)
		printf("Error: Data Mis-compare\n");;
	      stats[_STAT_READ].endtime=time_so_far();
	      close(fd);
	      stats[_STAT_READ].speed=stats[_STAT_READ].endtime-stats[_STAT_READ].starttime;
	      if(stats[_STAT_READ].speed < (double)0.0)
		stats[_STAT_READ].speed=(double)0.0;
	      stats[_STAT_READ].total_time+=stats[_STAT_READ].speed;
	      stats[_STAT_READ].counter++;
	      if(stats[_STAT_READ].speed < stats[_STAT_READ].best)
		 stats[_STAT_READ].best=stats[_STAT_READ].speed;
	      if(stats[_STAT_READ].speed > stats[_STAT_READ].worst)
		 stats[_STAT_READ].worst=stats[_STAT_READ].speed;
	    }
	    chdir("..");
	  }
	  chdir("..");
	}
}
Ejemplo n.º 17
0
void
dir_traverse(int x)
{
	int i,j,k;
	char buf[100];
	double time1, time2;
	stats[_STAT_DIR_TRAVERSE].best=(double)99999.9;
	stats[_STAT_DIR_TRAVERSE].worst=(double)0.00000000;
	for(i=0;i<x;i++)
	{
	  sprintf(buf,"fileop_L1_%d",i);
	  stats[_STAT_DIR_TRAVERSE].starttime=time_so_far();
	  chdir(buf);
	  stats[_STAT_DIR_TRAVERSE].endtime=time_so_far();
	  time1=stats[_STAT_DIR_TRAVERSE].endtime-stats[_STAT_DIR_TRAVERSE].starttime;
	  for(j=0;j<x;j++)
	  {
	    sprintf(buf,"fileop_L1_%d_L2_%d",i,j);
	    stats[_STAT_DIR_TRAVERSE].starttime=time_so_far();
	    chdir(buf);
	    stats[_STAT_DIR_TRAVERSE].endtime=time_so_far();
	    time2=stats[_STAT_DIR_TRAVERSE].endtime-stats[_STAT_DIR_TRAVERSE].starttime;
	    for(k=0;k<x;k++)
	    {
	      sprintf(buf,"fileop_dir_%d_%d_%d",i,j,k);
	      stats[_STAT_DIR_TRAVERSE].starttime=time_so_far();
	      chdir(buf);
	      chdir("..");
	      stats[_STAT_DIR_TRAVERSE].endtime=time_so_far();
	      stats[_STAT_DIR_TRAVERSE].speed=stats[_STAT_DIR_TRAVERSE].endtime-stats[_STAT_DIR_TRAVERSE].starttime;
	      if(stats[_STAT_DIR_TRAVERSE].speed < (double)0.0)
		stats[_STAT_DIR_TRAVERSE].speed=(double) 0.0;
	      stats[_STAT_DIR_TRAVERSE].total_time+=stats[_STAT_DIR_TRAVERSE].speed;
	      stats[_STAT_DIR_TRAVERSE].counter++;
	      if(stats[_STAT_DIR_TRAVERSE].speed < stats[_STAT_DIR_TRAVERSE].best)
		 stats[_STAT_DIR_TRAVERSE].best=stats[_STAT_DIR_TRAVERSE].speed;
	      if(stats[_STAT_DIR_TRAVERSE].speed > stats[_STAT_DIR_TRAVERSE].worst)
		 stats[_STAT_DIR_TRAVERSE].worst=stats[_STAT_DIR_TRAVERSE].speed;
	    }
	    stats[_STAT_DIR_TRAVERSE].starttime=time_so_far();
	    chdir("..");
	    stats[_STAT_DIR_TRAVERSE].endtime=time_so_far();
	    stats[_STAT_DIR_TRAVERSE].speed=time2+stats[_STAT_DIR_TRAVERSE].endtime-stats[_STAT_DIR_TRAVERSE].starttime;
	    if(stats[_STAT_DIR_TRAVERSE].speed < (double)0.0)
		stats[_STAT_DIR_TRAVERSE].speed=(double) 0.0;
	    stats[_STAT_DIR_TRAVERSE].total_time+=stats[_STAT_DIR_TRAVERSE].speed;
	    stats[_STAT_DIR_TRAVERSE].counter++;
	    if(stats[_STAT_DIR_TRAVERSE].speed < stats[_STAT_DIR_TRAVERSE].best)
		 stats[_STAT_DIR_TRAVERSE].best=stats[_STAT_DIR_TRAVERSE].speed;
	    if(stats[_STAT_DIR_TRAVERSE].speed > stats[_STAT_DIR_TRAVERSE].worst)
		 stats[_STAT_DIR_TRAVERSE].worst=stats[_STAT_DIR_TRAVERSE].speed;
	  }
	  stats[_STAT_DIR_TRAVERSE].starttime=time_so_far();
	  chdir("..");
	  stats[_STAT_DIR_TRAVERSE].endtime=time_so_far();
	  stats[_STAT_DIR_TRAVERSE].speed=time1+stats[_STAT_DIR_TRAVERSE].endtime-stats[_STAT_DIR_TRAVERSE].starttime;
	  if(stats[_STAT_DIR_TRAVERSE].speed < (double)0.0)
		stats[_STAT_DIR_TRAVERSE].speed=(double)0.0;
	  stats[_STAT_DIR_TRAVERSE].total_time+=stats[_STAT_DIR_TRAVERSE].speed;
	  stats[_STAT_DIR_TRAVERSE].counter++;
	  if(stats[_STAT_DIR_TRAVERSE].speed < stats[_STAT_DIR_TRAVERSE].best)
	 	stats[_STAT_DIR_TRAVERSE].best=stats[_STAT_DIR_TRAVERSE].speed;
	  if(stats[_STAT_DIR_TRAVERSE].speed > stats[_STAT_DIR_TRAVERSE].worst)
		 stats[_STAT_DIR_TRAVERSE].worst=stats[_STAT_DIR_TRAVERSE].speed;
	}
}
Ejemplo n.º 18
0
static void
timestamp()
{
  last_timestamp = time_so_far();
  last_cpustamp = cpu_so_far();
}
Ejemplo n.º 19
0
void write_perf_test1(off64_t kilo64,long long reclen ,long long *data1,long long *data2)
{
	double starttime1;
	double writetime[2];
	double walltime[2], cputime[2];
	double qtime_start,qtime_stop;
	double hist_time;
	double compute_val = (double)0;
	long long i,j;
	off64_t numrecs64,traj_offset;
	off64_t lock_offset=0;
	long long Index = 0;
	long long file_flags = 0;
	long long traj_size;
	unsigned long long writerate[2];
	off64_t filebytes64;
	int ltest;
	char *maddr;
	char *wmaddr,*free_addr;
	char *pbuff;
	char *nbuff;
	int fd,wval;
	int notruncate = 1;
	unsigned long w_traj_ops_completed=0;
	unsigned long w_traj_bytes_completed=0;
	char *filename = "/mnt/ramdisk/test1";

	int test_foo;

	nbuff=wmaddr=free_addr=0;
	traj_offset=0;
	test_foo=0;
	hist_time=qtime_start=qtime_stop=0;
	maddr=0;
	pbuff=mainbuffer;
	numrecs64 = (kilo64*1024)/reclen;
	filebytes64 = numrecs64*reclen;

	fd = 0;
	file_flags = O_RDWR;

/* Sanity check */
/* Some filesystems do not behave correctly and fail
 * when this sequence is performned. This is a very
 * bad thing. It breaks many applications and lurks
 * around quietly. This code should never get
 * triggered, but in the case of running iozone on
 * an NFS client, the filesystem type on the server
 * that is being exported can cause this failure.
 * If this failure happens, then the NFS client is
 * going to going to have problems, but the acutal
 * problem is the filesystem on the NFS server.
 * It's not NFS, it's the local filesystem on the
 * NFS server that is not correctly permitting
 * the sequence to function.
 */
/* _SUA_ Services for Unix Applications, under Windows
    does not have a truncate, so this must be skipped */
        if((fd = open(filename, (int)O_CREAT|O_RDWR,0))<0)
        {
                printf("\nCan not open temp file: %s\n",
                        filename);
                perror("open");
                exit(44);
        }
		if(!notruncate)
		{
			wval=ftruncate(fd,0);
			if(wval < 0)
			{
				printf("\n\nSanity check failed. Do not deploy this filesystem in a production environment !\n");
				exit(44);
			}
			close(fd);

		}
/* Sanity check */

	ltest=3;

	for( j=0; j<ltest; j++)
	{
		if(j==0)
		{
			if(!notruncate)
			{
	  	   		if((fd = creat(filename, 0640))<0)
	  	   		{
					printf("\nCan not create temp file: %s\n", 
						filename);
					perror("creat");
					exit(42);
	  	   		}
			}
		}
		if(fd) 
			close(fd);

	  	 if((fd = open(filename, (int)file_flags,0))<0)
	  	 {
			printf("\nCan not open temp file: %s\n", 
				filename);
			perror("open");
			exit(44);
	  	 }

		wval=fsync(fd);
		if(wval==-1){
			perror("fsync");
		}
		pbuff=mainbuffer;
		starttime1 = time_so_far();

		compute_val=(double)0;
		w_traj_ops_completed=0;
		w_traj_bytes_completed=0;

		for(i=0; i<numrecs64; i++){
			    wval=write(fd, pbuff, (size_t ) reclen);
			    if(wval != reclen)
			    {
#ifdef NO_PRINT_LLD
			    	printf("\nError writing block %ld, fd= %d\n", i,
					 fd);
#else
			    	printf("\nError writing block %lld, fd= %d\n", i,
					 fd);
#endif
			    	if(wval == -1)
					perror("write");
			    }
			w_traj_ops_completed++;
			w_traj_bytes_completed+=reclen;
		}

		writetime[j] = ((time_so_far() - starttime1))
			-compute_val;
		if(writetime[j] < (double).000001) 
		{
			writetime[j]=(double).000001;
		}
		wval=close(fd);
		if(wval==-1){
			perror("close");
		}
	}

	filebytes64=w_traj_bytes_completed;
		
        for(j=0;j<ltest;j++)
        {
                  writerate[j] = 
                    (unsigned long long) ((double) filebytes64 / writetime[j]);
		  printf("%s: ltest %d writerate %llu\n", __func__, j, writerate[j]);
	}

}