[Darshan-commits] [Darshan] branch, dev-modular, updated. darshan-2.3.1-135-g0d7fe69

Service Account git at mcs.anl.gov
Tue Aug 11 18:49:09 CDT 2015


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "".

The branch, dev-modular has been updated
       via  0d7fe6935fdccba8d604962228b5fdb0688f2656 (commit)
       via  4f5d233935e74193e7298efe688bb03169693457 (commit)
       via  30336460ceb8becd0dd219a2631f647b9f65ff6f (commit)
       via  6959ca27817bb471896df14308f5605b732bc11f (commit)
      from  a2ef6c6965fc2df514bd89728f69b2f205ec615c (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 0d7fe6935fdccba8d604962228b5fdb0688f2656
Author: Shane Snyder <ssnyder at mcs.anl.gov>
Date:   Tue Aug 11 13:20:24 2015 -0500

    finish implementation of darshan logutils

commit 4f5d233935e74193e7298efe688bb03169693457
Author: Shane Snyder <ssnyder at mcs.anl.gov>
Date:   Fri Aug 7 14:54:16 2015 -0500

    more makefile edits

commit 30336460ceb8becd0dd219a2631f647b9f65ff6f
Author: Shane Snyder <ssnyder at mcs.anl.gov>
Date:   Fri Aug 7 14:45:35 2015 -0500

    small fix for module logutils

commit 6959ca27817bb471896df14308f5605b732bc11f
Author: Shane Snyder <ssnyder at mcs.anl.gov>
Date:   Fri Aug 7 10:02:39 2015 -0500

    darshan-util makefile cleanup

-----------------------------------------------------------------------

Summary of changes:
 darshan-util/Makefile.in                |   43 ++--
 darshan-util/darshan-hdf5-logutils.c    |   10 +-
 darshan-util/darshan-log-params.c       |   14 --
 darshan-util/darshan-logutils.c         |  372 ++++++++++++++++++++++++++++---
 darshan-util/darshan-logutils.h         |   12 +-
 darshan-util/darshan-mpiio-logutils.c   |   10 +-
 darshan-util/darshan-pnetcdf-logutils.c |   10 +-
 darshan-util/darshan-posix-logutils.c   |   10 +-
 8 files changed, 398 insertions(+), 83 deletions(-)
 delete mode 100644 darshan-util/darshan-log-params.c


Diff of changes:
diff --git a/darshan-util/Makefile.in b/darshan-util/Makefile.in
index 16802bb..11bdbf1 100644
--- a/darshan-util/Makefile.in
+++ b/darshan-util/Makefile.in
@@ -1,4 +1,4 @@
-all: libdarshan-util.a darshan-parser
+all: libdarshan-util.a darshan-analyzer darshan-convert darshan-parser
 
 DESTDIR =
 srcdir = @srcdir@
@@ -13,6 +13,9 @@ libdir = $(DESTDIR)@libdir@
 pkgconfigdir = $(DESTDIR)$(libdir)/pkgconfig
 
 DARSHAN_LOG_FORMAT = $(srcdir)/../darshan-log-format.h
+DARSHAN_MOD_LOG_FORMATS = $(srcdir)/../darshan-posix-log-format.h $(srcdir)/../darshan-mpiio-log-format.h $(srcdir)/../darshan-hdf5-log-format.h $(srcdir)/../darshan-pnetcdf-log-format.h
+DARSHAN_MOD_LOGUTIL_HEADERS = darshan-posix-logutils.h darshan-mpiio-logutils.h darshan-hdf5-logutils.h darshan-pnetcdf-logutils.h
+
 DARSHAN_ENABLE_SHARED=@DARSHAN_ENABLE_SHARED@
 
 VPATH = $(srcdir)
@@ -61,6 +64,11 @@ darshan-hdf5-logutils.o: darshan-hdf5-logutils.c darshan-logutils.h darshan-hdf5
 darshan-hdf5-logutils.po: darshan-hdf5-logutils.c darshan-logutils.h darshan-hdf5-logutils.h $(DARSHAN_LOG_FORMAT) $(srcdir)/../darshan-hdf5-log-format.h | uthash-1.9.2
 	$(CC) $(CFLAGS_SHARED) -c  $< -o $@
 
+darshan-pnetcdf-logutils.o: darshan-pnetcdf-logutils.c darshan-logutils.h darshan-pnetcdf-logutils.h $(DARSHAN_LOG_FORMAT) $(srcdir)/../darshan-pnetcdf-log-format.h | uthash-1.9.2
+	$(CC) $(CFLAGS) -c  $< -o $@
+darshan-pnetcdf-logutils.po: darshan-pnetcdf-logutils.c darshan-logutils.h darshan-pnetcdf-logutils.h $(DARSHAN_LOG_FORMAT) $(srcdir)/../darshan-pnetcdf-log-format.h | uthash-1.9.2
+	$(CC) $(CFLAGS_SHARED) -c  $< -o $@
+
 libdarshan-util.so: darshan-logutils.po darshan-posix-logutils.po darshan-mpiio-logutils.po darshan-hdf5-logutils.po darshan-pnetcdf-logutils.po
 	$(CC) $(CFLAGS_SHARED) $(LDFLAGS) -o $@ $^ $(LIBS)
 	
@@ -70,48 +78,45 @@ libdarshan-util.a: darshan-logutils.o darshan-posix-logutils.o darshan-mpiio-log
 jenkins: util/bin/jenkins.o lookup3.o
 	$(CC) $(CFLAGS)  $(LDFLAGS) $< -o $@ lookup3.o $(LIBS)
 
-darshan-parser: darshan-parser.c darshan-logutils.h darshan-posix-logutils.h darshan-mpiio-logutils.h $(DARSHAN_LOG_FORMAT) $(srcdir)/../darshan-posix-log-format.h $(srcdir)/../darshan-mpiio-log-format.h libdarshan-util.a | uthash-1.9.2
-	$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@ $(LIBS) 
-
-#darshan-convert: darshan-convert.c $(DARSHAN_LOG_FORMAT) darshan-logutils.h darshan-logutils.o lookup3.o
-#	$(CC) $(CFLAGS)  $(LDFLAGS) $< darshan-logutils.o lookup3.o -o $@ $(LIBS)
+lookup3.o: lookup3.c
+	$(CC) $(CFLAGS) -c $< -o $@
 
-#darshan-analyzer: darshan-analyzer.c $(DARSHAN_LOG_FORMAT) darshan-logutils.h darshan-logutils.o
-#	$(CC) $(CFLAGS)  $(LDFLAGS) $< darshan-logutils.o -o $@ $(LIBS)
+darshan-analyzer: darshan-analyzer.c darshan-logutils.h $(DARSHAN_LOG_FORMAT) $(DARSHAN_MOD_LOGUTIL_HEADERS) $(DARSHAN_MOD_LOG_FORMATS) libdarshan-util.a | uthash-1.9.2
+	$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@ $(LIBS)
 
-#darshan-log-params: darshan-log-params.c $(DARSHAN_LOG_FORMAT)
-#	$(CC) $(CFLAGS)  $(LDFLAGS) $< -o $@ $(LIBS)
+darshan-convert: darshan-convert.c darshan-logutils.h $(DARSHAN_LOG_FORMAT) libdarshan-util.a | uthash-1.9.2
+	$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@ $(LIBS)
 
 #darshan-diff: darshan-diff.o $(DARSHAN_LOG_FORMAT) darshan-logutils.o darshan-logutils.h
 #	$(CC) $(CFLAGS)  $(LDFLAGS) $< darshan-logutils.o -o $@ $(LIBS)
 #darshan-diff.o: darshan-diff.c
 #	$(CC) $(CFLAGS) -c  $< -o $@
 
+darshan-parser: darshan-parser.c darshan-logutils.h $(DARSHAN_LOG_FORMAT) $(DARSHAN_MOD_LOGUTIL_HEADERS) $(DARSHAN_MOD_LOG_FORMATS) libdarshan-util.a | uthash-1.9.2
+	$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@ $(LIBS) 
+
 #test/gztest: test/gztest.c mktestdir
 #	$(CC) $(CFLAGS)  $(LDFLAGS) -lz $< -o $@
 
 #test/gz-bench: test/gz-bench.c mktestdir
 #	$(CC) $(CFLAGS)  $(LDFLAGS) -lz $< -o $@
 
-lookup3.o: lookup3.c
-	$(CC) $(CFLAGS) -c $< -o $@
-
 install:: all
 	install -d $(bindir)
 	install -d $(libdir)
 	install -d $(includedir)
 	install -d $(pkgconfigdir)
-	install -m 755 darshan-parser $(bindir)
-#	install -m 755 darshan-convert $(bindir)
+	install -m 755 darshan-analyzer $(bindir)
+	install -m 755 darshan-convert $(bindir)
 #	install -m 755 darshan-diff $(bindir)
-#	install -m 755 darshan-analyzer $(bindir)
+	install -m 755 darshan-parser $(bindir)
 #	install -m 755 $(srcdir)/darshan-summary-per-file.sh $(bindir)
 	install -m 755 libdarshan-util.a $(libdir)
 ifeq ($(DARSHAN_ENABLE_SHARED),1)
 	install -m 755 libdarshan-util.so $(libdir)
 endif
-#	install -m 644 $(srcdir)/darshan-logutils.h $(includedir)
-#	install -m 644 $(DARSHAN_LOG_FORMAT) $(includedir)
+	install -m 644 $(srcdir)/darshan-logutils.h $(includedir)
+	install -m 644 $(DARSHAN_LOG_FORMAT) $(includedir)
 #	install -m 755 darshan-job-summary/bin/darshan-job-summary.pl $(bindir)
 #	install -d $(libdir)/TeX
 #	install -m 644 $(srcdir)/darshan-job-summary/lib/TeX/Encode.pm $(libdir)/TeX/
@@ -124,7 +129,7 @@ endif
 
 
 clean::
-	rm -f *.o *.a darshan-parser darshan-posix-parser darshan-mpiio-parser
+	rm -f *.o *.a darshan-analyzer darshan-convert darshan-parser
 
 distclean:: clean
 	rm -f darshan-runtime-config.h aclocal.m4 autom4te.cache/* config.status config.log Makefile util/bin/darshan-job-summary.pl
diff --git a/darshan-util/darshan-hdf5-logutils.c b/darshan-util/darshan-hdf5-logutils.c
index d921263..af8ee79 100644
--- a/darshan-util/darshan-hdf5-logutils.c
+++ b/darshan-util/darshan-hdf5-logutils.c
@@ -42,13 +42,14 @@ int darshan_log_get_hdf5_file(darshan_fd fd, void **file_rec,
     int i;
     int ret;
     struct darshan_hdf5_file *file = NULL;
+    *rec_id = 0;
 
     file = malloc(sizeof(*file));
     if(!file)
         return(-1);
     memset(file, 0, sizeof(*file));
 
-    ret = darshan_log_get_moddat(fd, DARSHAN_HDF5_MOD,
+    ret = darshan_log_getmod(fd, DARSHAN_HDF5_MOD,
         (void *)file, sizeof(*file));
     if(ret == 1)
     {
@@ -62,11 +63,12 @@ int darshan_log_get_hdf5_file(darshan_fd fd, void **file_rec,
             for(i=0; i<HDF5_F_NUM_INDICES; i++)
                 DARSHAN_BSWAP64(&file->fcounters[i]);
         }
+
+        /* pass the file record back */
+        *file_rec = (void *)file;
+        *rec_id = file->f_id;
     }
 
-    /* pass the file record back */
-    *file_rec = (void *)file;
-    *rec_id = file->f_id;
     return(ret);
 }
 
diff --git a/darshan-util/darshan-log-params.c b/darshan-util/darshan-log-params.c
deleted file mode 100644
index 22645e5..0000000
--- a/darshan-util/darshan-log-params.c
+++ /dev/null
@@ -1,14 +0,0 @@
-#include <stdio.h>
-#include "darshan-log-format.h"
-
-int main(int argc, char **argv) 
-{
-    printf("version: %s\n", CP_VERSION);
-    printf("CP_JOB_RECORD_SIZE: %d\n", CP_JOB_RECORD_SIZE);
-    printf("CP_EXE_LEN: %zu\n", CP_EXE_LEN);
-    printf("CP_FILE_RECORD_SIZE: %zu\n", CP_FILE_RECORD_SIZE);
-    printf("CP_NAME_SUFFIX_LEN: %d\n", CP_NAME_SUFFIX_LEN);
-    printf("CP_NUM_INDICES: %d\n", CP_NUM_INDICES);
-    printf("CP_F_NUM_INDICES: %d\n", CP_F_NUM_INDICES);
-    return(0);
-}
diff --git a/darshan-util/darshan-logutils.c b/darshan-util/darshan-logutils.c
index e126e3f..06a37c6 100644
--- a/darshan-util/darshan-logutils.c
+++ b/darshan-util/darshan-logutils.c
@@ -21,7 +21,7 @@
 
 static int darshan_log_seek(darshan_fd fd, off_t offset);
 static int darshan_log_read(darshan_fd fd, void *buf, int len);
-//static int darshan_log_write(darshan_fd fd, void *buf, int len);
+static int darshan_log_write(darshan_fd fd, void *buf, int len);
 
 /* TODO: can we make this s.t. we don't care about ordering (i.e., X macro it ) */
 struct darshan_mod_logutil_funcs *mod_logutils[DARSHAN_MAX_MODS] =
@@ -94,9 +94,9 @@ int darshan_log_getheader(darshan_fd fd, struct darshan_header *header)
 
     /* read header from log file */
     ret = darshan_log_read(fd, header, sizeof(*header));
-    if(ret < sizeof(*header))
+    if(ret != sizeof(*header))
     {
-        fprintf(stderr, "Error: invalid darshan log file (failed to read header).\n");
+        fprintf(stderr, "Error: failed to read darshan log file header.\n");
         return(-1);
     }
 
@@ -140,6 +140,38 @@ int darshan_log_getheader(darshan_fd fd, struct darshan_header *header)
     return(0);
 }
 
+/* darshan_log_putheader()
+ *
+ * write a darshan header to log file
+ *
+ * returns 0 on success, -1 on failure
+ */
+int darshan_log_putheader(darshan_fd fd, struct darshan_header *header)
+{
+    int ret;
+
+    ret = darshan_log_seek(fd, 0);
+    if(ret < 0)
+    {
+        fprintf(stderr, "Error: unable to seek in darshan log file.\n");
+        return(-1);
+    }
+
+    /* write header to file */
+    ret = darshan_log_write(fd, header, sizeof(*header));
+    if(ret != sizeof(*header))
+    {
+        fprintf(stderr, "Error: failed to write Darshan log file header.\n");
+        return(-1);
+    }
+
+    /* copy the mapping information to the file descriptor */
+    memcpy(&fd->rec_map, &header->rec_map, sizeof(struct darshan_log_map));
+    memcpy(&fd->mod_map, &header->mod_map, DARSHAN_MAX_MODS * sizeof(struct darshan_log_map));
+
+    return(0);
+}
+
 /* darshan_log_getjob()
  *
  * read job level metadata from the darshan log file
@@ -159,9 +191,9 @@ int darshan_log_getjob(darshan_fd fd, struct darshan_job *job)
 
     /* read the job data from the log file */
     ret = darshan_log_read(fd, job, sizeof(*job));
-    if(ret < sizeof(*job))
+    if(ret != sizeof(*job))
     {
-        fprintf(stderr, "Error: invalid darshan log file (failed to read job data).\n");
+        fprintf(stderr, "Error: failed to read darshan log file job data.\n");
         return(-1);
     }
 
@@ -178,6 +210,56 @@ int darshan_log_getjob(darshan_fd fd, struct darshan_job *job)
     return(0);
 }
 
+/* darshan_log_putjob()
+ *
+ * write job level metadat to darshan log file
+ *
+ * returns 0 on success, -1 on failure
+ */
+int darshan_log_putjob(darshan_fd fd, struct darshan_job *job)
+{
+    struct darshan_job job_copy;
+    int len;
+    int ret;
+
+    ret = darshan_log_seek(fd, sizeof(struct darshan_header));
+    if(ret < 0)
+    {
+        fprintf(stderr, "Error: unable to seek in darshan log file.\n");
+        return(-1);
+    }
+
+    memset(&job_copy, 0, sizeof(*job));
+    memcpy(&job_copy, job, sizeof(*job));
+
+    /* check for newline in existing metadata, add if needed */
+    len = strlen(job_copy.metadata);
+    if(len > 0 && len < DARSHAN_JOB_METADATA_LEN)
+    {
+        if(job_copy.metadata[len-1] != '\n')
+        {
+            job_copy.metadata[len] = '\n';
+            job_copy.metadata[len+1] = '\0';
+        }
+    }
+
+    /* write job data to file */
+    ret = darshan_log_write(fd, job, sizeof(*job));
+    if(ret != sizeof(*job))
+    {
+        fprintf(stderr, "Error: failed to write darshan log file job data.\n");
+        return(-1);
+    }
+
+    return(0);
+}
+
+/* darshan_log_getexe()
+ *
+ * reads the application exe name from darshan log file
+ * 
+ * returns 0 on success, -1 on failure 
+ */
 int darshan_log_getexe(darshan_fd fd, char *buf)
 {
     int tmp_off = sizeof(struct darshan_header) + sizeof(struct darshan_job);
@@ -193,9 +275,9 @@ int darshan_log_getexe(darshan_fd fd, char *buf)
 
     /* read the trailing exe data from the darshan log */
     ret = darshan_log_read(fd, buf, DARSHAN_EXE_LEN+1);
-    if(ret < DARSHAN_EXE_LEN+1)
+    if(ret != DARSHAN_EXE_LEN+1)
     {
-        fprintf(stderr, "Error: invalid darshan log file (failed to read exe string).\n");
+        fprintf(stderr, "Error: failed to read exe string from darshan log file.\n");
         return(-1);
     }
 
@@ -207,11 +289,44 @@ int darshan_log_getexe(darshan_fd fd, char *buf)
     return (0);
 }
 
+/* darshan_log_putexe()
+ *
+ * wrties the application exe name to darshan log file
+ *
+ * returns 0 on success, -1 on failure 
+ */
+int darshan_log_putexe(darshan_fd fd, char *buf)
+{
+    int tmp_off = sizeof(struct darshan_header) + sizeof(struct darshan_job);
+    int len;
+    int ret;
+
+    ret = darshan_log_seek(fd, tmp_off);
+    if(ret < 0)
+    {
+        fprintf(stderr, "Error: unable to seek in darshan log file.\n");
+        return(-1);
+    }
+
+    len = strlen(buf);
+
+    ret = darshan_log_write(fd, buf, len);
+    if(ret != len)
+    {
+        fprintf(stderr, "Error: failed to write exe string to darshan log file.\n");
+        return(-1);
+    }
+
+    return(0);
+}
+
 /* darshan_log_getmounts()
  * 
- * retrieves mount table information from the log.  Note that mnt_pts and
+ * retrieves mount table information from the log. Note that mnt_pts and
  * fs_types are arrays that will be allocated by the function and must be
- * freed by the caller.  count will indicate the size of the arrays
+ * freed by the caller. count will indicate the size of the arrays
+ *
+ * returns 0 on success, -1 on failure
  */
 int darshan_log_getmounts(darshan_fd fd, char*** mnt_pts,
     char*** fs_types, int* count)
@@ -231,9 +346,9 @@ int darshan_log_getmounts(darshan_fd fd, char*** mnt_pts,
 
     /* read the trailing mount data from the darshan log */
     ret = darshan_log_read(fd, buf, DARSHAN_EXE_LEN+1);
-    if(ret < DARSHAN_EXE_LEN+1)
+    if(ret != DARSHAN_EXE_LEN+1)
     {
-        fprintf(stderr, "Error: invalid darshan log file (failed to read mount info).\n");
+        fprintf(stderr, "Error: failed to read mount info from darshan log file.\n");
         return(-1);
     }
 
@@ -273,7 +388,7 @@ int darshan_log_getmounts(darshan_fd fd, char*** mnt_pts,
             (*mnt_pts)[array_index]);
         if(ret != 2)
         {
-            fprintf(stderr, "Error: poorly formatted mount table in log file.\n");
+            fprintf(stderr, "Error: poorly formatted mount table in darshan log file.\n");
             return(-1);
         }
         pos--;
@@ -284,6 +399,44 @@ int darshan_log_getmounts(darshan_fd fd, char*** mnt_pts,
     return(0);
 }
 
+/* darshan_log_putmounts()
+ *
+ * writes mount information to the darshan log file
+ * NOTE: this function call should follow immediately after the call
+ * to darshan_log_putexe(), as it assumes the darshan log file pointer
+ * is pointing to the offset immediately following the exe string
+ *
+ * returns 0 on success, -1 on failure
+ */
+int darshan_log_putmounts(darshan_fd fd, char** mnt_pts, char** fs_types, int count)
+{
+    int i;
+    char line[1024];
+    int ret;
+
+    /* write each mount entry to file */
+    for(i=count-1; i>=0; i--)
+    {
+        sprintf(line, "\n%s\t%s", fs_types[i], mnt_pts[i]);
+        ret = darshan_log_write(fd, line, strlen(line));
+        if (ret != strlen(line))
+        {
+            fprintf(stderr, "Error: failed to write darshan log mount entry.\n");
+            return(-1);
+        }
+    }
+
+    /* seek ahead to end of exe region, will be zero filled */
+    ret = darshan_log_seek(fd, DARSHAN_JOB_RECORD_SIZE);
+    if (ret < 0)
+    {
+        fprintf(stderr, "Error: unable to seek forward in darshan log file.\n");
+        return(-1);
+    }
+
+    return(0);
+}
+
 /* darshan_log_gethash()
  *
  * read the hash of records from the darshan log file
@@ -301,10 +454,6 @@ int darshan_log_gethash(darshan_fd fd, struct darshan_record_ref **hash)
     struct darshan_record_ref *ref;
     int ret;
 
-    hash_buf = malloc(hash_buf_sz);
-    if(!hash_buf)
-        return(-1);
-
     ret = darshan_log_seek(fd, fd->rec_map.off);
     if(ret < 0)
     {
@@ -312,11 +461,15 @@ int darshan_log_gethash(darshan_fd fd, struct darshan_record_ref **hash)
         return(-1);
     }
 
+    hash_buf = malloc(hash_buf_sz);
+    if(!hash_buf)
+        return(-1);
+
     /* read the record hash from the log file */
     ret = darshan_log_read(fd, hash_buf, fd->rec_map.len);
-    if(ret < fd->rec_map.len)
+    if(ret != fd->rec_map.len)
     {
-        fprintf(stderr, "Error: invalid darshan log file (failed to read record hash).\n");
+        fprintf(stderr, "Error: failed to read record hash from darshan log file.\n");
         return(-1);
     }
 
@@ -369,8 +522,105 @@ int darshan_log_gethash(darshan_fd fd, struct darshan_record_ref **hash)
     return(0);
 }
 
-int darshan_log_get_moddat(darshan_fd fd, darshan_module_id mod_id,
-    void *moddat_buf, int moddat_buf_sz)
+/* darshan_log_puthash()
+ *
+ * writes the hash table of records to the darshan log file
+ *
+ * returns 0 on success, -1 on failure
+ */
+int darshan_log_puthash(darshan_fd fd, struct darshan_record_ref *hash)
+{
+    size_t hash_buf_sz;
+    char *hash_buf;
+    char *hash_buf_off;
+    struct darshan_record_ref *ref, *tmp;
+    uint32_t name_len;
+    size_t record_sz;
+    int ret;
+
+    ret = darshan_log_seek(fd, fd->rec_map.off);
+    if(ret < 0)
+    {
+        fprintf(stderr, "Error: unable to seek in darshan log file.\n");
+        return(-1);
+    }
+
+    /* allocate a buffer to store 2 MiB worth of record data */
+    /* NOTE: this buffer may be reallocated if estimate is too small */
+    hash_buf_sz = 2 * 1024 * 1024;
+    hash_buf = malloc(hash_buf_sz);
+    if(!hash_buf)
+    {
+        return(-1);
+    }
+
+    /* serialize the record hash into a buffer for writing */
+    hash_buf_off = hash_buf;
+    HASH_ITER(hlink, hash, ref, tmp)
+    {
+        name_len = strlen(ref->rec.name);
+        record_sz = sizeof(darshan_record_id) + sizeof(uint32_t) + name_len;
+        /* make sure there is room in the buffer for this record */
+        if((hash_buf_off + record_sz) > (hash_buf + hash_buf_sz))
+        {
+            char *tmp_buf;
+            size_t old_buf_sz;
+
+            /* if no room, reallocate the hash buffer at twice the current size */
+            old_buf_sz = hash_buf_off - hash_buf;
+            hash_buf_sz *= 2;
+            tmp_buf = malloc(hash_buf_sz);
+            if(!tmp_buf)
+            {
+                free(hash_buf);
+                return(-1);
+            }
+
+            memcpy(tmp_buf, hash_buf, old_buf_sz);
+            free(hash_buf);
+            hash_buf = tmp_buf;
+            hash_buf_off = hash_buf + old_buf_sz;
+        }
+
+        /* now serialize the record into the hash buffer.
+         * NOTE: darshan record hash serialization method: 
+         *          ... darshan_record_id | (uint32_t) path_len | path ...
+         */
+        *((darshan_record_id *)hash_buf_off) = ref->rec.id;
+        hash_buf_off += sizeof(darshan_record_id);
+        *((uint32_t *)hash_buf_off) = name_len;
+        hash_buf_off += sizeof(uint32_t);
+        memcpy(hash_buf_off, ref->rec.name, name_len);
+        hash_buf_off += name_len;
+    }
+
+    /* collectively write out the record hash to the darshan log */
+    hash_buf_sz = hash_buf_off - hash_buf;
+
+    /* write the record hash to file */
+    ret = darshan_log_write(fd, hash_buf, hash_buf_sz);
+    if(ret != hash_buf_sz)
+    {
+        fprintf(stderr, "Error: failed to write record hash to darshan log file.\n");
+        return(-1);
+    }
+
+    free(hash_buf);
+
+    return(0);
+}
+
+/* darshan_log_getmod()
+ *
+ * reads a chunk of data for a corresponding darshan instrumentation module
+ * NOTE: mod_buf_sz is the uncompressed size of data we wish to read for the given
+ * module. chunks of data can be read sequentially for a given module by
+ * repeatedly calling this function with the desired chunk sizes.
+ *
+ * returns 1 on successful read of data, 0 on end of module region, -1 on failure
+ */
+int darshan_log_getmod(darshan_fd fd, darshan_module_id mod_id,
+    void *mod_buf, int mod_buf_sz)
 {
     int mod_buf_end = fd->mod_map[mod_id].off + fd->mod_map[mod_id].len;
     int ret;
@@ -393,12 +643,19 @@ int darshan_log_get_moddat(darshan_fd fd, darshan_module_id mod_id,
         }
     }
 
-    /* read the record hash from the log file */
-    ret = darshan_log_read(fd, moddat_buf, moddat_buf_sz);
-    if(ret != moddat_buf_sz)
+    /* if the requested amount of data violates mapping info, error out */
+    if(mod_buf_sz > (mod_buf_end - fd->pos))
+    {
+        fprintf(stderr, "Error: module data read violates stored mapping information.\n");
+        return(-1);
+    }
+
+    /* read the module chunk from the log file */
+    ret = darshan_log_read(fd, mod_buf, mod_buf_sz);
+    if(ret != mod_buf_sz)
     {
         fprintf(stderr,
-            "Error: invalid darshan log file (failed to read module %s data).\n",
+            "Error: failed to read module %s data from darshan log file.\n",
             darshan_module_names[mod_id]);
         return(-1);
     }
@@ -406,6 +663,59 @@ int darshan_log_get_moddat(darshan_fd fd, darshan_module_id mod_id,
     return(1);
 }
 
+/* darshan_log_putmod()
+ *
+ * write a chunk of module data to the darshan log file
+ *
+ * returns 0 on success, -1 on failure
+ */
+int darshan_log_putmod(darshan_fd fd, darshan_module_id mod_id,
+    void *mod_buf, int mod_buf_sz)
+{
+    int mod_buf_end = fd->mod_map[mod_id].off + fd->mod_map[mod_id].len;
+    int ret;
+
+    if(!fd->mod_map[mod_id].len)
+    {
+        fprintf(stderr, "Error: attempting to write data for empty module.\n");
+        return(-1);
+    }
+
+    /* only seek to start of module data if current log file position 
+     * is not within the given mod_id's range. This allows one to
+     * repeatedly call this function and put chunks of a module's
+     * data piecemeal.
+     */
+    if((fd->pos < fd->mod_map[mod_id].off) || (fd->pos > mod_buf_end))
+    {
+        ret = darshan_log_seek(fd, fd->mod_map[mod_id].off);
+        if(ret < 0)
+        {
+            fprintf(stderr, "Error: unable to seek in darshan log file.\n");
+            return(-1);
+        }
+    }
+
+    /* if the given data violates stored mapping info, error out */
+    if(mod_buf_sz > (mod_buf_end - fd->pos))
+    {
+        fprintf(stderr, "Error: module data write violates stored mapping information.\n");
+        return(-1);
+    }
+
+    /* write the module chunk to the log file */
+    ret = darshan_log_write(fd, mod_buf, mod_buf_sz);
+    if(ret != mod_buf_sz)
+    {
+        fprintf(stderr,
+            "Error: failed to write module %s data to darshan log file.\n",
+            darshan_module_names[mod_id]);
+        return(-1);
+    }
+
+    return(0);
+}
+
 /* darshan_log_close()
  *
  * close an open darshan file descriptor
@@ -449,16 +759,15 @@ static int darshan_log_seek(darshan_fd fd, off_t offset)
     return(-1);
 }
 
-#if 0
-/* return amount written on success, -1 on failure.
+/* return amount read on success, 0 on EOF, -1 on failure.
  */
-static int darshan_log_write(darshan_fd fd, void* buf, int len)
+static int darshan_log_read(darshan_fd fd, void* buf, int len)
 {
     int ret;
 
     if(fd->gzf)
     {
-        ret = gzwrite(fd->gzf, buf, len);
+        ret = gzread(fd->gzf, buf, len);
         if(ret > 0)
             fd->pos += ret;
         return(ret);
@@ -466,17 +775,16 @@ static int darshan_log_write(darshan_fd fd, void* buf, int len)
 
     return(-1);
 }
-#endif
 
-/* return amount read on success, 0 on EOF, -1 on failure.
+/* return amount written on success, -1 on failure.
  */
-static int darshan_log_read(darshan_fd fd, void* buf, int len)
+static int darshan_log_write(darshan_fd fd, void* buf, int len)
 {
     int ret;
 
     if(fd->gzf)
     {
-        ret = gzread(fd->gzf, buf, len);
+        ret = gzwrite(fd->gzf, buf, len);
         if(ret > 0)
             fd->pos += ret;
         return(ret);
diff --git a/darshan-util/darshan-logutils.h b/darshan-util/darshan-logutils.h
index c54ec17..dea2691 100644
--- a/darshan-util/darshan-logutils.h
+++ b/darshan-util/darshan-logutils.h
@@ -60,13 +60,21 @@ extern struct darshan_mod_logutil_funcs *mod_logutils[DARSHAN_MAX_MODS];
 
 darshan_fd darshan_log_open(const char *name, const char* mode);
 int darshan_log_getheader(darshan_fd fd, struct darshan_header *header);
+int darshan_log_putheader(darshan_fd fd, struct darshan_header *header);
 int darshan_log_getjob(darshan_fd fd, struct darshan_job *job);
+int darshan_log_putjob(darshan_fd fd, struct darshan_job *job);
 int darshan_log_getexe(darshan_fd fd, char *buf);
+int darshan_log_putexe(darshan_fd fd, char *buf);
 int darshan_log_getmounts(darshan_fd fd, char*** mnt_pts,
     char*** fs_types, int* count);
+int darshan_log_putmounts(darshan_fd fd, char** mnt_pts,
+    char** fs_types, int count);
 int darshan_log_gethash(darshan_fd fd, struct darshan_record_ref **hash);
-int darshan_log_get_moddat(darshan_fd fd, darshan_module_id mod_id,
-    void *moddat_buf, int moddat_buf_sz);
+int darshan_log_puthash(darshan_fd fd, struct darshan_record_ref *hash);
+int darshan_log_getmod(darshan_fd fd, darshan_module_id mod_id,
+    void *mod_buf, int mod_buf_sz);
+int darshan_log_putmod(darshan_fd fd, darshan_module_id mod_id,
+    void *mod_buf, int mod_buf_sz);
 void darshan_log_close(darshan_fd file);
 
 /* convenience macros for printing Darshan counters */
diff --git a/darshan-util/darshan-mpiio-logutils.c b/darshan-util/darshan-mpiio-logutils.c
index f96b0a0..f1c1322 100644
--- a/darshan-util/darshan-mpiio-logutils.c
+++ b/darshan-util/darshan-mpiio-logutils.c
@@ -42,13 +42,14 @@ int darshan_log_get_mpiio_file(darshan_fd fd, void **file_rec,
     int i;
     int ret;
     struct darshan_mpiio_file *file = NULL;
+    *rec_id = 0;
 
     file = malloc(sizeof(*file));
     if(!file)
         return(-1);
     memset(file, 0, sizeof(*file));
 
-    ret = darshan_log_get_moddat(fd, DARSHAN_MPIIO_MOD,
+    ret = darshan_log_getmod(fd, DARSHAN_MPIIO_MOD,
         (void *)file, sizeof(*file));
     if(ret == 1)
     {
@@ -62,11 +63,12 @@ int darshan_log_get_mpiio_file(darshan_fd fd, void **file_rec,
             for(i=0; i<MPIIO_F_NUM_INDICES; i++)
                 DARSHAN_BSWAP64(&file->fcounters[i]);
         }
+
+        /* pass the file record back */
+        *file_rec = (void *)file;
+        *rec_id = file->f_id;
     }
 
-    /* pass the file record back */
-    *file_rec = (void *)file;
-    *rec_id = file->f_id;
     return(ret);
 }
 
diff --git a/darshan-util/darshan-pnetcdf-logutils.c b/darshan-util/darshan-pnetcdf-logutils.c
index 7b96396..e8d2db5 100644
--- a/darshan-util/darshan-pnetcdf-logutils.c
+++ b/darshan-util/darshan-pnetcdf-logutils.c
@@ -42,13 +42,14 @@ int darshan_log_get_pnetcdf_file(darshan_fd fd, void **file_rec,
     int i;
     int ret;
     struct darshan_pnetcdf_file *file = NULL;
+    *rec_id = 0;
 
     file = malloc(sizeof(*file));
     if(!file)
         return(-1);
     memset(file, 0, sizeof(*file));
 
-    ret = darshan_log_get_moddat(fd, DARSHAN_PNETCDF_MOD,
+    ret = darshan_log_getmod(fd, DARSHAN_PNETCDF_MOD,
         (void *)file, sizeof(*file));
     if(ret == 1)
     {
@@ -62,11 +63,12 @@ int darshan_log_get_pnetcdf_file(darshan_fd fd, void **file_rec,
             for(i=0; i<PNETCDF_F_NUM_INDICES; i++)
                 DARSHAN_BSWAP64(&file->fcounters[i]);
         }
+
+        /* pass the file record back */
+        *file_rec = (void *)file;
+        *rec_id = file->f_id;
     }
 
-    /* pass the file record back */
-    *file_rec = (void *)file;
-    *rec_id = file->f_id;
     return(ret);
 }
 
diff --git a/darshan-util/darshan-posix-logutils.c b/darshan-util/darshan-posix-logutils.c
index eedc4b5..9df0c8f 100644
--- a/darshan-util/darshan-posix-logutils.c
+++ b/darshan-util/darshan-posix-logutils.c
@@ -42,13 +42,14 @@ int darshan_log_get_posix_file(darshan_fd fd, void **file_rec,
     int i;
     int ret;
     struct darshan_posix_file *file = NULL;
+    *rec_id = 0;
 
     file = malloc(sizeof(*file));
     if(!file)
         return(-1);
     memset(file, 0, sizeof(*file));
 
-    ret = darshan_log_get_moddat(fd, DARSHAN_POSIX_MOD,
+    ret = darshan_log_getmod(fd, DARSHAN_POSIX_MOD,
         (void *)file, sizeof(*file));
     if(ret == 1)
     {
@@ -62,11 +63,12 @@ int darshan_log_get_posix_file(darshan_fd fd, void **file_rec,
             for(i=0; i<POSIX_F_NUM_INDICES; i++)
                 DARSHAN_BSWAP64(&file->fcounters[i]);
         }
+
+        /* pass the file record back */
+        *file_rec = (void *)file;
+        *rec_id = file->f_id;
     }
 
-    /* pass the file record back */
-    *file_rec = (void *)file;
-    *rec_id = file->f_id;
     return(ret);
 }
 


hooks/post-receive
--



More information about the Darshan-commits mailing list