[Darshan-commits] [Git][darshan/darshan][master] tracking stdout stderr and stdin

Philip Carns xgitlab at cels.anl.gov
Sat Aug 20 08:13:08 CDT 2016


Philip Carns pushed to branch master at darshan / darshan


Commits:
173d3d49 by Phil Carns at 2016-08-20T09:11:40-04:00
tracking stdout stderr and stdin

- - - - -


3 changed files:

- darshan-runtime/lib/darshan-common.c
- darshan-runtime/lib/darshan-stdio.c
- darshan-runtime/share/ld-opts/darshan-stdio-ld-opts


Changes:

=====================================
darshan-runtime/lib/darshan-common.c
=====================================
--- a/darshan-runtime/lib/darshan-common.c
+++ b/darshan-runtime/lib/darshan-common.c
@@ -126,7 +126,11 @@ char* darshan_clean_file_path(const char* path)
     char* cwd = NULL;
     char* filter = NULL;
 
-    if(!path || strlen(path) < 1)
+    /* NOTE: the last check in this if statement is for path strings that
+     * begin with the '<' character.  We assume that these are special
+     * reserved paths used by Darshan, like <STDIN>.
+     */
+    if(!path || strlen(path) < 1 || path[0] == '<')
         return(NULL);
 
     if(path[0] == '/')


=====================================
darshan-runtime/lib/darshan-stdio.c
=====================================
--- a/darshan-runtime/lib/darshan-stdio.c
+++ b/darshan-runtime/lib/darshan-stdio.c
@@ -94,7 +94,9 @@ DARSHAN_FORWARD_DECL(fputc, int, (int c, FILE *stream));
 DARSHAN_FORWARD_DECL(putw, int, (int w, FILE *stream));
 DARSHAN_FORWARD_DECL(fputs, int, (const char *s, FILE *stream));
 DARSHAN_FORWARD_DECL(fprintf, int, (FILE *stream, const char *format, ...));
+DARSHAN_FORWARD_DECL(printf, int, (const char *format, ...));
 DARSHAN_FORWARD_DECL(vfprintf, int, (FILE *stream, const char *format, va_list));
+DARSHAN_FORWARD_DECL(vprintf, int, (const char *format, va_list));
 DARSHAN_FORWARD_DECL(fread, size_t, (void *ptr, size_t size, size_t nmemb, FILE *stream));
 DARSHAN_FORWARD_DECL(fgetc, int, (FILE *stream));
 DARSHAN_FORWARD_DECL(getw, int, (FILE *stream));
@@ -463,6 +465,25 @@ int DARSHAN_DECL(fputs)(const char *s, FILE *stream)
     return(ret);
 }
 
+int DARSHAN_DECL(vprintf)(const char *format, va_list ap)
+{
+    int ret;
+    double tm1, tm2;
+
+    MAP_OR_FAIL(vprintf);
+
+    tm1 = darshan_core_wtime();
+    ret = __real_vprintf(format, ap);
+    tm2 = darshan_core_wtime();
+
+    STDIO_PRE_RECORD();
+    if(ret > 0)
+        STDIO_RECORD_WRITE(stdout, ret, tm1, tm2, 0);
+    STDIO_POST_RECORD();
+
+    return(ret);
+}
+
 int DARSHAN_DECL(vfprintf)(FILE *stream, const char *format, va_list ap)
 {
     int ret;
@@ -472,14 +493,38 @@ int DARSHAN_DECL(vfprintf)(FILE *stream, const char *format, va_list ap)
     MAP_OR_FAIL(vfprintf);
 
     tm1 = darshan_core_wtime();
-    start_off = ftell(stream);
     ret = __real_vfprintf(stream, format, ap);
-    end_off = ftell(stream);
     tm2 = darshan_core_wtime();
 
     STDIO_PRE_RECORD();
     if(ret > 0)
-        STDIO_RECORD_WRITE(stream, (end_off-start_off), tm1, tm2, 0);
+        STDIO_RECORD_WRITE(stream, ret, tm1, tm2, 0);
+    STDIO_POST_RECORD();
+
+    return(ret);
+}
+
+
+int DARSHAN_DECL(printf)(const char *format, ...)
+{
+    int ret;
+    double tm1, tm2;
+    va_list ap;
+
+    MAP_OR_FAIL(vprintf);
+
+    tm1 = darshan_core_wtime();
+    /* NOTE: we intentionally switch to vprintf here to handle the variable
+     * length arguments.
+     */
+    va_start(ap, format);
+    ret = __real_vprintf(format, ap);
+    va_end(ap);
+    tm2 = darshan_core_wtime();
+
+    STDIO_PRE_RECORD();
+    if(ret > 0)
+        STDIO_RECORD_WRITE(stdout, ret, tm1, tm2, 0);
     STDIO_POST_RECORD();
 
     return(ret);
@@ -491,7 +536,6 @@ int DARSHAN_DECL(fprintf)(FILE *stream, const char *format, ...)
     int ret;
     double tm1, tm2;
     va_list ap;
-    long start_off, end_off;
 
     MAP_OR_FAIL(vfprintf);
 
@@ -499,16 +543,14 @@ int DARSHAN_DECL(fprintf)(FILE *stream, const char *format, ...)
     /* NOTE: we intentionally switch to vfprintf here to handle the variable
      * length arguments.
      */
-    start_off = ftell(stream);
     va_start(ap, format);
     ret = __real_vfprintf(stream, format, ap);
     va_end(ap);
-    end_off = ftell(stream);
     tm2 = darshan_core_wtime();
 
     STDIO_PRE_RECORD();
     if(ret > 0)
-        STDIO_RECORD_WRITE(stream, (end_off-start_off), tm1, tm2, 0);
+        STDIO_RECORD_WRITE(stream, ret, tm1, tm2, 0);
     STDIO_POST_RECORD();
 
     return(ret);
@@ -939,6 +981,11 @@ static void stdio_runtime_initialize()
         return;
     }
     memset(stdio_runtime, 0, sizeof(*stdio_runtime));
+
+    /* instantiate records for stdin, stdout, and stderr */
+    STDIO_RECORD_OPEN(stdin, "<STDIN>", 0, 0);
+    STDIO_RECORD_OPEN(stdout, "<STDOUT>", 0, 0);
+    STDIO_RECORD_OPEN(stderr, "<STDERR>", 0, 0);
 }
 
 /************************************************************************


=====================================
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
@@ -20,6 +20,7 @@
 --wrap=fseeko64
 --wrap=fprintf
 --wrap=vfprintf
+--wrap=vprintf
 --wrap=fputc
 --wrap=fputs
 --wrap=putw
@@ -27,3 +28,4 @@
 --wrap=fsetpos64
 --wrap=rewind
 --wrap=__isoc99_fscanf
+--wrap=printf



View it on GitLab: https://xgitlab.cels.anl.gov/darshan/darshan/commit/173d3d49ba18ce4e0ca53e80b9f0a27b0cb8d3f2
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/darshan-commits/attachments/20160820/784e0f60/attachment-0001.html>


More information about the Darshan-commits mailing list