[Darshan-commits] [Git][darshan/darshan][dev-stdio] move fwrite wrapper to stdio module

Philip Carns xgitlab at cels.anl.gov
Sun May 1 08:51:20 CDT 2016


Philip Carns pushed to branch dev-stdio at darshan / darshan


Commits:
7e1b6e91 by Phil Carns at 2016-05-01T09:51:05-04:00
move fwrite wrapper to stdio module

- - - - -


8 changed files:

- darshan-runtime/lib/darshan-posix.c
- darshan-runtime/lib/darshan-stdio.c
- darshan-runtime/share/ld-opts/darshan-posix-ld-opts
- darshan-runtime/share/ld-opts/darshan-stdio-ld-opts
- darshan-stdio-log-format.h
- darshan-test/regression/test-cases/src/stdio-test.c
- darshan-test/regression/test-cases/stdio-test.sh
- darshan-util/darshan-stdio-logutils.c


Changes:

=====================================
darshan-runtime/lib/darshan-posix.c
=====================================
--- a/darshan-runtime/lib/darshan-posix.c
+++ b/darshan-runtime/lib/darshan-posix.c
@@ -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;


=====================================
darshan-runtime/lib/darshan-stdio.c
=====================================
--- a/darshan-runtime/lib/darshan-stdio.c
+++ b/darshan-runtime/lib/darshan-stdio.c
@@ -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 *
  **********************************************************/


=====================================
darshan-runtime/share/ld-opts/darshan-posix-ld-opts
=====================================
--- a/darshan-runtime/share/ld-opts/darshan-posix-ld-opts
+++ b/darshan-runtime/share/ld-opts/darshan-posix-ld-opts
@@ -15,7 +15,6 @@
 --wrap=readv
 --wrap=writev
 --wrap=fread
---wrap=fwrite
 --wrap=lseek
 --wrap=lseek64
 --wrap=fseek


=====================================
darshan-runtime/share/ld-opts/darshan-stdio-ld-opts
=====================================
--- a/darshan-runtime/share/ld-opts/darshan-stdio-ld-opts
+++ b/darshan-runtime/share/ld-opts/darshan-stdio-ld-opts
@@ -2,3 +2,4 @@
 --wrap=fopen
 --wrap=fopen64
 --wrap=fclose
+--wrap=fwrite


=====================================
darshan-stdio-log-format.h
=====================================
--- a/darshan-stdio-log-format.h
+++ b/darshan-stdio-log-format.h
@@ -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


=====================================
darshan-test/regression/test-cases/src/stdio-test.c
=====================================
--- a/darshan-test/regression/test-cases/src/stdio-test.c
+++ b/darshan-test/regression/test-cases/src/stdio-test.c
@@ -50,6 +50,9 @@ int main(int argc, char **argv)
       return(-1);
    }
 
+   if(mynod == 0)
+      fwrite("hello", 1, 6, file);
+
    fclose(file);
 
    MPI_Finalize();


=====================================
darshan-test/regression/test-cases/stdio-test.sh
=====================================
--- a/darshan-test/regression/test-cases/stdio-test.sh
+++ b/darshan-test/regression/test-cases/stdio-test.sh
@@ -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


=====================================
darshan-util/darshan-stdio-logutils.c
=====================================
--- a/darshan-util/darshan-stdio-logutils.c
+++ b/darshan-util/darshan-stdio-logutils.c
@@ -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;
 }



View it on GitLab: https://xgitlab.cels.anl.gov/darshan/darshan/commit/7e1b6e9135f92b73d5fdd0cc8bdad42162f18b32
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/darshan-commits/attachments/20160501/325887bd/attachment-0001.html>


More information about the Darshan-commits mailing list