Commit 8fd6d930 authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

file.c: added I/O timer

parent 9eb70dc9
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <unistd.h> #include <unistd.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/time.h> // gettimeofday()
#include <fcntl.h> #include <fcntl.h>
/* /*
size_t getpagesize(void); size_t getpagesize(void);
...@@ -116,6 +117,7 @@ typedef struct ...@@ -116,6 +117,7 @@ typedef struct
off_t bufferStart; off_t bufferStart;
off_t bufferEnd; off_t bufferEnd;
size_t bufferCnt; size_t bufferCnt;
double time_in_sec;
} }
bfile_t; bfile_t;
...@@ -130,7 +132,7 @@ enum F_I_L_E_Flags ...@@ -130,7 +132,7 @@ enum F_I_L_E_Flags
}; };
static int FileInfo = FALSE; static int FileInfo = FALSE;
#if ! defined (MIN_BUF_SIZE) #if ! defined (MIN_BUF_SIZE)
...@@ -304,6 +306,7 @@ void file_init_entry(bfile_t *fileptr) ...@@ -304,6 +306,7 @@ void file_init_entry(bfile_t *fileptr)
fileptr->bufferPos = 0; fileptr->bufferPos = 0;
fileptr->bufferCnt = 0; fileptr->bufferCnt = 0;
fileptr->bufferPtr = NULL; fileptr->bufferPtr = NULL;
fileptr->time_in_sec = 0.0;
} }
static static
...@@ -360,6 +363,15 @@ int pagesize(void) ...@@ -360,6 +363,15 @@ int pagesize(void)
#endif #endif
} }
static
double file_time()
{
double tseconds = 0.0;
struct timeval mytime;
gettimeofday(&mytime, NULL);
tseconds = (double) mytime.tv_sec + (double) mytime.tv_usec*1.0e-6;
return (tseconds);
}
void fileDebug(int debug) void fileDebug(int debug)
{ {
...@@ -759,7 +771,7 @@ void file_initialize(void) ...@@ -759,7 +771,7 @@ void file_initialize(void)
if ( FILE_Debug ) if ( FILE_Debug )
Message("FILE_MAX = %d", _file_max); Message("FILE_MAX = %d", _file_max);
FileInfo = (int) file_getenv("FILE_INFO"); FileInfo = (int) file_getenv("FILE_INFO");
value = file_getenv("FILE_BUFSIZE"); value = file_getenv("FILE_BUFSIZE");
if ( value >= 0 ) FileBufferSizeEnv = value; if ( value >= 0 ) FileBufferSizeEnv = value;
...@@ -1196,6 +1208,7 @@ int fileClose(int fileID) ...@@ -1196,6 +1208,7 @@ int fileClose(int fileID)
char *fbtname[] = {"unknown", "standard", "mmap"}; char *fbtname[] = {"unknown", "standard", "mmap"};
char *ftname[] = {"unknown", "open", "fopen"}; char *ftname[] = {"unknown", "open", "fopen"};
bfile_t *fileptr; bfile_t *fileptr;
double rout = 0;
fileptr = file_to_pointer(fileID); fileptr = file_to_pointer(fileID);
...@@ -1252,6 +1265,15 @@ int fileClose(int fileID) ...@@ -1252,6 +1265,15 @@ int fileClose(int fileID)
fprintf(stderr, " bytes transfered : %ld\n", (long) fileptr->byteTrans); fprintf(stderr, " bytes transfered : %ld\n", (long) fileptr->byteTrans);
} }
if ( fileptr->time_in_sec > 0 )
{
rout = fileptr->byteTrans;
rout /= 1024.*1014.*fileptr->time_in_sec;
}
fprintf(stderr, " wall time [s] : %.2f\n", fileptr->time_in_sec);
fprintf(stderr, " data rate [MB/s] : %.1f\n", rout);
fprintf(stderr, " file access : %ld\n", fileptr->access); fprintf(stderr, " file access : %ld\n", fileptr->access);
if ( fileptr->mode == 'r' && fileptr->type == FILE_TYPE_OPEN ) if ( fileptr->mode == 'r' && fileptr->type == FILE_TYPE_OPEN )
{ {
...@@ -1390,6 +1412,10 @@ size_t fileRead(int fileID, void *restrict ptr, size_t size) ...@@ -1390,6 +1412,10 @@ size_t fileRead(int fileID, void *restrict ptr, size_t size)
if ( fileptr ) if ( fileptr )
{ {
double t_begin = 0.0;
if ( FileInfo ) t_begin = file_time();
if ( fileptr->type == FILE_TYPE_OPEN ) if ( fileptr->type == FILE_TYPE_OPEN )
nread = file_read_from_buffer(fileptr, ptr, size); nread = file_read_from_buffer(fileptr, ptr, size);
else else
...@@ -1404,6 +1430,8 @@ size_t fileRead(int fileID, void *restrict ptr, size_t size) ...@@ -1404,6 +1430,8 @@ size_t fileRead(int fileID, void *restrict ptr, size_t size)
} }
} }
if ( FileInfo ) fileptr->time_in_sec += file_time() - t_begin;
fileptr->position += nread; fileptr->position += nread;
fileptr->byteTrans += nread; fileptr->byteTrans += nread;
fileptr->access++; fileptr->access++;
...@@ -1424,13 +1452,19 @@ size_t fileWrite(int fileID, const void *restrict ptr, size_t size) ...@@ -1424,13 +1452,19 @@ size_t fileWrite(int fileID, const void *restrict ptr, size_t size)
if ( fileptr ) if ( fileptr )
{ {
double t_begin = 0.0;
/* if ( fileptr->buffer == NULL ) file_set_buffer(fileptr); */ /* if ( fileptr->buffer == NULL ) file_set_buffer(fileptr); */
if ( FileInfo ) t_begin = file_time();
if ( fileptr->type == FILE_TYPE_FOPEN ) if ( fileptr->type == FILE_TYPE_FOPEN )
nwrite = fwrite(ptr, 1, size, fileptr->fp); nwrite = fwrite(ptr, 1, size, fileptr->fp);
else else
nwrite = write(fileptr->fd, ptr, size); nwrite = write(fileptr->fd, ptr, size);
if ( FileInfo ) fileptr->time_in_sec += file_time() - t_begin;
fileptr->position += nwrite; fileptr->position += nwrite;
fileptr->byteTrans += nwrite; fileptr->byteTrans += nwrite;
fileptr->access++; fileptr->access++;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment