Commit 29b23f7e authored by Philip Carns's avatar Philip Carns

move fclose wrapper to stdio module

parent 7e58577d
...@@ -71,7 +71,6 @@ DARSHAN_FORWARD_DECL(mmap64, void*, (void *addr, size_t length, int prot, int fl ...@@ -71,7 +71,6 @@ DARSHAN_FORWARD_DECL(mmap64, void*, (void *addr, size_t length, int prot, int fl
DARSHAN_FORWARD_DECL(fsync, int, (int fd)); DARSHAN_FORWARD_DECL(fsync, int, (int fd));
DARSHAN_FORWARD_DECL(fdatasync, int, (int fd)); DARSHAN_FORWARD_DECL(fdatasync, int, (int fd));
DARSHAN_FORWARD_DECL(close, int, (int fd)); DARSHAN_FORWARD_DECL(close, int, (int fd));
DARSHAN_FORWARD_DECL(fclose, int, (FILE *fp));
DARSHAN_FORWARD_DECL(aio_read, int, (struct aiocb *aiocbp)); DARSHAN_FORWARD_DECL(aio_read, int, (struct aiocb *aiocbp));
DARSHAN_FORWARD_DECL(aio_write, int, (struct aiocb *aiocbp)); DARSHAN_FORWARD_DECL(aio_write, int, (struct aiocb *aiocbp));
DARSHAN_FORWARD_DECL(aio_read64, int, (struct aiocb64 *aiocbp)); DARSHAN_FORWARD_DECL(aio_read64, int, (struct aiocb64 *aiocbp));
...@@ -1162,38 +1161,6 @@ int DARSHAN_DECL(close)(int fd) ...@@ -1162,38 +1161,6 @@ int DARSHAN_DECL(close)(int fd)
return(ret); return(ret);
} }
int DARSHAN_DECL(fclose)(FILE *fp)
{
struct posix_file_runtime* file;
int fd = fileno(fp);
double tm1, tm2;
int ret;
MAP_OR_FAIL(fclose);
tm1 = darshan_core_wtime();
ret = __real_fclose(fp);
tm2 = darshan_core_wtime();
POSIX_LOCK();
posix_runtime_initialize();
file = posix_file_by_fd(fd);
if(file)
{
file->last_byte_written = 0;
file->last_byte_read = 0;
file->file_record->fcounters[POSIX_F_CLOSE_TIMESTAMP] =
darshan_core_wtime();
DARSHAN_TIMER_INC_NO_OVERLAP(
file->file_record->fcounters[POSIX_F_META_TIME],
tm1, tm2, file->last_meta_end);
posix_file_close_fd(fd);
}
POSIX_UNLOCK();
return(ret);
}
int DARSHAN_DECL(aio_read)(struct aiocb *aiocbp) int DARSHAN_DECL(aio_read)(struct aiocb *aiocbp)
{ {
int ret; int ret;
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
DARSHAN_FORWARD_DECL(fopen, FILE*, (const char *path, const char *mode)); 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(fopen64, FILE*, (const char *path, const char *mode));
DARSHAN_FORWARD_DECL(fclose, int, (FILE *fp));
/* The stdio_file_runtime structure maintains necessary runtime metadata /* The stdio_file_runtime structure maintains necessary runtime metadata
* for the STDIO file record (darshan_stdio_record structure, defined in * for the STDIO file record (darshan_stdio_record structure, defined in
...@@ -201,6 +202,39 @@ FILE* DARSHAN_DECL(fopen64)(const char *path, const char *mode) ...@@ -201,6 +202,39 @@ FILE* DARSHAN_DECL(fopen64)(const char *path, const char *mode)
return(ret); return(ret);
} }
int DARSHAN_DECL(fclose)(FILE *fp)
{
struct stdio_file_runtime* file;
double tm1, tm2;
int ret;
MAP_OR_FAIL(fclose);
tm1 = darshan_core_wtime();
ret = __real_fclose(fp);
tm2 = darshan_core_wtime();
STDIO_LOCK();
stdio_runtime_initialize();
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;
file->file_record->fcounters[STDIO_F_CLOSE_END_TIMESTAMP] = tm2;
DARSHAN_TIMER_INC_NO_OVERLAP(
file->file_record->fcounters[STDIO_F_META_TIME],
tm1, tm2, file->last_meta_end);
stdio_file_close_stream(fp);
}
STDIO_UNLOCK();
return(ret);
}
/********************************************************** /**********************************************************
* Internal functions for manipulating STDIO module state * * Internal functions for manipulating STDIO module state *
**********************************************************/ **********************************************************/
......
...@@ -30,7 +30,6 @@ ...@@ -30,7 +30,6 @@
--wrap=fsync --wrap=fsync
--wrap=fdatasync --wrap=fdatasync
--wrap=close --wrap=close
--wrap=fclose
--wrap=aio_read --wrap=aio_read
--wrap=aio_write --wrap=aio_write
--wrap=aio_read64 --wrap=aio_read64
......
--undefined=__wrap_fopen --undefined=__wrap_fopen
--wrap=fopen --wrap=fopen
--wrap=fopen64 --wrap=fopen64
--wrap=fclose
...@@ -66,6 +66,10 @@ ...@@ -66,6 +66,10 @@
X(STDIO_F_OPEN_START_TIMESTAMP) \ X(STDIO_F_OPEN_START_TIMESTAMP) \
/* timestamp of last open completion */\ /* timestamp of last open completion */\
X(STDIO_F_OPEN_END_TIMESTAMP) \ X(STDIO_F_OPEN_END_TIMESTAMP) \
/* timestamp of first close */\
X(STDIO_F_CLOSE_START_TIMESTAMP) \
/* timestamp of last close completion */\
X(STDIO_F_CLOSE_END_TIMESTAMP) \
/* cumulative meta time */\ /* cumulative meta time */\
X(STDIO_F_META_TIME) \ X(STDIO_F_META_TIME) \
/* end of counters */\ /* end of counters */\
......
...@@ -57,6 +57,16 @@ if [ ! $(echo "$STDIO_F_META_TIME > 0" | bc -l) ]; then ...@@ -57,6 +57,16 @@ if [ ! $(echo "$STDIO_F_META_TIME > 0" | bc -l) ]; then
echo "Error: counter is incorrect" 1>&2 echo "Error: counter is incorrect" 1>&2
exit 1 exit 1
fi fi
STDIO_F_CLOSE_START_TIMESTAMP=`grep STDIO_F_CLOSE_START_TIMESTAMP $DARSHAN_TMP/${PROG}.darshan.txt |tail -n 1 |cut -f 5`
if [ ! $(echo "$STDIO_F_CLOSE_START_TIMESTAMP > 0" | bc -l) ]; then
echo "Error: counter is incorrect" 1>&2
exit 1
fi
STDIO_F_CLOSE_END_TIMESTAMP=`grep STDIO_F_CLOSE_END_TIMESTAMP $DARSHAN_TMP/${PROG}.darshan.txt |tail -n 1 |cut -f 5`
if [ ! $(echo "$STDIO_F_CLOSE_END_TIMESTAMP > 0" | bc -l) ]; then
echo "Error: counter is incorrect" 1>&2
exit 1
fi
exit 0 exit 0
...@@ -146,6 +146,8 @@ static void darshan_log_print_stdio_description() ...@@ -146,6 +146,8 @@ static void darshan_log_print_stdio_description()
printf("# STDIO_FOPENS: number of 'fopen' function calls.\n"); printf("# STDIO_FOPENS: number of 'fopen' function calls.\n");
printf("# STDIO_F_OPEN_START_TIMESTAMP: timestamp of the first call to function 'fopen'.\n"); printf("# STDIO_F_OPEN_START_TIMESTAMP: timestamp of the first call to function 'fopen'.\n");
printf("# STDIO_F_OPEN_END_TIMESTAMP: timestamp of the completion of the last call to 'fopen'.\n"); printf("# STDIO_F_OPEN_END_TIMESTAMP: timestamp of the completion of the last call to 'fopen'.\n");
printf("# STDIO_F_CLOSE_START_TIMESTAMP: timestamp of the first call to function 'fclose'.\n");
printf("# STDIO_F_CLOSE_END_TIMESTAMP: timestamp of the completion of the last call to 'fclose'.\n");
printf("# STDIO_F_META_TIME: cumulative time spent in metadata operations.\n"); printf("# STDIO_F_META_TIME: cumulative time spent in metadata operations.\n");
return; return;
......
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