[Darshan-commits] [Git][darshan/darshan][master] 2 commits: allow logutils to optionally allocate record data

Shane Snyder xgitlab at cels.anl.gov
Mon Sep 19 18:47:11 CDT 2016


Shane Snyder pushed to branch master at darshan / darshan


Commits:
f21728f3 by Shane Snyder at 2016-09-19T18:42:49-05:00
allow logutils to optionally allocate record data

also, bug fix to avoid any attempt of reading log file for
modules with no data present in the log

- - - - -
ab32cf66 by Shane Snyder at 2016-09-19T18:42:49-05:00
port utilities to new log get record interface

- - - - -


14 changed files:

- darshan-util/darshan-analyzer.c
- darshan-util/darshan-bgq-logutils.c
- darshan-util/darshan-convert.c
- darshan-util/darshan-diff.c
- darshan-util/darshan-hdf5-logutils.c
- darshan-util/darshan-logutils.h
- darshan-util/darshan-lustre-logutils.c
- darshan-util/darshan-merge.c
- darshan-util/darshan-mpiio-logutils.c
- darshan-util/darshan-null-logutils.c
- darshan-util/darshan-parser.c
- darshan-util/darshan-pnetcdf-logutils.c
- darshan-util/darshan-posix-logutils.c
- darshan-util/darshan-stdio-logutils.c


Changes:

=====================================
darshan-util/darshan-analyzer.c
=====================================
--- a/darshan-util/darshan-analyzer.c
+++ b/darshan-util/darshan-analyzer.c
@@ -38,12 +38,13 @@ int process_log(const char *fname, double *io_ratio, int *used_mpio, int *used_p
     struct darshan_job job;
     struct darshan_mod_logutil_funcs *psx_mod = mod_logutils[DARSHAN_POSIX_MOD];
     struct darshan_posix_file psx_rec;
+    void *psx_rec_p = &psx_rec;
     int f_count;
     double total_io_time;
     double total_job_time;
 
     assert(psx_mod);
-    memset(&psx_rec, 0, sizeof(struct darshan_posix_file));
+    memset(psx_rec_p, 0, sizeof(struct darshan_posix_file));
 
     file = darshan_log_open(fname);
     if (file == NULL)
@@ -63,7 +64,7 @@ int process_log(const char *fname, double *io_ratio, int *used_mpio, int *used_p
     f_count = 0;
     total_io_time = 0.0;
 
-    while((ret = psx_mod->log_get_record(file, &psx_rec)) == 1)
+    while((ret = psx_mod->log_get_record(file, &psx_rec_p)) == 1)
     {
         f_count   += 1;
 
@@ -76,7 +77,7 @@ int process_log(const char *fname, double *io_ratio, int *used_mpio, int *used_p
                          psx_rec.fcounters[POSIX_F_WRITE_TIME] +
                          psx_rec.fcounters[POSIX_F_META_TIME]);
 
-        memset(&psx_rec, 0, sizeof(struct darshan_posix_file));
+        memset(psx_rec_p, 0, sizeof(struct darshan_posix_file));
     }
     if (ret < 0)
     {


=====================================
darshan-util/darshan-bgq-logutils.c
=====================================
--- a/darshan-util/darshan-bgq-logutils.c
+++ b/darshan-util/darshan-bgq-logutils.c
@@ -34,7 +34,7 @@ char *bgq_f_counter_names[] = {
  */
 #define DARSHAN_BGQ_FILE_SIZE_1 (112 + 8)
 
-static int darshan_log_get_bgq_rec(darshan_fd fd, void* bgq_buf);
+static int darshan_log_get_bgq_rec(darshan_fd fd, void** bgq_buf_p);
 static int darshan_log_put_bgq_rec(darshan_fd fd, void* bgq_buf, int ver);
 static void darshan_log_print_bgq_rec(void *file_rec,
     char *file_name, char *mnt_pt, char *fs_type, int ver);
@@ -53,14 +53,24 @@ struct darshan_mod_logutil_funcs bgq_logutils =
     .log_agg_records = &darshan_log_agg_bgq_recs
 };
 
-static int darshan_log_get_bgq_rec(darshan_fd fd, void* bgq_buf)
+static int darshan_log_get_bgq_rec(darshan_fd fd, void** bgq_buf_p)
 {
-    struct darshan_bgq_record *rec = (struct darshan_bgq_record *)bgq_buf;
+    struct darshan_bgq_record *rec = *((struct darshan_bgq_record **)bgq_buf_p);
     int rec_len;
     char *buffer, *p;
     int i;
     int ret = -1;
 
+    if(fd->mod_map[DARSHAN_BGQ_MOD].len == 0)
+        return(0);
+
+    if(*bgq_buf_p == NULL)
+    {
+        rec = malloc(sizeof(*rec));
+        if(!rec)
+            return(-1);
+    }
+
     /* read the BGQ record from file, checking the version first so we
      * can read it correctly
      */
@@ -68,7 +78,11 @@ static int darshan_log_get_bgq_rec(darshan_fd fd, void* bgq_buf)
     {
         buffer = malloc(DARSHAN_BGQ_FILE_SIZE_1);
         if(!buffer)
+        {
+            if(*bgq_buf_p == NULL)
+                free(rec);
             return(-1);
+        }
 
         rec_len = DARSHAN_BGQ_FILE_SIZE_1;
         ret = darshan_log_get_mod(fd, DARSHAN_BGQ_MOD, buffer, rec_len);
@@ -93,6 +107,14 @@ static int darshan_log_get_bgq_rec(darshan_fd fd, void* bgq_buf)
         ret = darshan_log_get_mod(fd, DARSHAN_BGQ_MOD, rec, rec_len);
     }
 
+    if(*bgq_buf_p == NULL)
+    {
+        if(ret == rec_len)
+            *bgq_buf_p = rec;
+        else
+            free(rec);
+    }
+
     if(ret < 0)
         return(-1);
     else if(ret < rec_len)


=====================================
darshan-util/darshan-convert.c
=====================================
--- a/darshan-util/darshan-convert.c
+++ b/darshan-util/darshan-convert.c
@@ -258,7 +258,7 @@ int main(int argc, char **argv)
     struct darshan_mnt_info *mnt_data_array;
     struct darshan_name_record_ref *name_hash = NULL;
     struct darshan_name_record_ref *ref, *tmp;
-    char mod_buf[DEF_MOD_BUF_SIZE];
+    char *mod_buf;
     enum darshan_comp_type comp_type;
     int bzip2;
     int obfuscate;
@@ -363,6 +363,14 @@ int main(int argc, char **argv)
         return(-1);
     }
 
+    mod_buf = malloc(DEF_MOD_BUF_SIZE);
+    if(!mod_buf)
+    {
+        darshan_log_close(infile);
+        darshan_log_close(outfile);
+        return(-1);
+    }
+
     /* loop over each module and convert it's data to the new format */
     for(i=0; i<DARSHAN_MAX_MODS; i++)
     {
@@ -381,7 +389,7 @@ int main(int argc, char **argv)
         /* we have module data to convert */
         memset(mod_buf, 0, DEF_MOD_BUF_SIZE);
 
-        ret = mod_logutils[i]->log_get_record(infile, mod_buf);
+        ret = mod_logutils[i]->log_get_record(infile, (void **)&mod_buf);
         if(ret != 1)
         {
             fprintf(stderr, "Error: failed to parse the first %s module record.\n",
@@ -409,7 +417,7 @@ int main(int argc, char **argv)
 
                 memset(mod_buf, 0, DEF_MOD_BUF_SIZE);
             }
-        } while((ret = mod_logutils[i]->log_get_record(infile, mod_buf)) == 1);
+        } while((ret = mod_logutils[i]->log_get_record(infile, (void **)&mod_buf)) == 1);
     }
 
     darshan_log_close(infile);
@@ -425,6 +433,8 @@ int main(int argc, char **argv)
         free(ref);
     }
 
+    free(mod_buf);
+
     return(ret);
 }
 


=====================================
darshan-util/darshan-diff.c
=====================================
--- a/darshan-util/darshan-diff.c
+++ b/darshan-util/darshan-diff.c
@@ -16,7 +16,7 @@
 struct darshan_mod_record_ref
 {
     int rank;
-    char mod_dat[DEF_MOD_BUF_SIZE];
+    char *mod_dat;
     struct darshan_mod_record_ref *prev;
     struct darshan_mod_record_ref *next;
 };
@@ -269,6 +269,7 @@ int main(int argc, char *argv[])
                         mod_rec1->next->prev = mod_rec1->prev;
                         rec_ref1->mod_recs[i] = mod_rec1->next;
                     }
+                    free(mod_rec1->mod_dat);
                     free(mod_rec1);
                 }
                 if(mod_buf2)
@@ -283,6 +284,7 @@ int main(int argc, char *argv[])
                         mod_rec2->next->prev = mod_rec2->prev;
                         rec_ref2->mod_recs[i] = mod_rec2->next;
                     }
+                    free(mod_rec2->mod_dat);
                     free(mod_rec2);
                 }
             }
@@ -327,6 +329,7 @@ int main(int argc, char *argv[])
                     mod_rec2->next->prev = mod_rec2->prev;
                     rec_ref2->mod_recs[i] = mod_rec2->next;
                 }
+                free(mod_rec2->mod_dat);
                 free(mod_rec2);
             }
         }
@@ -377,16 +380,18 @@ static int darshan_build_global_record_hash(
             assert(mod_rec);
             memset(mod_rec, 0, sizeof(struct darshan_mod_record_ref));
 
-            ret = mod_logutils[i]->log_get_record(fd, mod_rec->mod_dat);
+            ret = mod_logutils[i]->log_get_record(fd, (void **)&(mod_rec->mod_dat));
             if(ret < 0)
             {
                 fprintf(stderr, "Error: unable to read module %s data from log file.\n",
                     darshan_module_names[i]);
+                free(mod_rec->mod_dat);
                 free(mod_rec);
                 return(-1);
             }
             else if(ret == 0)
             {
+                free(mod_rec->mod_dat);
                 free(mod_rec);
                 break;
             }


=====================================
darshan-util/darshan-hdf5-logutils.c
=====================================
--- a/darshan-util/darshan-hdf5-logutils.c
+++ b/darshan-util/darshan-hdf5-logutils.c
@@ -30,7 +30,7 @@ char *hdf5_f_counter_names[] = {
 };
 #undef X
 
-static int darshan_log_get_hdf5_file(darshan_fd fd, void* hdf5_buf);
+static int darshan_log_get_hdf5_file(darshan_fd fd, void** hdf5_buf_p);
 static int darshan_log_put_hdf5_file(darshan_fd fd, void* hdf5_buf, int ver);
 static void darshan_log_print_hdf5_file(void *file_rec,
     char *file_name, char *mnt_pt, char *fs_type, int ver);
@@ -49,24 +49,42 @@ struct darshan_mod_logutil_funcs hdf5_logutils =
     .log_agg_records = &darshan_log_agg_hdf5_files
 };
 
-static int darshan_log_get_hdf5_file(darshan_fd fd, void* hdf5_buf)
+static int darshan_log_get_hdf5_file(darshan_fd fd, void** hdf5_buf_p)
 {
-    struct darshan_hdf5_file *file;
+    struct darshan_hdf5_file *file = *((struct darshan_hdf5_file **)hdf5_buf_p);
     int i;
     int ret;
 
-    ret = darshan_log_get_mod(fd, DARSHAN_HDF5_MOD, hdf5_buf,
+    if(fd->mod_map[DARSHAN_HDF5_MOD].len == 0)
+        return(0);
+
+    if(*hdf5_buf_p == NULL)
+    {
+        file = malloc(sizeof(*file));
+        if(!file)
+            return(-1);
+    }
+
+    ret = darshan_log_get_mod(fd, DARSHAN_HDF5_MOD, file,
         sizeof(struct darshan_hdf5_file));
+
+    if(*hdf5_buf_p == NULL)
+    {
+        if(ret == sizeof(struct darshan_hdf5_file))
+            *hdf5_buf_p = file;
+        else
+            free(file);
+    }
+
     if(ret < 0)
         return(-1);
     else if(ret < sizeof(struct darshan_hdf5_file))
         return(0);
     else
     {
-        file = (struct darshan_hdf5_file *)hdf5_buf;
+        /* if the read was successful, do any necessary byte-swapping */
         if(fd->swap_flag)
         {
-            /* swap bytes if necessary */
             DARSHAN_BSWAP64(&(file->base_rec.id));
             DARSHAN_BSWAP64(&(file->base_rec.rank));
             for(i=0; i<HDF5_NUM_INDICES; i++)


=====================================
darshan-util/darshan-logutils.h
=====================================
--- a/darshan-util/darshan-logutils.h
+++ b/darshan-util/darshan-logutils.h
@@ -69,18 +69,18 @@ struct darshan_mod_logutil_funcs
      * return 1 on successful read of record, 0 on no more
      * module data, -1 on error
      *      - 'fd' is the file descriptor to get record from
-     *      - 'buf' is the buffer to store the record in
-     *      - 'rec_id' is the corresponding darshan record id
+     *      - 'buf' is a pointer to a buffer address to store the record in
+     *          * NOTE: if the buffer pointed to is NULL, the record memory is malloc'ed
      */
     int (*log_get_record)(
         darshan_fd fd,
-        void* buf
+        void** buf
     );
     /* put a single module record into the log file.
      * return 0 on success, -1 on error
      *      - 'fd' is the file descriptor to put record into
      *      - 'buf' is the buffer containing the record data
-     *      - 'rec_id' is the corresponding darshan record id
+     *      - 'ver' is the version of the record
      */
     int (*log_put_record)(
         darshan_fd fd,


=====================================
darshan-util/darshan-lustre-logutils.c
=====================================
--- a/darshan-util/darshan-lustre-logutils.c
+++ b/darshan-util/darshan-lustre-logutils.c
@@ -24,7 +24,7 @@ char *lustre_counter_names[] = {
 };
 #undef X
 
-static int darshan_log_get_lustre_record(darshan_fd fd, void* lustre_buf);
+static int darshan_log_get_lustre_record(darshan_fd fd, void** lustre_buf_p);
 static int darshan_log_put_lustre_record(darshan_fd fd, void* lustre_buf, int ver);
 static void darshan_log_print_lustre_record(void *file_rec,
     char *file_name, char *mnt_pt, char *fs_type, int ver);
@@ -41,21 +41,31 @@ struct darshan_mod_logutil_funcs lustre_logutils =
     .log_print_diff = &darshan_log_print_lustre_record_diff
 };
 
-static int darshan_log_get_lustre_record(darshan_fd fd, void* lustre_buf)
+static int darshan_log_get_lustre_record(darshan_fd fd, void** lustre_buf_p)
 {
-    struct darshan_lustre_record *rec;
+    struct darshan_lustre_record *rec = *((struct darshan_lustre_record **)lustre_buf_p);
+    struct darshan_lustre_record tmp_rec;
     int i;
     int ret;
 
+    if(fd->mod_map[DARSHAN_LUSTRE_MOD].len == 0)
+        return(0);
+
     /* retrieve the fixed-size portion of the record */
-    ret = darshan_log_get_mod(fd, DARSHAN_LUSTRE_MOD, lustre_buf,
+    ret = darshan_log_get_mod(fd, DARSHAN_LUSTRE_MOD, &tmp_rec,
         sizeof(struct darshan_lustre_record));
     if(ret < 0)
         return(-1);
     else if(ret < sizeof(struct darshan_lustre_record))
         return(0);
 
-    rec = (struct darshan_lustre_record *)lustre_buf;
+    if(*lustre_buf_p == NULL)
+    {
+        rec = malloc(LUSTRE_RECORD_SIZE(tmp_rec.counters[LUSTRE_STRIPE_WIDTH]));
+        if(!rec)
+            return(-1);
+    }
+    memcpy(rec, &tmp_rec, sizeof(struct darshan_lustre_record));
 
     /* swap bytes if necessary */
     if(fd->swap_flag)
@@ -76,16 +86,30 @@ static int darshan_log_get_lustre_record(darshan_fd fd, void* lustre_buf)
             (rec->counters[LUSTRE_STRIPE_WIDTH] - 1)*sizeof(OST_ID)
         );
         if(ret < 0)
-            return(-1);
+            ret = -1;
         else if(ret < (rec->counters[LUSTRE_STRIPE_WIDTH] - 1)*sizeof(OST_ID))
-            return(0);
+            ret = 0;
+        else
+            ret = 1;
         /* swap bytes if necessary */
         if ( fd->swap_flag )
             for (i = 1; i < rec->counters[LUSTRE_STRIPE_WIDTH]; i++ )
                 DARSHAN_BSWAP64(&(rec->ost_ids[i]));
     }
+    else
+    {
+        ret = 1;
+    }
+
+    if(*lustre_buf_p == NULL)
+    {
+        if(ret == 1)
+            *lustre_buf_p = rec;
+        else
+            free(rec);
+    }
 
-    return(1);
+    return(ret);
 }
 
 static int darshan_log_put_lustre_record(darshan_fd fd, void* lustre_buf, int ver)


=====================================
darshan-util/darshan-merge.c
=====================================
--- a/darshan-util/darshan-merge.c
+++ b/darshan-util/darshan-merge.c
@@ -109,7 +109,7 @@ int build_mod_shared_rec_hash(char **infile_list, int n_infiles,
             return(-1);
         }
 
-        while((ret = mod_logutils[mod_id]->log_get_record(in_fd, mod_buf)) == 1)
+        while((ret = mod_logutils[mod_id]->log_get_record(in_fd, (void **)&mod_buf)) == 1)
         {
             base_rec = (struct darshan_base_record *)mod_buf;
             if(init_rank == -1)
@@ -422,7 +422,7 @@ int main(int argc, char *argv[])
             }
 
             /* loop over module records and write them to output file */
-            while((ret = mod_logutils[i]->log_get_record(in_fd, mod_buf)) == 1)
+            while((ret = mod_logutils[i]->log_get_record(in_fd, (void **)&mod_buf)) == 1)
             {
                 base_rec = (struct darshan_base_record *)mod_buf;
 


=====================================
darshan-util/darshan-mpiio-logutils.c
=====================================
--- a/darshan-util/darshan-mpiio-logutils.c
+++ b/darshan-util/darshan-mpiio-logutils.c
@@ -30,7 +30,7 @@ char *mpiio_f_counter_names[] = {
 };
 #undef X
 
-static int darshan_log_get_mpiio_file(darshan_fd fd, void* mpiio_buf);
+static int darshan_log_get_mpiio_file(darshan_fd fd, void** mpiio_buf_p);
 static int darshan_log_put_mpiio_file(darshan_fd fd, void* mpiio_buf, int ver);
 static void darshan_log_print_mpiio_file(void *file_rec,
     char *file_name, char *mnt_pt, char *fs_type, int ver);
@@ -49,24 +49,42 @@ struct darshan_mod_logutil_funcs mpiio_logutils =
     .log_agg_records = &darshan_log_agg_mpiio_files
 };
 
-static int darshan_log_get_mpiio_file(darshan_fd fd, void* mpiio_buf)
+static int darshan_log_get_mpiio_file(darshan_fd fd, void** mpiio_buf_p)
 {
-    struct darshan_mpiio_file *file;
+    struct darshan_mpiio_file *file = *((struct darshan_mpiio_file **)mpiio_buf_p);
     int i;
     int ret;
 
-    ret = darshan_log_get_mod(fd, DARSHAN_MPIIO_MOD, mpiio_buf,
+    if(fd->mod_map[DARSHAN_MPIIO_MOD].len == 0)
+        return(0);
+
+    if(*mpiio_buf_p == NULL)
+    {
+        file = malloc(sizeof(*file));
+        if(!file)
+            return(-1);
+    }
+
+    ret = darshan_log_get_mod(fd, DARSHAN_MPIIO_MOD, file,
         sizeof(struct darshan_mpiio_file));
+
+    if(*mpiio_buf_p == NULL)
+    {
+        if(ret == sizeof(struct darshan_mpiio_file))
+            *mpiio_buf_p = file;
+        else
+            free(file);
+    }
+
     if(ret < 0)
         return(-1);
     else if(ret < sizeof(struct darshan_mpiio_file))
         return(0);
     else
     {
-        file = (struct darshan_mpiio_file *)mpiio_buf;
+        /* if the read was successful, do any necessary byte-swapping */
         if(fd->swap_flag)
         {
-            /* swap bytes if necessary */
             DARSHAN_BSWAP64(&(file->base_rec.id));
             DARSHAN_BSWAP64(&(file->base_rec.rank));
             for(i=0; i<MPIIO_NUM_INDICES; i++)


=====================================
darshan-util/darshan-null-logutils.c
=====================================
--- a/darshan-util/darshan-null-logutils.c
+++ b/darshan-util/darshan-null-logutils.c
@@ -32,7 +32,7 @@ char *null_f_counter_names[] = {
 #undef X
 
 /* prototypes for each of the NULL module's logutil functions */
-static int darshan_log_get_null_record(darshan_fd fd, void* null_buf);
+static int darshan_log_get_null_record(darshan_fd fd, void** null_buf_p);
 static int darshan_log_put_null_record(darshan_fd fd, void* null_buf, int ver);
 static void darshan_log_print_null_record(void *file_rec,
     char *file_name, char *mnt_pt, char *fs_type, int ver);
@@ -60,15 +60,34 @@ struct darshan_mod_logutil_funcs null_logutils =
  * 'rec_id'. Return 1 on successful record read, 0 on no more data,
  * and -1 on error.
  */
-static int darshan_log_get_null_record(darshan_fd fd, void* null_buf)
+static int darshan_log_get_null_record(darshan_fd fd, void** null_buf_p)
 {
-    struct darshan_null_record *rec;
+    struct darshan_null_record *rec = *((struct darshan_null_record **)null_buf_p);
     int i;
     int ret;
 
+    if(fd->mod_map[DARSHAN_NULL_MOD].len == 0)
+        return(0);
+
+    if(*null_buf_p == NULL)
+    {
+        rec = malloc(sizeof(*rec));
+        if(!rec)
+            return(-1);
+    }
+
     /* read a NULL module record from the darshan log file */
-    ret = darshan_log_get_mod(fd, DARSHAN_NULL_MOD, null_buf,
+    ret = darshan_log_get_mod(fd, DARSHAN_NULL_MOD, rec,
         sizeof(struct darshan_null_record));
+
+    if(*null_buf_p == NULL)
+    {
+        if(ret == sizeof(struct darshan_null_record))
+            *null_buf_p = rec;
+        else
+            free(rec);
+    }
+
     if(ret < 0)
         return(-1);
     else if(ret < sizeof(struct darshan_null_record))
@@ -76,10 +95,8 @@ static int darshan_log_get_null_record(darshan_fd fd, void* null_buf)
     else
     {
         /* if the read was successful, do any necessary byte-swapping */
-        rec = (struct darshan_null_record *)null_buf;
         if(fd->swap_flag)
         {
-            /* swap bytes if necessary */
             DARSHAN_BSWAP64(&(rec->base_rec.id));
             DARSHAN_BSWAP64(&(rec->base_rec.rank));
             for(i=0; i<NULL_NUM_INDICES; i++)


=====================================
darshan-util/darshan-parser.c
=====================================
--- a/darshan-util/darshan-parser.c
+++ b/darshan-util/darshan-parser.c
@@ -422,7 +422,7 @@ int main(int argc, char **argv)
                 mod_logutils[i]->log_print_description();
         }
 
-        ret = mod_logutils[i]->log_get_record(fd, mod_buf);
+        ret = mod_logutils[i]->log_get_record(fd, (void **)&mod_buf);
         if(ret != 1)
         {
             fprintf(stderr, "Error: failed to parse the first %s module record.\n",
@@ -526,7 +526,7 @@ int main(int argc, char **argv)
 
             memset(mod_buf, 0, DEF_MOD_BUF_SIZE);
 
-        } while((ret = mod_logutils[i]->log_get_record(fd, mod_buf)) == 1);
+        } while((ret = mod_logutils[i]->log_get_record(fd, (void **)&mod_buf)) == 1);
         if (ret < 0)
         {
             ret = -1;


=====================================
darshan-util/darshan-pnetcdf-logutils.c
=====================================
--- a/darshan-util/darshan-pnetcdf-logutils.c
+++ b/darshan-util/darshan-pnetcdf-logutils.c
@@ -30,7 +30,7 @@ char *pnetcdf_f_counter_names[] = {
 };
 #undef X
 
-static int darshan_log_get_pnetcdf_file(darshan_fd fd, void* pnetcdf_buf);
+static int darshan_log_get_pnetcdf_file(darshan_fd fd, void** pnetcdf_buf_p);
 static int darshan_log_put_pnetcdf_file(darshan_fd fd, void* pnetcdf_buf, int ver);
 static void darshan_log_print_pnetcdf_file(void *file_rec,
     char *file_name, char *mnt_pt, char *fs_type, int ver);
@@ -49,24 +49,42 @@ struct darshan_mod_logutil_funcs pnetcdf_logutils =
     .log_agg_records = &darshan_log_agg_pnetcdf_files
 };
 
-static int darshan_log_get_pnetcdf_file(darshan_fd fd, void* pnetcdf_buf)
+static int darshan_log_get_pnetcdf_file(darshan_fd fd, void** pnetcdf_buf_p)
 {
-    struct darshan_pnetcdf_file *file;
+    struct darshan_pnetcdf_file *file = *((struct darshan_pnetcdf_file **)pnetcdf_buf_p);
     int i;
     int ret;
 
-    ret = darshan_log_get_mod(fd, DARSHAN_PNETCDF_MOD, pnetcdf_buf,
+    if(fd->mod_map[DARSHAN_PNETCDF_MOD].len == 0)
+        return(0);
+
+    if(*pnetcdf_buf_p == NULL)
+    {
+        file = malloc(sizeof(*file));
+        if(!file)
+            return(-1);
+    }
+
+    ret = darshan_log_get_mod(fd, DARSHAN_PNETCDF_MOD, file,
         sizeof(struct darshan_pnetcdf_file));
+
+    if(*pnetcdf_buf_p == NULL)
+    {
+        if(ret == sizeof(struct darshan_pnetcdf_file))
+            *pnetcdf_buf_p = file;
+        else
+            free(file);
+    }
+
     if(ret < 0)
         return(-1);
     else if(ret < sizeof(struct darshan_pnetcdf_file))
         return(0);
     else
     {
-        file = (struct darshan_pnetcdf_file *)pnetcdf_buf;
+        /* if the read was successful, do any necessary byte-swapping */
         if(fd->swap_flag)
         {
-            /* swap bytes if necessary */
             DARSHAN_BSWAP64(&(file->base_rec.id));
             DARSHAN_BSWAP64(&(file->base_rec.rank));
             for(i=0; i<PNETCDF_NUM_INDICES; i++)


=====================================
darshan-util/darshan-posix-logutils.c
=====================================
--- a/darshan-util/darshan-posix-logutils.c
+++ b/darshan-util/darshan-posix-logutils.c
@@ -32,7 +32,7 @@ char *posix_f_counter_names[] = {
 
 #define DARSHAN_POSIX_FILE_SIZE_1 680
 
-static int darshan_log_get_posix_file(darshan_fd fd, void* posix_buf);
+static int darshan_log_get_posix_file(darshan_fd fd, void** posix_buf_p);
 static int darshan_log_put_posix_file(darshan_fd fd, void* posix_buf, int ver);
 static void darshan_log_print_posix_file(void *file_rec,
     char *file_name, char *mnt_pt, char *fs_type, int ver);
@@ -51,14 +51,24 @@ struct darshan_mod_logutil_funcs posix_logutils =
     .log_agg_records = &darshan_log_agg_posix_files,
 };
 
-static int darshan_log_get_posix_file(darshan_fd fd, void* posix_buf)
+static int darshan_log_get_posix_file(darshan_fd fd, void** posix_buf_p)
 {
-    struct darshan_posix_file *file = (struct darshan_posix_file *)posix_buf;
+    struct darshan_posix_file *file = *((struct darshan_posix_file **)posix_buf_p);
     int rec_len;
     char *buffer, *p;
     int i;
     int ret = -1;
 
+    if(fd->mod_map[DARSHAN_POSIX_MOD].len == 0)
+        return(0);
+
+    if(*posix_buf_p == NULL)
+    {
+        file = malloc(sizeof(*file));
+        if(!file)
+            return(-1);
+    }
+
     /* read the POSIX record from file, checking the version first so we
      * can correctly up-convert to the current darshan version
      */
@@ -66,7 +76,11 @@ static int darshan_log_get_posix_file(darshan_fd fd, void* posix_buf)
     {
         buffer = malloc(DARSHAN_POSIX_FILE_SIZE_1);
         if(!buffer)
+        {
+            if(*posix_buf_p == NULL)
+                free(file);
             return(-1);
+        }
 
         rec_len = DARSHAN_POSIX_FILE_SIZE_1;
         ret = darshan_log_get_mod(fd, DARSHAN_POSIX_MOD, buffer, rec_len);
@@ -90,7 +104,15 @@ static int darshan_log_get_posix_file(darshan_fd fd, void* posix_buf)
     else if(fd->mod_ver[DARSHAN_POSIX_MOD] == 2)
     {
         rec_len = sizeof(struct darshan_posix_file);
-        ret = darshan_log_get_mod(fd, DARSHAN_POSIX_MOD, posix_buf, rec_len);
+        ret = darshan_log_get_mod(fd, DARSHAN_POSIX_MOD, file, rec_len);
+    }
+
+    if(*posix_buf_p == NULL)
+    {
+        if(ret == rec_len)
+            *posix_buf_p = file;
+        else
+            free(file);
     }
 
     if(ret < 0)
@@ -99,9 +121,9 @@ static int darshan_log_get_posix_file(darshan_fd fd, void* posix_buf)
         return(0);
     else
     {
+        /* if the read was successful, do any necessary byte-swapping */
         if(fd->swap_flag)
         {
-            /* swap bytes if necessary */
             DARSHAN_BSWAP64(&file->base_rec.id);
             DARSHAN_BSWAP64(&file->base_rec.rank);
             for(i=0; i<POSIX_NUM_INDICES; i++)


=====================================
darshan-util/darshan-stdio-logutils.c
=====================================
--- a/darshan-util/darshan-stdio-logutils.c
+++ b/darshan-util/darshan-stdio-logutils.c
@@ -32,7 +32,7 @@ char *stdio_f_counter_names[] = {
 #undef X
 
 /* prototypes for each of the STDIO module's logutil functions */
-static int darshan_log_get_stdio_record(darshan_fd fd, void* stdio_buf);
+static int darshan_log_get_stdio_record(darshan_fd fd, void** stdio_buf_p);
 static int darshan_log_put_stdio_record(darshan_fd fd, void* stdio_buf, int ver);
 static void darshan_log_print_stdio_record(void *file_rec,
     char *file_name, char *mnt_pt, char *fs_type, int ver);
@@ -57,15 +57,34 @@ struct darshan_mod_logutil_funcs stdio_logutils =
  * buffer in 'stdio_buf'. Return 1 on successful record read, 0 on no 
  * more data, and -1 on error.
  */
-static int darshan_log_get_stdio_record(darshan_fd fd, void* stdio_buf)
+static int darshan_log_get_stdio_record(darshan_fd fd, void** stdio_buf_p)
 {
-    struct darshan_stdio_file *file;
+    struct darshan_stdio_file *file = *((struct darshan_stdio_file **)stdio_buf_p);
     int i;
     int ret;
 
+    if(fd->mod_map[DARSHAN_STDIO_MOD].len == 0)
+        return(0);
+
+    if(*stdio_buf_p == NULL)
+    {
+        file = malloc(sizeof(*file));
+        if(!file)
+            return(-1);
+    }
+
     /* read a STDIO module record from the darshan log file */
-    ret = darshan_log_get_mod(fd, DARSHAN_STDIO_MOD, stdio_buf,
+    ret = darshan_log_get_mod(fd, DARSHAN_STDIO_MOD, file,
         sizeof(struct darshan_stdio_file));
+
+    if(*stdio_buf_p == NULL)
+    {
+        if(ret == sizeof(struct darshan_stdio_file))
+            *stdio_buf_p = file;
+        else
+            free(file);
+    }
+
     if(ret < 0)
         return(-1);
     else if(ret < sizeof(struct darshan_stdio_file))
@@ -73,10 +92,8 @@ static int darshan_log_get_stdio_record(darshan_fd fd, void* stdio_buf)
     else
     {
         /* if the read was successful, do any necessary byte-swapping */
-        file = (struct darshan_stdio_file *)stdio_buf;
         if(fd->swap_flag)
         {
-            /* swap bytes if necessary */
             DARSHAN_BSWAP64(&file->base_rec.id);
             DARSHAN_BSWAP64(&file->base_rec.rank);
             for(i=0; i<STDIO_NUM_INDICES; i++)



View it on GitLab: https://xgitlab.cels.anl.gov/darshan/darshan/compare/ddb55a27c53a2dca4507908ea006b7b4dcc888ca...ab32cf6690d62217a188a1dcf5010331405a6c04
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/darshan-commits/attachments/20160919/1fd28fe0/attachment-0001.html>


More information about the Darshan-commits mailing list