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

file.c: added I/O timer

parent 9eb70dc9
......@@ -11,6 +11,7 @@
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h> // gettimeofday()
#include <fcntl.h>
/*
size_t getpagesize(void);
......@@ -116,6 +117,7 @@ typedef struct
off_t bufferStart;
off_t bufferEnd;
size_t bufferCnt;
double time_in_sec;
}
bfile_t;
......@@ -304,6 +306,7 @@ void file_init_entry(bfile_t *fileptr)
fileptr->bufferPos = 0;
fileptr->bufferCnt = 0;
fileptr->bufferPtr = NULL;
fileptr->time_in_sec = 0.0;
}
static
......@@ -360,6 +363,15 @@ int pagesize(void)
#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)
{
......@@ -1196,6 +1208,7 @@ int fileClose(int fileID)
char *fbtname[] = {"unknown", "standard", "mmap"};
char *ftname[] = {"unknown", "open", "fopen"};
bfile_t *fileptr;
double rout = 0;
fileptr = file_to_pointer(fileID);
......@@ -1252,6 +1265,15 @@ int fileClose(int fileID)
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);
if ( fileptr->mode == 'r' && fileptr->type == FILE_TYPE_OPEN )
{
......@@ -1390,6 +1412,10 @@ size_t fileRead(int fileID, void *restrict ptr, size_t size)
if ( fileptr )
{
double t_begin = 0.0;
if ( FileInfo ) t_begin = file_time();
if ( fileptr->type == FILE_TYPE_OPEN )
nread = file_read_from_buffer(fileptr, ptr, size);
else
......@@ -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->byteTrans += nread;
fileptr->access++;
......@@ -1424,13 +1452,19 @@ size_t fileWrite(int fileID, const void *restrict ptr, size_t size)
if ( fileptr )
{
double t_begin = 0.0;
/* if ( fileptr->buffer == NULL ) file_set_buffer(fileptr); */
if ( FileInfo ) t_begin = file_time();
if ( fileptr->type == FILE_TYPE_FOPEN )
nwrite = fwrite(ptr, 1, size, fileptr->fp);
else
nwrite = write(fileptr->fd, ptr, size);
if ( FileInfo ) fileptr->time_in_sec += file_time() - t_begin;
fileptr->position += nwrite;
fileptr->byteTrans += nwrite;
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