diff --git a/darshan-util/darshan-convert.c b/darshan-util/darshan-convert.c index 657e58f2f65f45edac3be489417b90279373078b..3a28a7ce9c494548334912f12959c39572472c7c 100644 --- a/darshan-util/darshan-convert.c +++ b/darshan-util/darshan-convert.c @@ -230,8 +230,7 @@ int main(int argc, char **argv) darshan_fd outfile; int i; int mount_count; - char** mnt_pts; - char** fs_types; + struct darshan_mnt_info *mnt_data_array; struct darshan_record_ref *rec_hash = NULL; struct darshan_record_ref *ref, *tmp; char mod_buf[DEF_MOD_BUF_SIZE]; @@ -299,7 +298,7 @@ int main(int argc, char **argv) return(-1); } - ret = darshan_log_getmounts(infile, &mnt_pts, &fs_types, &mount_count); + ret = darshan_log_getmounts(infile, &mnt_data_array, &mount_count); if(ret < 0) { darshan_log_close(infile); @@ -308,7 +307,7 @@ int main(int argc, char **argv) return(-1); } - ret = darshan_log_putmounts(outfile, mnt_pts, fs_types, mount_count); + ret = darshan_log_putmounts(outfile, mnt_data_array, mount_count); if(ret < 0) { darshan_log_close(infile); @@ -389,16 +388,8 @@ int main(int argc, char **argv) darshan_log_close(infile); darshan_log_close(outfile); - for(i=0; i 0) - { - free(mnt_pts); - free(fs_types); - } + free(mnt_data_array); HASH_ITER(hlink, rec_hash, ref, tmp) { diff --git a/darshan-util/darshan-logutils.c b/darshan-util/darshan-logutils.c index 5818e523eb72432348f305205c84e37957eccb65..0bbcdd46f0878cddbd71e26f049b9023eb9f3e20 100644 --- a/darshan-util/darshan-logutils.c +++ b/darshan-util/darshan-logutils.c @@ -66,6 +66,7 @@ struct darshan_fd_int_state struct darshan_dz_state dz; }; +static int darshan_mnt_info_cmp(const void *a, const void *b); static int darshan_log_getheader(darshan_fd fd); static int darshan_log_putheader(darshan_fd fd); static int darshan_log_seek(darshan_fd fd, off_t offset); @@ -374,14 +375,14 @@ int darshan_log_putexe(darshan_fd fd, char *buf) /* darshan_log_getmounts() * - * 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 + * retrieves mount table information from the log. Note that mnt_data_array + * is an array that will be allocated by the function and must be + * freed by the caller. count will indicate the size of the array * * returns 0 on success, -1 on failure */ -int darshan_log_getmounts(darshan_fd fd, char*** mnt_pts, - char*** fs_types, int* count) +int darshan_log_getmounts(darshan_fd fd, struct darshan_mnt_info **mnt_data_array, + int* count) { struct darshan_fd_int_state *state = fd->state; char *pos; @@ -416,34 +417,27 @@ int darshan_log_getmounts(darshan_fd fd, char*** mnt_pts, } /* allocate output arrays */ - *mnt_pts = malloc((*count)*sizeof(char*)); - assert(*mnt_pts); - *fs_types = malloc((*count)*sizeof(char*)); - assert(*fs_types); + *mnt_data_array = malloc((*count)*sizeof(**mnt_data_array)); + assert(*mnt_data_array); - /* work backwards through the table and parse each line (except for + /* work through the table and parse each line (except for * first, which holds command line information) */ - while((pos = strrchr(state->exe_mnt_data, '\n')) != NULL) + pos = state->exe_mnt_data; + while((pos = strchr(pos, '\n')) != NULL) { - /* overestimate string lengths */ - (*mnt_pts)[array_index] = malloc(DARSHAN_EXE_LEN); - assert((*mnt_pts)[array_index]); - (*fs_types)[array_index] = malloc(DARSHAN_EXE_LEN); - assert((*fs_types)[array_index]); - - ret = sscanf(++pos, "%s\t%s", (*fs_types)[array_index], - (*mnt_pts)[array_index]); + ret = sscanf(++pos, "%s\t%s", (*mnt_data_array)[array_index].mnt_type, + (*mnt_data_array)[array_index].mnt_path); if(ret != 2) { fprintf(stderr, "Error: poorly formatted mount table in darshan log file.\n"); return(-1); } - pos--; - *pos = '\0'; array_index++; } + qsort(*mnt_data_array, *count, sizeof(**mnt_data_array), darshan_mnt_info_cmp); + return(0); } @@ -456,7 +450,8 @@ int darshan_log_getmounts(darshan_fd fd, char*** mnt_pts, * * returns 0 on success, -1 on failure */ -int darshan_log_putmounts(darshan_fd fd, char** mnt_pts, char** fs_types, int count) +int darshan_log_putmounts(darshan_fd fd, struct darshan_mnt_info *mnt_data_array, + int count) { struct darshan_fd_int_state *state = fd->state; int i; @@ -472,7 +467,7 @@ int darshan_log_putmounts(darshan_fd fd, char** mnt_pts, char** fs_types, int co tmp = mnt_dat; for(i=count-1; i>=0; i--) { - sprintf(line, "\n%s\t%s", fs_types[i], mnt_pts[i]); + sprintf(line, "\n%s\t%s", mnt_data_array[i].mnt_type, mnt_data_array[i].mnt_path); memcpy(tmp, line, strlen(line)); tmp += strlen(line); @@ -827,6 +822,19 @@ void darshan_log_close(darshan_fd fd) /* **************************************************** */ +static int darshan_mnt_info_cmp(const void *a, const void *b) +{ + struct darshan_mnt_info *m_a = (struct darshan_mnt_info *)a; + struct darshan_mnt_info *m_b = (struct darshan_mnt_info *)b; + + if(strlen(m_a->mnt_path) > strlen(m_b->mnt_path)) + return(-1); + else if(strlen(m_a->mnt_path) < strlen(m_b->mnt_path)) + return(1); + else + return(0); +} + /* read the header of the darshan log and set internal fd data structures * NOTE: this is the only portion of the darshan log that is uncompressed * diff --git a/darshan-util/darshan-logutils.h b/darshan-util/darshan-logutils.h index 9c9237b69e4d1bb23ac7d766a211b40577ef9123..1881bb49722bcf66de4e09bfdf323e94c7ef6684 100644 --- a/darshan-util/darshan-logutils.h +++ b/darshan-util/darshan-logutils.h @@ -47,6 +47,12 @@ struct darshan_record_ref UT_hash_handle hlink; }; +struct darshan_mnt_info +{ + char mnt_type[DARSHAN_EXE_LEN]; + char mnt_path[DARSHAN_EXE_LEN]; +}; + /* functions to be implemented by each module for integration with * darshan log file utilities (e.g., parser & convert tools) */ @@ -115,10 +121,10 @@ 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_getmounts(darshan_fd fd, struct darshan_mnt_info **mnt_data_array, + int* count); +int darshan_log_putmounts(darshan_fd fd, struct darshan_mnt_info *mnt_data_array, + int count); int darshan_log_gethash(darshan_fd fd, struct darshan_record_ref **hash); int darshan_log_puthash(darshan_fd fd, struct darshan_record_ref *hash); int darshan_log_getmod(darshan_fd fd, darshan_module_id mod_id, diff --git a/darshan-util/darshan-parser.c b/darshan-util/darshan-parser.c index b5e417d5db4bf4380b43eac39594a9ed56c6e172..ffd338c0201bc86a13b969e9ec0ae8a70948b4d3 100644 --- a/darshan-util/darshan-parser.c +++ b/darshan-util/darshan-parser.c @@ -205,8 +205,7 @@ int main(int argc, char **argv) struct darshan_record_ref *rec_hash = NULL; struct darshan_record_ref *ref, *tmp_ref; int mount_count; - char** mnt_pts; - char** fs_types; + struct darshan_mnt_info *mnt_data_array; time_t tmp_time = 0; char *token; char *save; @@ -248,7 +247,7 @@ int main(int argc, char **argv) } /* get the mount information for this log */ - ret = darshan_log_getmounts(fd, &mnt_pts, &fs_types, &mount_count); + ret = darshan_log_getmounts(fd, &mnt_data_array, &mount_count); if(ret < 0) { darshan_log_close(fd); @@ -318,7 +317,8 @@ int main(int argc, char **argv) printf("# -------------------------------------------------------\n"); for(i=0; irec.name, strlen(mnt_pts[j])) == 0) + if(strncmp(mnt_data_array[j].mnt_path, ref->rec.name, + strlen(mnt_data_array[j].mnt_path)) == 0) { - mnt_pt = mnt_pts[j]; - fs_type = fs_types[j]; + mnt_pt = mnt_data_array[j].mnt_path; + fs_type = mnt_data_array[j].mnt_type; break; } } @@ -633,15 +634,9 @@ cleanup: } /* free mount info */ - for(i=0; i 0) { - free(mnt_pts); - free(fs_types); + free(mnt_data_array); } return(ret);