[Darshan-commits] [Git][darshan/darshan][fileno-wrapping] 4 commits: only throwout empty stdin, stdout, stderr stdio recs

Shane Snyder xgitlab at cels.anl.gov
Wed Dec 5 16:17:04 CST 2018


Shane Snyder pushed to branch fileno-wrapping at darshan / darshan


Commits:
e0bc4a1a by Shane Snyder at 2018-12-05T20:36:02Z
only throwout empty stdin,stdout,stderr stdio recs

- - - - -
4d0c757c by Shane Snyder at 2018-12-05T22:15:00Z
add function to query name associated with recid

- - - - -
abdf2094 by Shane Snyder at 2018-12-05T22:16:29Z
add posix function for registering new fd

- - - - -
5afac01b by Shane Snyder at 2018-12-05T22:16:43Z
wrap fileno in stdio module, forward fd to posix

- - - - -


5 changed files:

- darshan-runtime/darshan.h
- darshan-runtime/lib/darshan-core.c
- darshan-runtime/lib/darshan-posix.c
- darshan-runtime/lib/darshan-stdio.c
- darshan-runtime/share/ld-opts/darshan-stdio-ld-opts


Changes:

=====================================
darshan-runtime/darshan.h
=====================================
@@ -178,6 +178,14 @@ void *darshan_core_register_record(
     int rec_len,
     struct darshan_fs_info *fs_info);
 
+
+/* darshan_core_lookup_record_name()
+ *
+ * Looks up the name associated with a given Darshan record ID.
+ */
+char *darshan_core_lookup_record_name(
+    darshan_record_id rec_id);
+
 /* darshan_core_wtime()
  *
  * Returns the elapsed time relative to (roughly) the start of


=====================================
darshan-runtime/lib/darshan-core.c
=====================================
@@ -2107,6 +2107,21 @@ void *darshan_core_register_record(
     return(rec_buf);;
 }
 
+char *darshan_core_lookup_record_name(darshan_record_id rec_id)
+{
+    struct darshan_core_name_record_ref *ref;
+    char *name = NULL;
+
+    DARSHAN_CORE_LOCK();
+    HASH_FIND(hlink, darshan_core->name_hash, &rec_id,
+        sizeof(darshan_record_id), ref);
+    if(ref)
+        name = ref->name_record->name;
+    DARSHAN_CORE_UNLOCK();
+
+    return(name);
+}
+
 void darshan_instrument_fs_data(int fs_type, const char *path, int fd)
 {
 #ifdef DARSHAN_LUSTRE


=====================================
darshan-runtime/lib/darshan-posix.c
=====================================
@@ -166,6 +166,10 @@ extern void dxt_posix_write(darshan_record_id rec_id, int64_t offset,
 extern void dxt_posix_read(darshan_record_id rec_id, int64_t offset,
     int64_t length, double start_time, double end_time);
 
+/* function for registering a newly opened file descriptor with the POSIX module */
+int darshan_posix_add_open_fd(int fd, char *rec_name, int64_t counter,
+    double tm1, double tm2);
+
 static struct posix_runtime *posix_runtime = NULL;
 static pthread_mutex_t posix_runtime_mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
 static int my_rank = -1;
@@ -1426,6 +1430,20 @@ static void posix_aio_tracker_add(int fd, void *aiocbp)
     return;
 }
 
+int darshan_posix_add_open_fd(int fd, char *rec_name, int64_t counter,
+    double tm1, double tm2)
+{
+    struct posix_file_record_ref *rec_ref;
+    int ret = 0;
+
+    POSIX_PRE_RECORD();
+    POSIX_RECORD_OPEN(fd, rec_name, 0, tm1, tm2);
+    /* XXX */
+    POSIX_POST_RECORD();
+
+    return(ret);
+}
+
 static void posix_finalize_file_records(void *rec_ref_p)
 {
     struct posix_file_record_ref *rec_ref =


=====================================
darshan-runtime/lib/darshan-stdio.c
=====================================
@@ -118,6 +118,7 @@ DARSHAN_FORWARD_DECL(fseeko64, int, (FILE *stream, off64_t offset, int whence));
 DARSHAN_FORWARD_DECL(fsetpos, int, (FILE *stream, const fpos_t *pos));
 DARSHAN_FORWARD_DECL(fsetpos64, int, (FILE *stream, const fpos64_t *pos));
 DARSHAN_FORWARD_DECL(rewind, void, (FILE *stream));
+DARSHAN_FORWARD_DECL(fileno, int, (FILE *stream));
 
 /* structure to track stdio stats at runtime */
 struct stdio_file_record_ref
@@ -162,6 +163,12 @@ static struct stdio_file_record_ref *stdio_track_new_file_record(
     darshan_record_id rec_id, const char *path);
 static void stdio_cleanup_runtime();
 
+/* external prototype from POSIX module used to register new POSIX file
+ * records corresponding to file descriptors returned by STDIO fileno()
+ */
+extern int darshan_posix_add_open_fd(int fd, char *rec_name, int64_t counter,
+    double tm1, double tm2);
+
 #define STDIO_LOCK() pthread_mutex_lock(&stdio_runtime_mutex)
 #define STDIO_UNLOCK() pthread_mutex_unlock(&stdio_runtime_mutex)
 
@@ -184,6 +191,7 @@ static void stdio_cleanup_runtime();
     struct stdio_file_record_ref* rec_ref; \
     char *newpath; \
     int __fd; \
+    MAP_OR_FAIL(fileno); \
     if(__ret == NULL) break; \
     newpath = darshan_clean_file_path(__path); \
     if(!newpath) newpath = (char*)__path; \
@@ -206,7 +214,7 @@ static void stdio_cleanup_runtime();
     rec_ref->file_rec->fcounters[STDIO_F_OPEN_END_TIMESTAMP] = __tm2; \
     DARSHAN_TIMER_INC_NO_OVERLAP(rec_ref->file_rec->fcounters[STDIO_F_META_TIME], __tm1, __tm2, rec_ref->last_meta_end); \
     darshan_add_record_ref(&(stdio_runtime->stream_hash), &(__ret), sizeof(__ret), rec_ref); \
-    __fd = fileno(__ret); \
+    __fd = __real_fileno(__ret); \
     darshan_instrument_fs_data(rec_ref->fs_type, newpath, __fd); \
     if(newpath != (char*)__path) free(newpath); \
 } while(0)
@@ -949,6 +957,34 @@ int DARSHAN_DECL(fsetpos64)(FILE *stream, const fpos64_t *pos)
     return(ret);
 }
 
+int DARSHAN_DECL(fileno)(FILE *stream)
+{
+    int ret;
+    struct stdio_file_record_ref *rec_ref;
+    double tm1, tm2;
+
+    MAP_OR_FAIL(fileno);
+
+    tm1 = darshan_core_wtime();
+    ret = __real_fileno(stream);
+    tm2 = darshan_core_wtime();
+
+    if(ret >= 0)
+    {
+        STDIO_PRE_RECORD();
+        rec_ref = darshan_lookup_record_ref(stdio_runtime->stream_hash, &stream, sizeof(stream));
+        if(rec_ref)
+        {
+            char *rec_name = darshan_core_lookup_record_name(
+                rec_ref->file_rec->base_rec.id);
+            /* register this new FD with the POSIX module so we can track it */
+            darshan_posix_add_open_fd(ret, rec_name, 00, tm1, tm2);
+        }
+        STDIO_POST_RECORD();
+    }
+
+    return(ret);
+}
 
 /**********************************************************
  * Internal functions for manipulating STDIO module state *
@@ -1228,18 +1264,26 @@ static void stdio_shutdown(
      * logic above has likely broken the mapping to the static array.
      * We walk it manually here instead.
      */
+    darshan_record_id stdin_rec_id = darshan_core_gen_record_id("<STDIN>");
+    darshan_record_id stdout_rec_id = darshan_core_gen_record_id("<STDOUT>");
+    darshan_record_id stderr_rec_id = darshan_core_gen_record_id("<STDERR>");
     for(i=0; i<stdio_rec_count; i++)
     {
-        if(stdio_rec_buf[i].counters[STDIO_WRITES] == 0 &&
-            stdio_rec_buf[i].counters[STDIO_READS] == 0)
+        if((stdio_rec_buf[i].base_rec.id == stdin_rec_id) ||
+           (stdio_rec_buf[i].base_rec.id == stdout_rec_id) ||
+           (stdio_rec_buf[i].base_rec.id == stderr_rec_id))
         {
-            if(i != (stdio_rec_count-1))
+            if(stdio_rec_buf[i].counters[STDIO_WRITES] == 0 &&
+                stdio_rec_buf[i].counters[STDIO_READS] == 0)
             {
-                memmove(&stdio_rec_buf[i], &stdio_rec_buf[i+1],
-                    (stdio_rec_count-i-1)*sizeof(stdio_rec_buf[i]));
-                i--;
+                if(i != (stdio_rec_count-1))
+                {
+                    memmove(&stdio_rec_buf[i], &stdio_rec_buf[i+1],
+                        (stdio_rec_count-i-1)*sizeof(stdio_rec_buf[i]));
+                    i--;
+                }
+                stdio_rec_count--;
             }
-            stdio_rec_count--;
         }
     }
 


=====================================
darshan-runtime/share/ld-opts/darshan-stdio-ld-opts
=====================================
@@ -29,3 +29,4 @@
 --wrap=rewind
 --wrap=__isoc99_fscanf
 --wrap=printf
+--wrap=fileno



View it on GitLab: https://xgitlab.cels.anl.gov/darshan/darshan/compare/a658ce005608c573bab26ff73078c4c03cb5e05e...5afac01b8f6381add9bbad4709c8ff40c8a390ce

-- 
View it on GitLab: https://xgitlab.cels.anl.gov/darshan/darshan/compare/a658ce005608c573bab26ff73078c4c03cb5e05e...5afac01b8f6381add9bbad4709c8ff40c8a390ce
You're receiving this email because of your account on xgitlab.cels.anl.gov.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/darshan-commits/attachments/20181205/15b9cdb4/attachment-0001.html>


More information about the Darshan-commits mailing list