Commit 7e1b6e91 authored by Philip Carns's avatar Philip Carns

move fwrite wrapper to stdio module

parent 107937f1
......@@ -56,7 +56,6 @@ DARSHAN_FORWARD_DECL(pwrite64, ssize_t, (int fd, const void *buf, size_t count,
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(fwrite, size_t, (const 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));
......@@ -756,37 +755,6 @@ size_t DARSHAN_DECL(fread)(void *ptr, size_t size, size_t nmemb, FILE *stream)
return(ret);
}
size_t DARSHAN_DECL(fwrite)(const void *ptr, size_t size, size_t nmemb, FILE *stream)
{
size_t ret;
int aligned_flag = 0;
double tm1, tm2;
MAP_OR_FAIL(fwrite);
if((unsigned long)ptr % darshan_mem_alignment == 0) aligned_flag = 1;
tm1 = darshan_core_wtime();
ret = __real_fwrite(ptr, size, nmemb, stream);
tm2 = darshan_core_wtime();
POSIX_LOCK();
posix_runtime_initialize();
if(ret > 0)
{
POSIX_RECORD_WRITE(size*ret, fileno(stream), 0, 0,
aligned_flag, 1, tm1, tm2);
}
else
{
POSIX_RECORD_WRITE(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;
......
......@@ -34,6 +34,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));
/* The stdio_file_runtime structure maintains necessary runtime metadata
* for the STDIO file record (darshan_stdio_record structure, defined in
......@@ -154,7 +155,7 @@ static void stdio_shutdown(void);
file->offset = 0; \
file->last_byte_written = 0; \
file->last_byte_read = 0; \
file->file_record->counters[STDIO_FOPENS] += 1; \
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) \
file->file_record->fcounters[STDIO_F_OPEN_START_TIMESTAMP] = __tm1; \
......@@ -163,6 +164,28 @@ static void stdio_shutdown(void);
} while(0)
/* TODO: fix write start timestamp and read start timestamp logic in other
* modules
*/
#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); \
file->file_record->counters[STDIO_BYTES_WRITTEN] += __bytes; \
file->file_record->counters[STDIO_WRITES] += 1; \
if(file->file_record->fcounters[STDIO_F_WRITE_START_TIMESTAMP] == 0 || \
file->file_record->fcounters[STDIO_F_WRITE_START_TIMESTAMP] > __tm1) \
file->file_record->fcounters[STDIO_F_WRITE_START_TIMESTAMP] = __tm1; \
file->file_record->fcounters[STDIO_F_WRITE_END_TIMESTAMP] = __tm2; \
DARSHAN_TIMER_INC_NO_OVERLAP(file->file_record->fcounters[STDIO_F_WRITE_TIME], __tm1, __tm2, file->last_write_end); \
} while(0)
FILE* DARSHAN_DECL(fopen)(const char *path, const char *mode)
{
......@@ -235,6 +258,26 @@ int DARSHAN_DECL(fclose)(FILE *fp)
return(ret);
}
size_t DARSHAN_DECL(fwrite)(const void *ptr, size_t size, size_t nmemb, FILE *stream)
{
size_t ret;
double tm1, tm2;
MAP_OR_FAIL(fwrite);
tm1 = darshan_core_wtime();
ret = __real_fwrite(ptr, size, nmemb, stream);
tm2 = darshan_core_wtime();
STDIO_LOCK();
stdio_runtime_initialize();
if(ret > 0)
STDIO_RECORD_WRITE(stream, size*ret, tm1, tm2);
STDIO_UNLOCK();
return(ret);
}
/**********************************************************
* Internal functions for manipulating STDIO module state *
**********************************************************/
......
......@@ -15,7 +15,6 @@
--wrap=readv
--wrap=writev
--wrap=fread
--wrap=fwrite
--wrap=lseek
--wrap=lseek64
--wrap=fseek
......
......@@ -2,3 +2,4 @@
--wrap=fopen
--wrap=fopen64
--wrap=fclose
--wrap=fwrite
......@@ -40,7 +40,7 @@
* int fprintf(FILE *, const char *, ...);
* int fputc(int, FILE *);
* int fputs(const char *, FILE *);
* size_t fwrite(const void *, size_t, size_t, FILE *);
* size_t fwrite(const void *, size_t, size_t, FILE *); DONE
* int putc(int, FILE *);
* int putc_unlocked(int, FILE *);
* int putw(int, FILE *);
......@@ -57,7 +57,13 @@
#define STDIO_COUNTERS \
/* count of fopens */\
X(STDIO_FOPENS) \
X(STDIO_OPENS) \
/* maximum byte (offset) written */\
X(STDIO_MAX_BYTE_WRITTEN) \
/* total bytes written */ \
X(STDIO_BYTES_WRITTEN) \
/* number of writes */ \
X(STDIO_WRITES) \
/* end of counters */\
X(STDIO_NUM_INDICES)
......@@ -70,19 +76,25 @@
X(STDIO_F_CLOSE_START_TIMESTAMP) \
/* timestamp of last close completion */\
X(STDIO_F_CLOSE_END_TIMESTAMP) \
/* timestamp of first write */\
X(STDIO_F_WRITE_START_TIMESTAMP) \
/* timestamp of last write completion */\
X(STDIO_F_WRITE_END_TIMESTAMP) \
/* cumulative meta time */\
X(STDIO_F_META_TIME) \
/* cumulative write time */\
X(STDIO_F_WRITE_TIME) \
/* end of counters */\
X(STDIO_F_NUM_INDICES)
#define X(a) a,
/* integer counters for the "STDIO" example module */
/* integer counters for the "STDIO" module */
enum darshan_stdio_indices
{
STDIO_COUNTERS
};
/* floating point counters for the "STDIO" example module */
/* floating point counters for the "STDIO" module */
enum darshan_stdio_f_indices
{
STDIO_F_COUNTERS
......
......@@ -50,6 +50,9 @@ int main(int argc, char **argv)
return(-1);
}
if(mynod == 0)
fwrite("hello", 1, 6, file);
fclose(file);
MPI_Finalize();
......
......@@ -27,42 +27,53 @@ if [ $? -ne 0 ]; then
exit 1
fi
# TODO: look for "tail" commands in all of these test cases and remove them
# TODO: look for "head" commands in all of these test cases and remove them
# later. Right now they are needed to make sure we only check 1 out of 4
# possible records because reduction is not implemented yet
# check results
# in this case we want to confirm that the STDIO counters were triggered
STDIO_OPENS=`grep STDIO_FOPENS $DARSHAN_TMP/${PROG}.darshan.txt |tail -n 1 |cut -f 5`
STDIO_OPENS=`grep STDIO_OPENS $DARSHAN_TMP/${PROG}.darshan.txt |head -n 1 |cut -f 5`
if [ ! "$STDIO_OPENS" -gt 0 ]; then
echo "Error: STDIO open count of $STDIO_FOPENS is incorrect" 1>&2
echo "Error: STDIO open count of $STDIO_OPENS is incorrect" 1>&2
exit 1
fi
STDIO_BYTES_WRITTEN=`grep STDIO_BYTES_WRITTEN $DARSHAN_TMP/${PROG}.darshan.txt |head -n 1 |cut -f 5`
if [ ! "$STDIO_BYTES_WRITTEN" -eq 6 ]; then
echo "Error: STDIO open count of $STDIO_BYTES_WRITTEN is incorrect" 1>&2
exit 1
fi
# make sure that some of the floating point counters are valid
# use bc for floating point comparison
STDIO_F_OPEN_START_TIMESTAMP=`grep STDIO_F_OPEN_START_TIMESTAMP $DARSHAN_TMP/${PROG}.darshan.txt |tail -n 1 |cut -f 5`
STDIO_F_OPEN_START_TIMESTAMP=`grep STDIO_F_OPEN_START_TIMESTAMP $DARSHAN_TMP/${PROG}.darshan.txt |head -n 1 |cut -f 5`
if [ ! $(echo "$STDIO_F_OPEN_START_TIMESTAMP > 0" | bc -l) ]; then
echo "Error: counter is incorrect" 1>&2
exit 1
fi
STDIO_F_OPEN_END_TIMESTAMP=`grep STDIO_F_OPEN_END_TIMESTAMP $DARSHAN_TMP/${PROG}.darshan.txt |tail -n 1 |cut -f 5`
STDIO_F_OPEN_END_TIMESTAMP=`grep STDIO_F_OPEN_END_TIMESTAMP $DARSHAN_TMP/${PROG}.darshan.txt |head -n 1 |cut -f 5`
if [ ! $(echo "$STDIO_F_OPEN_END_TIMESTAMP > 0" | bc -l) ]; then
echo "Error: counter is incorrect" 1>&2
exit 1
fi
STDIO_F_META_TIME=`grep STDIO_F_META_TIME $DARSHAN_TMP/${PROG}.darshan.txt |tail -n 1 |cut -f 5`
STDIO_F_META_TIME=`grep STDIO_F_META_TIME $DARSHAN_TMP/${PROG}.darshan.txt |head -n 1 |cut -f 5`
if [ ! $(echo "$STDIO_F_META_TIME > 0" | bc -l) ]; then
echo "Error: counter is incorrect" 1>&2
exit 1
fi
STDIO_F_CLOSE_START_TIMESTAMP=`grep STDIO_F_CLOSE_START_TIMESTAMP $DARSHAN_TMP/${PROG}.darshan.txt |tail -n 1 |cut -f 5`
STDIO_F_WRITE_TIME=`grep STDIO_F_WRITE_TIME $DARSHAN_TMP/${PROG}.darshan.txt |head -n 1 |cut -f 5`
if [ ! $(echo "$STDIO_F_WRITE_TIME > 0" | bc -l) ]; then
echo "Error: counter is incorrect" 1>&2
exit 1
fi
STDIO_F_CLOSE_START_TIMESTAMP=`grep STDIO_F_CLOSE_START_TIMESTAMP $DARSHAN_TMP/${PROG}.darshan.txt |head -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`
STDIO_F_CLOSE_END_TIMESTAMP=`grep STDIO_F_CLOSE_END_TIMESTAMP $DARSHAN_TMP/${PROG}.darshan.txt |head -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
......
......@@ -143,12 +143,12 @@ 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_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_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_{OPENS|WRITES} 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");
printf("# STDIO_F_*_END_TIMESTAMP: timestamp of the completion of the last call to that type of function.\n");
printf("# STDIO_F_*_TIME: cumulative time spent in different types of functions.\n");
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