Commit da685755 authored by Philip Carns's avatar Philip Carns

move fread wrapper to stdio module

parent 25833864
......@@ -55,7 +55,6 @@ DARSHAN_FORWARD_DECL(pread64, ssize_t, (int fd, void *buf, size_t count, off64_t
DARSHAN_FORWARD_DECL(pwrite64, ssize_t, (int fd, const void *buf, size_t count, off64_t offset));
DARSHAN_FORWARD_DECL(readv, ssize_t, (int fd, const struct iovec *iov, int iovcnt));
DARSHAN_FORWARD_DECL(writev, ssize_t, (int fd, const struct iovec *iov, int iovcnt));
DARSHAN_FORWARD_DECL(fread, size_t, (void *ptr, size_t size, size_t nmemb, FILE *stream));
DARSHAN_FORWARD_DECL(lseek, off_t, (int fd, off_t offset, int whence));
DARSHAN_FORWARD_DECL(lseek64, off64_t, (int fd, off64_t offset, int whence));
DARSHAN_FORWARD_DECL(fseek, int, (FILE *stream, long offset, int whence));
......@@ -726,37 +725,6 @@ ssize_t DARSHAN_DECL(writev)(int fd, const struct iovec *iov, int iovcnt)
return(ret);
}
size_t DARSHAN_DECL(fread)(void *ptr, size_t size, size_t nmemb, FILE *stream)
{
size_t ret;
int aligned_flag = 0;
double tm1, tm2;
MAP_OR_FAIL(fread);
if((unsigned long)ptr % darshan_mem_alignment == 0) aligned_flag = 1;
tm1 = darshan_core_wtime();
ret = __real_fread(ptr, size, nmemb, stream);
tm2 = darshan_core_wtime();
POSIX_LOCK();
posix_runtime_initialize();
if(ret > 0)
{
POSIX_RECORD_READ(size*ret, fileno(stream), 0, 0,
aligned_flag, 1, tm1, tm2);
}
else
{
POSIX_RECORD_READ(ret, fileno(stream), 0, 0,
aligned_flag, 1, tm1, tm2);
}
POSIX_UNLOCK();
return(ret);
}
off_t DARSHAN_DECL(lseek)(int fd, off_t offset, int whence)
{
off_t ret;
......
......@@ -35,6 +35,7 @@ DARSHAN_FORWARD_DECL(fopen, FILE*, (const char *path, const char *mode));
DARSHAN_FORWARD_DECL(fopen64, FILE*, (const char *path, const char *mode));
DARSHAN_FORWARD_DECL(fclose, int, (FILE *fp));
DARSHAN_FORWARD_DECL(fwrite, size_t, (const void *ptr, size_t size, size_t nmemb, FILE *stream));
DARSHAN_FORWARD_DECL(fread, size_t, (void *ptr, size_t size, size_t nmemb, FILE *stream));
/* The stdio_file_runtime structure maintains necessary runtime metadata
* for the STDIO file record (darshan_stdio_record structure, defined in
......@@ -64,8 +65,6 @@ struct stdio_file_runtime
/* TODO: make sure we need/want all of these fields */
struct darshan_stdio_record* file_record;
int64_t offset;
int64_t last_byte_read;
int64_t last_byte_written;
enum darshan_io_type last_io_type;
double last_meta_end;
double last_read_end;
......@@ -153,8 +152,6 @@ static void stdio_shutdown(void);
file = stdio_file_by_name_setstream(__path, __ret); \
if(!file) break; \
file->offset = 0; \
file->last_byte_written = 0; \
file->last_byte_read = 0; \
file->file_record->counters[STDIO_OPENS] += 1; \
if(file->file_record->fcounters[STDIO_F_OPEN_START_TIMESTAMP] == 0 || \
file->file_record->fcounters[STDIO_F_OPEN_START_TIMESTAMP] > __tm1) \
......@@ -164,13 +161,30 @@ static void stdio_shutdown(void);
} while(0)
#define STDIO_RECORD_READ(__fp, __bytes, __tm1, __tm2) do{ \
int64_t this_offset; \
struct stdio_file_runtime* file; \
file = stdio_file_by_stream(__fp); \
if(!file) break; \
this_offset = file->offset; \
file->offset = this_offset + __bytes; \
if(file->file_record->counters[STDIO_MAX_BYTE_READ] < (this_offset + __bytes - 1)) \
file->file_record->counters[STDIO_MAX_BYTE_READ] = (this_offset + __bytes - 1); \
file->file_record->counters[STDIO_BYTES_READ] += __bytes; \
file->file_record->counters[STDIO_READS] += 1; \
if(file->file_record->fcounters[STDIO_F_READ_START_TIMESTAMP] == 0 || \
file->file_record->fcounters[STDIO_F_READ_START_TIMESTAMP] > __tm1) \
file->file_record->fcounters[STDIO_F_READ_START_TIMESTAMP] = __tm1; \
file->file_record->fcounters[STDIO_F_READ_END_TIMESTAMP] = __tm2; \
DARSHAN_TIMER_INC_NO_OVERLAP(file->file_record->fcounters[STDIO_F_READ_TIME], __tm1, __tm2, file->last_write_end); \
} while(0)
#define STDIO_RECORD_WRITE(__fp, __bytes, __tm1, __tm2) do{ \
int64_t this_offset; \
struct stdio_file_runtime* file; \
file = stdio_file_by_stream(__fp); \
if(!file) break; \
this_offset = file->offset; \
file->last_byte_written = this_offset + __bytes - 1; \
file->offset = this_offset + __bytes; \
if(file->file_record->counters[STDIO_MAX_BYTE_WRITTEN] < (this_offset + __bytes - 1)) \
file->file_record->counters[STDIO_MAX_BYTE_WRITTEN] = (this_offset + __bytes - 1); \
......@@ -238,8 +252,6 @@ int DARSHAN_DECL(fclose)(FILE *fp)
file = stdio_file_by_stream(fp);
if(file)
{
file->last_byte_written = 0;
file->last_byte_read = 0;
if(file->file_record->fcounters[STDIO_F_CLOSE_START_TIMESTAMP] == 0 ||
file->file_record->fcounters[STDIO_F_CLOSE_START_TIMESTAMP] > tm1)
file->file_record->fcounters[STDIO_F_CLOSE_START_TIMESTAMP] = tm1;
......@@ -274,6 +286,26 @@ size_t DARSHAN_DECL(fwrite)(const void *ptr, size_t size, size_t nmemb, FILE *st
return(ret);
}
size_t DARSHAN_DECL(fread)(void *ptr, size_t size, size_t nmemb, FILE *stream)
{
size_t ret;
double tm1, tm2;
MAP_OR_FAIL(fread);
tm1 = darshan_core_wtime();
ret = __real_fread(ptr, size, nmemb, stream);
tm2 = darshan_core_wtime();
STDIO_LOCK();
stdio_runtime_initialize();
if(ret > 0)
STDIO_RECORD_READ(stream, size*ret, tm1, tm2);
STDIO_UNLOCK();
return(ret);
}
/**********************************************************
* Internal functions for manipulating STDIO module state *
**********************************************************/
......
......@@ -14,7 +14,6 @@
--wrap=pwrite64
--wrap=readv
--wrap=writev
--wrap=fread
--wrap=lseek
--wrap=lseek64
--wrap=fseek
......
......@@ -3,3 +3,4 @@
--wrap=fopen64
--wrap=fclose
--wrap=fwrite
--wrap=fread
......@@ -13,13 +13,13 @@
/*
* functions for opening streams
* --------------
* FILE *fdopen(int, const char *); DONE
* FILE *fdopen(int, const char *); DONE
* FILE *fopen(const char *, const char *);
* FILE *freopen(const char *, const char *, FILE *);
*
* functions for closing streams
* --------------
* int fclose(FILE *); DONE
* int fclose(FILE *); DONE
*
* functions for flushing streams
* --------------
......@@ -29,7 +29,7 @@
* --------------
* int fgetc(FILE *);
* char *fgets(char *, int, FILE *);
* size_t fread(void *, size_t, size_t, FILE *);
* size_t fread(void *, size_t, size_t, FILE *); DONE
* int fscanf(FILE *, const char *, ...);
* int getc(FILE *);
* int getc_unlocked(FILE *);
......@@ -64,6 +64,12 @@
X(STDIO_BYTES_WRITTEN) \
/* number of writes */ \
X(STDIO_WRITES) \
/* maximum byte (offset) written */\
X(STDIO_MAX_BYTE_READ) \
/* total bytes written */ \
X(STDIO_BYTES_READ) \
/* number of writes */ \
X(STDIO_READS) \
/* end of counters */\
X(STDIO_NUM_INDICES)
......@@ -80,10 +86,16 @@
X(STDIO_F_WRITE_START_TIMESTAMP) \
/* timestamp of last write completion */\
X(STDIO_F_WRITE_END_TIMESTAMP) \
/* timestamp of first read */\
X(STDIO_F_READ_START_TIMESTAMP) \
/* timestamp of last read completion */\
X(STDIO_F_READ_END_TIMESTAMP) \
/* cumulative meta time */\
X(STDIO_F_META_TIME) \
/* cumulative write time */\
X(STDIO_F_WRITE_TIME) \
/* cumulative read time */\
X(STDIO_F_READ_TIME) \
/* end of counters */\
X(STDIO_F_NUM_INDICES)
......
......@@ -31,6 +31,7 @@ int main(int argc, char **argv)
int namelen;
char processor_name[MPI_MAX_PROCESSOR_NAME];
FILE *file;
char buffer[128] = {0};
/* startup MPI and determine the rank of this process */
MPI_Init(&argc,&argv);
......@@ -43,7 +44,7 @@ int main(int argc, char **argv)
if (mynod == 0) printf("# Using stdio calls.\n");
file = fopen(opt_file, "w");
file = fopen(opt_file, "w+");
if(!file)
{
perror("fopen");
......@@ -51,7 +52,11 @@ int main(int argc, char **argv)
}
if(mynod == 0)
{
fwrite("hello", 1, 6, file);
fseek(file, 0, SEEK_SET);
fread(buffer, 1, 1024, file);
}
fclose(file);
......
......@@ -44,6 +44,11 @@ if [ ! "$STDIO_BYTES_WRITTEN" -eq 6 ]; then
echo "Error: STDIO open count of $STDIO_BYTES_WRITTEN is incorrect" 1>&2
exit 1
fi
STDIO_BYTES_READ=`grep STDIO_BYTES_READ $DARSHAN_TMP/${PROG}.darshan.txt |head -n 1 |cut -f 5`
if [ ! "$STDIO_BYTES_READ" -eq 6 ]; then
echo "Error: STDIO open count of $STDIO_BYTES_READ is incorrect" 1>&2
exit 1
fi
# make sure that some of the floating point counters are valid
......
......@@ -143,7 +143,7 @@ static void darshan_log_print_stdio_record(void *file_rec, char *file_name,
static void darshan_log_print_stdio_description()
{
printf("\n# description of STDIO counters:\n");
printf("# STDIO_{OPENS|WRITES} are types of operations.\n");
printf("# STDIO_{OPENS|WRITES|READS} are types of operations.\n");
printf("# STDIO_BYTES_*: total bytes read and written.\n");
printf("# STDIO_MAX_BYTE_*: highest offset byte read and written.\n");
printf("# STDIO_F_*_START_TIMESTAMP: timestamp of the first call to that type of function.\n");
......
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