GitLab maintenance scheduled for Today, 2019-12-05, from 17:00 to 18:00 CT - Services will be unavailable during this time.

Commit f21728f3 authored by Shane Snyder's avatar Shane Snyder

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
parent ddb55a27
......@@ -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)
......
......@@ -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++)
......
......@@ -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,
......
......@@ -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)
......
......@@ -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++)
......
......@@ -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++)
......
......@@ -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++)
......
......@@ -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++)
......
......@@ -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++)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment