[Darshan-commits] [Git][darshan/darshan][dev-stdio] fflush wrapper

Philip Carns xgitlab at cels.anl.gov
Mon May 23 19:50:12 CDT 2016


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


Commits:
9781671b by Phil Carns at 2016-05-23T20:50:05-04:00
fflush wrapper

- - - - -


4 changed files:

- darshan-runtime/lib/darshan-stdio.c
- darshan-runtime/share/ld-opts/darshan-stdio-ld-opts
- darshan-stdio-log-format.h
- darshan-util/darshan-stdio-logutils.c


Changes:

=====================================
darshan-runtime/lib/darshan-stdio.c
=====================================
--- a/darshan-runtime/lib/darshan-stdio.c
+++ b/darshan-runtime/lib/darshan-stdio.c
@@ -32,7 +32,7 @@
  *
  * functions for flushing streams
  * --------------
- * int      fflush(FILE *);
+ * int      fflush(FILE *);                                 DONE
  *
  * functions for reading data
  * --------------
@@ -96,6 +96,7 @@ DARSHAN_FORWARD_DECL(fopen64, FILE*, (const char *path, const char *mode));
 DARSHAN_FORWARD_DECL(fdopen, FILE*, (int fd, const char *mode));
 DARSHAN_FORWARD_DECL(freopen, FILE*, (const char *path, const char *mode, FILE *stream));
 DARSHAN_FORWARD_DECL(fclose, int, (FILE *fp));
+DARSHAN_FORWARD_DECL(fflush, 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));
 DARSHAN_FORWARD_DECL(fseek, int, (FILE *stream, long offset, int whence));
@@ -238,7 +239,7 @@ static void stdio_shutdown(void);
     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{ \
+#define STDIO_RECORD_WRITE(__fp, __bytes,  __tm1, __tm2, __fflush_flag) do{ \
     int64_t this_offset; \
     struct stdio_file_runtime* file; \
     file = stdio_file_by_stream(__fp); \
@@ -248,7 +249,10 @@ static void stdio_shutdown(void);
     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(__fflush_flag) \
+        file->file_record->counters[STDIO_FLUSHES] += 1; \
+    else \
+        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; \
@@ -332,6 +336,26 @@ FILE* DARSHAN_DECL(freopen)(const char *path, const char *mode, FILE *stream)
     return(ret);
 }
 
+int DARSHAN_DECL(fflush)(FILE *fp)
+{
+    double tm1, tm2;
+    int ret;
+
+    MAP_OR_FAIL(fflush);
+
+    tm1 = darshan_core_wtime();
+    ret = __real_fflush(fp);
+    tm2 = darshan_core_wtime();
+
+    STDIO_LOCK();
+    stdio_runtime_initialize();
+    if(ret >= 0)
+        STDIO_RECORD_WRITE(fp, 0, tm1, tm2, 1);
+    STDIO_UNLOCK();
+
+    return(ret);
+}
+
 int DARSHAN_DECL(fclose)(FILE *fp)
 {
     struct stdio_file_runtime* file;
@@ -377,7 +401,7 @@ size_t DARSHAN_DECL(fwrite)(const void *ptr, size_t size, size_t nmemb, FILE *st
     STDIO_LOCK();
     stdio_runtime_initialize();
     if(ret > 0)
-        STDIO_RECORD_WRITE(stream, size*ret, tm1, tm2);
+        STDIO_RECORD_WRITE(stream, size*ret, tm1, tm2, 0);
     STDIO_UNLOCK();
 
     return(ret);


=====================================
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
@@ -3,6 +3,7 @@
 --wrap=fopen64
 --wrap=fdopen
 --wrap=freopen
+--wrap=fflush
 --wrap=fclose
 --wrap=fwrite
 --wrap=fread


=====================================
darshan-stdio-log-format.h
=====================================
--- a/darshan-stdio-log-format.h
+++ b/darshan-stdio-log-format.h
@@ -27,6 +27,8 @@
     X(STDIO_READS) \
     /* count of seeks */\
     X(STDIO_SEEKS) \
+    /* count of flushes */\
+    X(STDIO_FLUSHES) \
     /* end of counters */\
     X(STDIO_NUM_INDICES)
 


=====================================
darshan-util/darshan-stdio-logutils.c
=====================================
--- a/darshan-util/darshan-stdio-logutils.c
+++ b/darshan-util/darshan-stdio-logutils.c
@@ -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|READS|SEEKS} are types of operations.\n");
+    printf("#   STDIO_{OPENS|WRITES|READS|SEEKS|FLUSHES} 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");



View it on GitLab: https://xgitlab.cels.anl.gov/darshan/darshan/commit/9781671bd804abde8a89f0d3dbedb8950092b8c1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/darshan-commits/attachments/20160523/6b0b82d9/attachment.html>


More information about the Darshan-commits mailing list