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

📄 iozone.c

📁 硬盘速度测试 linux下 源码 c/c
💻 C
📖 第 1 页 / 共 5 页
字号:
/************************************************************************//*	Original Author: 						*//*		William Norcott (wnorcott@us.oracle.com)		*//*              4 Dunlap Drive						*//*              Nashua, NH 03060					*//*  									*//************************************************************************//*      Enhancements by:						*//*	 	Don Capps (capps@iozone.org)				*//* 		7417 Crenshaw						*//* 		Plano, TX 75025						*//*  									*//************************************************************************//*  Copyright 1991, 1992, 1994, 1998, 2000, 2001  William D. Norcott	*//************************************************************************//*									*//* Iozone is based on the original work done by William Norrcot. It has	*//* been enhanced so that it provides a more complete filesystem   	*//* characterization.							*//* Its purpose is to provide automated filesystem characterization.	*//* Enhancements have been made by:					*//*									*//* Don Capps	   (HP)	         capps@iozone.org			*/ /*									*//* Iozone can perform single stream and multi stream I/O		*//* also it now performs read, write, re-read, re-write, 		*//* read backwards, read/write random, re-read record, 			*//* pread, re-pread, re-pwrite, preadv, re-preadv, pwritev,		*//* stride read, and re-pwritev,mmap, POSIX async I/O, NFS               *//* cluster testing and much more.					*//*									*//* The frontend now uses getopt() and the user can control many more	*//* of the actions.							*//*									*//*									*//************************************************************************//************************************************************************//* For the beginner... 						        *//* 									*//* 1. make linux  (linux, hpux, convex, hpux_no_ansi)			*//* 2. type ./iozone -Ra							*//* 									*//*  Hint: Type make    (it will give you a list of valid targets)	*//* 									*//************************************************************************//* The version number */#define THISVERSION "        Version $Revision: 3.291 $"#if defined(linux)  #define _GNU_SOURCE#endif/* Include for Cygnus development environment for Windows */#if defined (Windows)#include <Windows.h>int errno;#else#if defined(linux)#include <errno.h>#elseextern  int errno;   /* imported for errors */extern  int h_errno; /* imported for errors */#endif#endif#include <sys/types.h>#include <sys/stat.h>#if defined (__LP64__) || defined(OSF_64) || defined(__alpha__) || defined(__arch64__) || defined(_LP64) || defined(__s390x__) || defined(__AMD64__)#define MODE "\tCompiled for 64 bit mode."#define _64BIT_ARCH_#else#define MODE "\tCompiled for 32 bit mode."#endif#ifndef NO_THREADS#include <pthread.h>#endif#if defined(HAVE_ANSIC_C) && defined(linux)#include <stdlib.h>#include <sys/wait.h>#endif#ifdef HAVE_PROTO#include "proto.h"#elseint atoi();int close();int unlink();int main();void record_command_line();#if !defined(linux)int wait();#endifint fsync();void srand48();long lrand48();void create_list();void Poll();void print_header();void Kill();long long l_min();long long l_max();long long mythread_create();int gen_new_buf();void touch_dedup();#endif#include <fcntl.h>char *help[] = {"    Usage: iozone [-s filesize_Kb] [-r record_size_Kb] [-f [path]filename] [-h]","                  [-i test] [-E] [-p] [-a] [-A] [-z] [-Z] [-m] [-M] [-t children]","                  [-l min_number_procs] [-u max_number_procs] [-v] [-R] [-x] [-o]","                  [-d microseconds] [-F path1 path2...] [-V pattern] [-j stride]","                  [-T] [-C] [-B] [-D] [-G] [-I] [-H depth] [-k depth] [-U mount_point]","                  [-S cache_size] [-O] [-L cacheline_size] [-K] [-g maxfilesize_Kb]","                  [-n minfilesize_Kb] [-N] [-Q] [-P start_cpu] [-e] [-c] [-b Excel.xls]","                  [-J milliseconds] [-X write_telemetry_filename] [-w] [-W]","                  [-Y read_telemetry_filename] [-y minrecsize_Kb] [-q maxrecsize_Kb]","                  [-+u] [-+m cluster_filename] [-+d] [-+x multiplier] [-+p # ]","                  [-+r] [-+t] [-+X] [-+Z]"," ","           -a  Auto mode","           -A  Auto2 mode","           -b Filename  Create Excel worksheet file","           -B  Use mmap() files","           -c  Include close in the timing calculations","           -C  Show bytes transferred by each child in throughput testing","           -d #  Microsecond delay out of barrier","           -D  Use msync(MS_ASYNC) on mmap files","           -e  Include flush (fsync,fflush) in the timing calculations","           -E  Run extension tests","           -f filename  to use","           -F filenames  for each process/thread in throughput test","           -g #  Set maximum file size (in Kbytes) for auto mode (or #m or #g)","           -G  Use msync(MS_SYNC) on mmap files","           -h  help","           -H #  Use POSIX async I/O with # async operations","           -i #  Test to run (0=write/rewrite, 1=read/re-read, 2=random-read/write","                 3=Read-backwards, 4=Re-write-record, 5=stride-read, 6=fwrite/re-fwrite","                 7=fread/Re-fread, 8=random_mix, 9=pwrite/Re-pwrite, 10=pread/Re-pread","                 11=pwritev/Re-pwritev, 12=preadv/Re-preadv)","           -I  Use VxFS VX_DIRECT, O_DIRECT,or O_DIRECTIO for all file operations","           -j #  Set stride of file accesses to (# * record size)","           -J #  milliseconds of compute cycle before each I/O operation","           -k #  Use POSIX async I/O (no bcopy) with # async operations","           -K  Create jitter in the access pattern for readers","           -l #  Lower limit on number of processes to run","           -L #  Set processor cache line size to value (in bytes)","           -m  Use multiple buffers","           -M  Report uname -a output","           -n #  Set minimum file size (in Kbytes) for auto mode (or #m or #g)","           -N  Report results in microseconds per operation","           -o  Writes are synch (O_SYNC)","           -O  Give results in ops/sec.","           -p  Purge on","           -P #  Bind processes/threads to processors, starting with this cpu","           -q #  Set maximum record size (in Kbytes) for auto mode (or #m or #g)","           -Q  Create offset/latency files","           -r #  record size in Kb","              or -r #k .. size in Kb","              or -r #m .. size in Mb","              or -r #g .. size in Gb","           -R  Generate Excel report","           -s #  file size in Kb","              or -s #k .. size in Kb","              or -s #m .. size in Mb","              or -s #g .. size in Gb","           -S #  Set processor cache size to value (in Kbytes)","           -t #  Number of threads or processes to use in throughput test","           -T  Use POSIX pthreads for throughput tests","           -u #  Upper limit on number of processes to run","           -U  Mount point to remount between tests","           -v  version information","           -V #  Verify data pattern write/read","           -w  Do not unlink temporary file","           -W  Lock file when reading or writing","           -x  Turn off stone-walling","           -X filename  Write telemetry file. Contains lines with (offset reclen compute_time) in ascii","           -y #  Set minimum record size (in Kbytes) for auto mode (or #m or #g)","           -Y filename  Read  telemetry file. Contains lines with (offset reclen compute_time) in ascii","           -z  Used in conjunction with -a to test all possible record sizes","           -Z  Enable mixing of mmap I/O and file I/O","           -+K Sony special. Manual control of test 8.","           -+m  Cluster_filename   Enable Cluster testing","           -+d  File I/O diagnostic mode. (To troubleshoot a broken file I/O subsystem)","           -+u  Enable CPU utilization output (Experimental)","           -+x # Multiplier to use for incrementing file and record sizes","           -+p # Percentage of mix to be reads","           -+r Enable O_RSYNC|O_SYNC for all testing.","           -+t Enable network performance test. Requires -+m ","           -+n No retests selected.","           -+k Use constant aggregate data set size.","           -+q Delay in seconds between tests.","           -+l Enable record locking mode.","           -+L Enable record locking mode, with shared file.","           -+B Sequential mixed workload.",#if defined(O_DSYNC)"           -+D Enable O_DSYNC mode.",#endif#ifndef NO_MADVISE"           -+A #  Enable madvise. 0 = normal, 1=random, 2=sequential","                                  3=dontneed, 4=willneed",#endif"           -+V Enable shared file. No locking.",#if defined(Windows)"           -+U Windows Unbufferd I/O API (Very Experimental)",#endif"           -+X Enable short circuit mode for filesystem testing ONLY","               ALL Results are NOT valid in this mode.","           -+Z Enable old data set compatibility mode. WARNING.. Published","               hacks may invalidate these results and generate bogus, high","               values for results.","           -+w ## Percent of non-dedup-able data in buffers.","" };char *head1[] = {  "       'Iozone' Filesystem Benchmark Program",  " ",THISVERSION,  MODE,  " ",  "       Original Author: William Norcott (wnorcott@us.oracle.com)",  "               4 Dunlap Drive",  "               Nashua, NH 03060",  " ",  "       Enhancements: Don Capps (capps@iozone.org)",  "        	  7417 Crenshaw",  "        	  Plano, TX 75025",  " ",  "  Copyright 1991, 1992, 1994, 1998, 1999, 2002   William D. Norcott",  " ",  "  License to freely use and distribute this software is hereby granted ",  "  by the author, subject to the condition that this copyright notice ",  "  remains intact.  The author retains the exclusive right to publish ",  "  derivative works based on this work, including, but not limited to, ",  "  revised versions of this work",  " ",  "  Other contributors:",  " ",  "  Don Capps       (Network Appliance)	capps@iozone.org",  " ",  ""};/******************************************************************    INCLUDE FILES (system-dependent)******************************************************************/#include <sys/mman.h>#include <stdio.h>#include <signal.h>#include <unistd.h>#include <fcntl.h>#if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__APPLE__) && !defined(__DragonFly__)#include <malloc.h>#endif#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__APPLE__) || defined(__DragonFly__)#include <stdlib.h>#include <string.h>#endif#if defined (__FreeBSD__) || defined(__OpenBSD__) || defined(__bsdi__) || defined(__APPLE__) || defined(__DragonFly__)#ifndef O_SYNC#define O_SYNC O_FSYNC#endif#endif#if ((defined(solaris) && defined(__LP64__)) || defined(__s390x__))/* If we are building for 64-bit Solaris, all functions that return pointers * must be declared before they are used; otherwise the compiler will assume * that they return ints and the top 32 bits of the pointer will be lost, * causing segmentation faults.  The following includes take care of this. * It should be safe to add these for all other OSs too, but we're only * doing it for Solaris now in case another OS turns out to be a special case. */#include <strings.h>#include <stdlib.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#endif#if ( defined(solaris) && defined(studio11) )#include <strings.h>#include <stdlib.h>#endif#if defined(OSFV5) || defined(linux)#include <string.h>#endif#if defined(linux)#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#endif#ifndef MAP_FAILED#define MAP_FAILED -1#endif#ifdef generictypedef long long off64_t;#endif#if defined(__DragonFly__)#define __off64_t_definedtypedef off_t off64_t;#endif#ifndef solaris#ifndef off64_t#ifndef _OFF64_T#ifndef __AIX__#ifndef __off64_t_defined#ifndef SCO_Unixware_gcc#ifndef UWIN#ifndef __DragonFly__typedef long long off64_t;#endif#endif#endif#endif#endif#endif#endif#endif#ifdef __AIX__#include <fcntl.h>#endif#ifdef VXFS#include <sys/fs/vx_ioctl.h>#endif#ifdef unix#if defined (__APPLE__) || defined(__FreeBSD__) || defined(__DragonFly__)#include <sys/time.h>#endif#include <sys/times.h>#include <sys/file.h>#include <sys/resource.h>#ifndef NULL#define NULL 0#endif#ifndef nolimits#include <limits.h>#endif#endif#ifdef HAVE_ANSIC_C#define VOLATILE volatile#else #define VOLATILE #endif#include <sys/time.h>#ifdef SHARED_MEM#include <sys/shm.h>#endif#if defined(bsd4_2) && !defined(MS_SYNC)#define MS_SYNC 0#define MS_ASYNC 0#endif#if defined(bsd4_4) || defined(__DragonFly__)#define MAP_ANONYMOUS MAP_ANON#endif#if defined(SCO_Unixware_gcc) || defined(solaris) || defined(UWIN) || defined(SCO)#define MAP_FILE (0)#endif#if defined(IRIX) || defined(IRIX64) || defined(Windows) || defined(bsd4_2) || defined(bsd4_4) || defined(SCO) || defined(Solaris) || defined(SCO_Unixware_gcc)long long page_size = 4096;#define GOT_PAGESIZE 1#elif defined(NBPG)long long page_size = NBPG;#define GOT_PAGESIZE 1#elif defined(old_linux)#include <asm/page.h>long long page_size = PAGE_SIZE;#define GOT_PAGESIZE 1#elif !defined(GOT_PAGESIZE)long long page_size = 4096; /* Used when all else fails */#endif#ifdef HAVE_PREAD#ifdef HAVE_PREADV#define PVECMAX 16#ifdef _HPUX_SOURCE#define PER_VECTOR_OFFSET#include <sys/puio.h>struct piovec piov[PVECMAX];#else#include <sys/uio.h>struct iovec piov[PVECMAX];#define piov_base iov_base#define piov_len iov_len#endif#endif#endif#define DEDUPSEED 0x2719362/* * In multi thread/process throughput mode each child keeps track of * statistics and communicates them through various flavors of * shared memory, and via messages. */struct child_stats {	long long flag;		/* control space */	long long flag1;	/* pad */	float walltime;	        /* child elapsed time */	float cputime;		/* child CPU time */	float throughput; 	/* Throughput in either kb/sec or ops/sec */	float actual;	   	/* Either actual kb read or # of ops performed */

⌨️ 快捷键说明

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