⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fileop.c

📁 硬盘速度测试 linux下 源码 c/c
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * Author: Don Capps * 3/13/2006 * Copyright:  (2006) *   You are free to distribute and use this benchmark, for free. * You are not permitted to distribute modified versions, or * borrow code from this project to create proprietary products * or competitive benchmarks. Any product that contains any * of this code will be considered a derivative work and will * be the sole property of me. *  fileop [-f X ]|[-l # -u #] [-s Y] [-t] [-v] [-e] [-b] [-w] [-h] [-d]       -f # Force factor. X^3 files will be created and removed.       -l # Lower limit on the value of the Force factor.       -u # Upper limit on the value of the Force factor.       -s # Optional. Sets filesize for the create/write.       -t # Verbose output option.       -v # Version information.       -e # Excel importable format.       -b Output best case       -w Output worst case       -h Help text       -d <dir> specify starting directory. * * X is a force factor. The total number of files will *   be X * X * X   ( X ^ 3 ) *   The structure of the file tree is: *   X number of Level 1 directorys, with X number of *   level 2 directories, with X number of files in each *   of the level 2 directories. * *   Example:  fileop 2 * *           dir_1                        dir_2 *          /     \                      /     \ *    sdir_1       sdir_2          sdir_1       sdir_2 *    /     \     /     \          /     \      /     \ * file_1 file_2 file_1 file_2   file_1 file_2 file_1 file_2 * * Each file will be created, and then 1 byte is written to the file. * */#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <sys/time.h>#include <stdlib.h>#include <stdio.h>#include <signal.h>#include <unistd.h>#include <dirent.h>#include <string.h>#if defined(Windows)#include <Windows.h>#endifint x,excel;int verbose = 0;int sz = 1;char *mbuffer;#define _STAT_CREATE 0#define _STAT_WRITE 1#define _STAT_CLOSE 2#define _STAT_LINK 3#define _STAT_UNLINK 4#define _STAT_DELETE 5#define _STAT_STAT 6#define _STAT_ACCESS 7#define _STAT_CHMOD 8#define _STAT_READDIR 9#define _STAT_DIR_CREATE 10#define _STAT_DIR_DELETE 11#define _STAT_READ 12#define _NUM_STATS 14struct stat_struct {	double starttime;	double endtime;	double speed;	double best;	double worst;	double dummy;	double total_time;	double dummy1;	long long counter;} volatile stats[_NUM_STATS];static double time_so_far(void);void dir_create(int);void dir_delete(int);void file_create(int);void file_stat(int);void file_access(int);void file_chmod(int);void file_readdir(int);void file_delete(int);void file_link(int);void file_unlink(int);void file_read(int);void splash(void);void usage(void);void bzero();void clear_stats();int validate(char *, int , char );#define THISVERSION "        $Revision: 1.40 $"/*#define NULL 0*/char version[]=THISVERSION;char thedir[]="."; /* Default is to use the current directory */int cret;int lower, upper,range;int i;int best, worst;int dirlen;int main(int argc, char **argv){	if(argc == 1)	{		usage();		exit(1);	}	while((cret = getopt(argc,argv,"hbwetvf:s:l:u:d: ")) != EOF){		switch(cret){                case 'h':                        usage();                        exit(0);                        break;                case 'd' :                        dirlen=strlen(optarg);                        if (optarg[dirlen-1]=='/') {                          strncpy(thedir, optarg, dirlen-1);                        }                        else {                          strncpy(thedir, optarg, dirlen);                        }                        break;		case 'f':	/* Force factor */			x=atoi(optarg);			if(x < 0)				x=1;			break;		case 's':	/* Size of files */                        sz=atoi(optarg);                        if(optarg[strlen(optarg)-1]=='k' ||                                optarg[strlen(optarg)-1]=='K'){                                sz = (1024 * atoi(optarg));                        }                        if(optarg[strlen(optarg)-1]=='m' ||                                optarg[strlen(optarg)-1]=='M'){                                sz = (1024 * 1024 * atoi(optarg));                        }			if(sz < 0)				sz=1;			break;		case 'l':	/* lower force value */			lower=atoi(optarg);			range=1;			if(lower < 0)				lower=1;			break;		case 'v':	/* version */			splash();			exit(0);			break;		case 'u':	/* upper force value */			upper=atoi(optarg);			range=1;			if(upper < 0)				upper=1;			break;		case 't':	/* verbose */			verbose=1;			break;		case 'e':	/* Excel */			excel=1;			break;		case 'b':	/* Best */			best=1;			break;		case 'w':	/* Worst */			worst=1;			break;		}	}	mbuffer=(char *)malloc(sz);	memset(mbuffer,'a',sz);	if(!excel)	  printf("\nFileop:  File size is %d,  Output is in Ops/sec. (A=Avg, B=Best, W=Worst)\n",sz);	if(!verbose)	{#ifdef Windows	   	printf(" .     %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %12s\n",       	   	"mkdir","rmdir","create","read","write","close","stat",		"access","chmod","readdir","delete"," Total_files");#else	   	printf(" .     %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %6s %12s\n",       	   	"mkdir","rmdir","create","read","write","close","stat",		"access","chmod","readdir","link  ","unlink","delete",		" Total_files");#endif	}	if(x==0)		x=1;	if(range==0)		lower=upper=x;	for(i=lower;i<=upper;i++)	{		clear_stats();		x=i;	   /*	    * Dir Create test 	    */	   dir_create(x);	   if(verbose)	   {	      printf("mkdir:   Dirs = %9lld ",stats[_STAT_DIR_CREATE].counter);	      printf("Total Time = %12.9f seconds\n", stats[_STAT_DIR_CREATE].total_time);	      printf("         Avg mkdir(s)/sec     = %12.2f (%12.9f seconds/op)\n",			stats[_STAT_DIR_CREATE].counter/stats[_STAT_DIR_CREATE].total_time,			stats[_STAT_DIR_CREATE].total_time/stats[_STAT_DIR_CREATE].counter);	      printf("         Best mkdir(s)/sec    = %12.2f (%12.9f seconds/op)\n",1/stats[_STAT_DIR_CREATE].best,stats[_STAT_DIR_CREATE].best);	      printf("         Worst mkdir(s)/sec   = %12.2f (%12.9f seconds/op)\n\n",1/stats[_STAT_DIR_CREATE].worst,stats[_STAT_DIR_CREATE].worst);	   }	   /*	    * Dir delete test	    */	   dir_delete(x);	   if(verbose)	   {	   printf("rmdir:   Dirs = %9lld ",stats[_STAT_DIR_DELETE].counter);	   printf("Total Time = %12.9f seconds\n",stats[_STAT_DIR_DELETE].total_time);	   printf("         Avg rmdir(s)/sec     = %12.2f (%12.9f seconds/op)\n",			stats[_STAT_DIR_DELETE].counter/stats[_STAT_DIR_DELETE].total_time,			stats[_STAT_DIR_DELETE].total_time/stats[_STAT_DIR_DELETE].counter);	   printf("         Best rmdir(s)/sec    = %12.2f (%12.9f seconds/op)\n",1/stats[_STAT_DIR_DELETE].best,stats[_STAT_DIR_DELETE].best);	   printf("         Worst rmdir(s)/sec   = %12.2f (%12.9f seconds/op)\n\n",1/stats[_STAT_DIR_DELETE].worst,stats[_STAT_DIR_DELETE].worst);	   }	   /*	    * Create test 	    */	   file_create(x);	   if(verbose)	   {	      printf("create:  Files = %9lld ",stats[_STAT_CREATE].counter);	      printf("Total Time = %12.9f seconds\n", stats[_STAT_CREATE].total_time);	      printf("         Avg create(s)/sec    = %12.2f (%12.9f seconds/op)\n",			stats[_STAT_CREATE].counter/stats[_STAT_CREATE].total_time,			stats[_STAT_CREATE].total_time/stats[_STAT_CREATE].counter);	      printf("         Best create(s)/sec   = %12.2f (%12.9f seconds/op)\n",			1/stats[_STAT_CREATE].best,stats[_STAT_CREATE].best);	      printf("         Worst create(s)/sec  = %12.2f (%12.9f seconds/op)\n\n",			1/stats[_STAT_CREATE].worst,stats[_STAT_CREATE].worst);	      printf("write:   Files = %9lld ",stats[_STAT_WRITE].counter);	      printf("Total Time = %12.9f seconds\n", stats[_STAT_WRITE].total_time);	      printf("         Avg write(s)/sec     = %12.2f (%12.9f seconds/op)\n",			stats[_STAT_WRITE].counter/stats[_STAT_WRITE].total_time,			stats[_STAT_WRITE].total_time/stats[_STAT_WRITE].counter);	      printf("         Best write(s)/sec    = %12.2f (%12.9f seconds/op)\n",			1/stats[_STAT_WRITE].best,stats[_STAT_WRITE].best);   	      printf("         Worst write(s)/sec   = %12.2f (%12.9f seconds/op)\n\n",			1/stats[_STAT_WRITE].worst,stats[_STAT_WRITE].worst);	      printf("close:   Files = %9lld ",stats[_STAT_CLOSE].counter);	      printf("Total Time = %12.9f seconds\n", stats[_STAT_CLOSE].total_time);	      printf("         Avg close(s)/sec     = %12.2f (%12.9f seconds/op)\n",			stats[_STAT_CLOSE].counter/stats[_STAT_CLOSE].total_time,			stats[_STAT_CLOSE].total_time/stats[_STAT_CLOSE].counter);	      printf("         Best close(s)/sec    = %12.2f (%12.9f seconds/op)\n",			1/stats[_STAT_CLOSE].best,stats[_STAT_CLOSE].best);	      printf("         Worst close(s)/sec   = %12.2f (%12.9f seconds/op)\n\n",			1/stats[_STAT_CLOSE].worst,stats[_STAT_CLOSE].worst);	   }	   /*	    * Stat test 	    */	   file_stat(x);	   if(verbose)	   {	      printf("stat:    Files = %9lld ",stats[_STAT_STAT].counter);	      printf("Total Time = %12.9f seconds\n", stats[_STAT_STAT].total_time);	      printf("         Avg stat(s)/sec      = %12.2f (%12.9f seconds/op)\n",			stats[_STAT_STAT].counter/stats[_STAT_STAT].total_time,			stats[_STAT_STAT].total_time/stats[_STAT_STAT].counter);	      printf("         Best stat(s)/sec     = %12.2f (%12.9f seconds/op)\n",			1/stats[_STAT_STAT].best,stats[_STAT_STAT].best);	      printf("         Worst stat(s)/sec    = %12.2f (%12.9f seconds/op)\n\n",			1/stats[_STAT_STAT].worst,stats[_STAT_STAT].worst);	   }	   /*	    * Read test 	    */	   file_read(x);	   if(verbose)	   {	      printf("read:    Files = %9lld ",stats[_STAT_READ].counter);	      printf("Total Time = %12.9f seconds\n", stats[_STAT_READ].total_time);	      printf("         Avg read(s)/sec      = %12.2f (%12.9f seconds/op)\n",			stats[_STAT_READ].counter/stats[_STAT_READ].total_time,			stats[_STAT_READ].total_time/stats[_STAT_READ].counter);	      printf("         Best read(s)/sec     = %12.2f (%12.9f seconds/op)\n",			1/stats[_STAT_READ].best,stats[_STAT_READ].best);	      printf("         Worst read(s)/sec    = %12.2f (%12.9f seconds/op)\n\n",			1/stats[_STAT_READ].worst,stats[_STAT_READ].worst);	   }	   /*	    * Access test 	    */	   file_access(x);	   if(verbose)	   {	      printf("access:  Files = %9lld ",stats[_STAT_ACCESS].counter);	      printf("Total Time = %12.9f seconds\n", stats[_STAT_ACCESS].total_time);	      printf("         Avg access(s)/sec    = %12.2f (%12.9f seconds/op)\n",			stats[_STAT_ACCESS].counter/stats[_STAT_ACCESS].total_time,			stats[_STAT_ACCESS].total_time/stats[_STAT_ACCESS].counter);	      printf("         Best access(s)/sec   = %12.2f (%12.9f seconds/op)\n",			1/stats[_STAT_ACCESS].best,stats[_STAT_ACCESS].best);	      printf("         Worst access(s)/sec  = %12.2f (%12.9f seconds/op)\n\n",			1/stats[_STAT_ACCESS].worst,stats[_STAT_ACCESS].worst);	   }	   /*	    * Chmod test 	    */	   file_chmod(x);	   if(verbose)	   {	      printf("chmod:   Files = %9lld ",stats[_STAT_CHMOD].counter);	      printf("Total Time = %12.9f seconds\n", stats[_STAT_CHMOD].total_time);	      printf("         Avg chmod(s)/sec     = %12.2f (%12.9f seconds/op)\n",			stats[_STAT_CHMOD].counter/stats[_STAT_CHMOD].total_time,			stats[_STAT_CHMOD].total_time/stats[_STAT_CHMOD].counter);	      printf("         Best chmod(s)/sec    = %12.2f (%12.9f seconds/op)\n",			1/stats[_STAT_CHMOD].best,stats[_STAT_CHMOD].best);	      printf("         Worst chmod(s)/sec   = %12.2f (%12.9f seconds/op)\n\n",			1/stats[_STAT_CHMOD].worst,stats[_STAT_CHMOD].worst);	   }	   /*	    * readdir test 	    */	   file_readdir(x);	   if(verbose)	   {	      printf("readdir: Files = %9lld ",stats[_STAT_READDIR].counter);	      printf("Total Time = %12.9f seconds\n", stats[_STAT_READDIR].total_time);	      printf("         Avg readdir(s)/sec   = %12.2f (%12.9f seconds/op)\n",			stats[_STAT_READDIR].counter/stats[_STAT_READDIR].total_time,			stats[_STAT_READDIR].total_time/stats[_STAT_READDIR].counter);	      printf("         Best readdir(s)/sec  = %12.2f (%12.9f seconds/op)\n",			1/stats[_STAT_READDIR].best,stats[_STAT_READDIR].best);	      printf("         Worst readdir(s)/sec = %12.2f (%12.9f seconds/op)\n\n",			1/stats[_STAT_READDIR].worst,stats[_STAT_READDIR].worst);	   }#if !defined(Windows)	   /*	    * link test 	    */	   file_link(x);	   if(verbose)	   {	      printf("link:    Files = %9lld ",stats[_STAT_LINK].counter);	      printf("Total Time = %12.9f seconds\n",stats[_STAT_LINK].total_time);	      printf("         Avg link(s)/sec      = %12.2f (%12.9f seconds/op)\n",			stats[_STAT_LINK].counter/stats[_STAT_LINK].total_time,			stats[_STAT_LINK].total_time/stats[_STAT_LINK].counter);	      printf("         Best link(s)/sec     = %12.2f (%12.9f seconds/op)\n",			1/stats[_STAT_LINK].best,stats[_STAT_LINK].best);	      printf("         Worst link(s)/sec    = %12.2f (%12.9f seconds/op)\n\n",			1/stats[_STAT_LINK].worst,stats[_STAT_LINK].worst);	   }	   /*	    * unlink test 	    */	   file_unlink(x);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -