Commit a658ce00 authored by Philip Carns's avatar Philip Carns

Merge branch 'darshan_core_fprintf' into 'master'

implement internal darshan-core fprintf routine

Closes #251

See merge request darshan/darshan!29
parents f119346b 9c83fab7
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
{ \ { \
__real_ ## __func = dlsym(RTLD_NEXT, #__func); \ __real_ ## __func = dlsym(RTLD_NEXT, #__func); \
if(!(__real_ ## __func)) { \ if(!(__real_ ## __func)) { \
fprintf(stderr, "Darshan failed to map symbol: %s\n", #__func); \ darshan_core_fprintf(stderr, "Darshan failed to map symbol: %s\n", #__func); \
exit(1); \ exit(1); \
} \ } \
} }
...@@ -185,6 +185,15 @@ void *darshan_core_register_record( ...@@ -185,6 +185,15 @@ void *darshan_core_register_record(
*/ */
double darshan_core_wtime(void); double darshan_core_wtime(void);
/* darshan_core_fprintf()
*
* Prints internal Darshan output on a given stream.
*/
void darshan_core_fprintf(
FILE *stream,
const char *format,
...);
/* darshan_core_excluded_path() /* darshan_core_excluded_path()
* *
* Returns true (1) if the given file path 'path' is in Darshan's * Returns true (1) if the given file path 'path' is in Darshan's
......
...@@ -330,8 +330,8 @@ void darshan_core_initialize(int argc, char **argv) ...@@ -330,8 +330,8 @@ void darshan_core_initialize(int argc, char **argv)
MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD);
if(my_rank == 0) if(my_rank == 0)
{ {
fprintf(stderr, "#darshan:<op>\t<nprocs>\t<time>\n"); darshan_core_fprintf(stderr, "#darshan:<op>\t<nprocs>\t<time>\n");
fprintf(stderr, "darshan:init\t%d\t%f\n", nprocs, init_max); darshan_core_fprintf(stderr, "darshan:init\t%d\t%f\n", nprocs, init_max);
} }
} }
...@@ -439,7 +439,7 @@ void darshan_core_shutdown() ...@@ -439,7 +439,7 @@ void darshan_core_shutdown()
if(strlen(logfile_name) == 0) if(strlen(logfile_name) == 0)
{ {
/* failed to generate log file name */ /* failed to generate log file name */
fprintf(stderr, "darshan library warning: unable to determine log file path\n"); darshan_core_fprintf(stderr, "darshan library warning: unable to determine log file path\n");
free(logfile_name); free(logfile_name);
darshan_core_cleanup(final_core); darshan_core_cleanup(final_core);
return; return;
...@@ -476,7 +476,7 @@ void darshan_core_shutdown() ...@@ -476,7 +476,7 @@ void darshan_core_shutdown()
{ {
if(my_rank == 0) if(my_rank == 0)
{ {
fprintf(stderr, "darshan library warning: unable to create log file %s\n", darshan_core_fprintf(stderr, "darshan library warning: unable to create log file %s\n",
logfile_name); logfile_name);
} }
free(logfile_name); free(logfile_name);
...@@ -498,7 +498,7 @@ void darshan_core_shutdown() ...@@ -498,7 +498,7 @@ void darshan_core_shutdown()
final_core->comp_buf, &comp_buf_sz); final_core->comp_buf, &comp_buf_sz);
if(all_ret) if(all_ret)
{ {
fprintf(stderr, "darshan library warning: unable to compress job data\n"); darshan_core_fprintf(stderr, "darshan library warning: unable to compress job data\n");
unlink(logfile_name); unlink(logfile_name);
} }
else else
...@@ -509,7 +509,7 @@ void darshan_core_shutdown() ...@@ -509,7 +509,7 @@ void darshan_core_shutdown()
final_core->comp_buf, comp_buf_sz, MPI_BYTE, &status); final_core->comp_buf, comp_buf_sz, MPI_BYTE, &status);
if(all_ret != MPI_SUCCESS) if(all_ret != MPI_SUCCESS)
{ {
fprintf(stderr, darshan_core_fprintf(stderr,
"darshan library warning: unable to write job data to log file %s\n", "darshan library warning: unable to write job data to log file %s\n",
logfile_name); logfile_name);
unlink(logfile_name); unlink(logfile_name);
...@@ -544,7 +544,7 @@ void darshan_core_shutdown() ...@@ -544,7 +544,7 @@ void darshan_core_shutdown()
{ {
if(my_rank == 0) if(my_rank == 0)
{ {
fprintf(stderr, darshan_core_fprintf(stderr,
"darshan library warning: unable to write record hash to log file %s\n", "darshan library warning: unable to write record hash to log file %s\n",
logfile_name); logfile_name);
unlink(logfile_name); unlink(logfile_name);
...@@ -632,7 +632,7 @@ void darshan_core_shutdown() ...@@ -632,7 +632,7 @@ void darshan_core_shutdown()
{ {
if(my_rank == 0) if(my_rank == 0)
{ {
fprintf(stderr, darshan_core_fprintf(stderr,
"darshan library warning: unable to write %s module data to log file %s\n", "darshan library warning: unable to write %s module data to log file %s\n",
darshan_module_names[i], logfile_name); darshan_module_names[i], logfile_name);
unlink(logfile_name); unlink(logfile_name);
...@@ -670,7 +670,7 @@ void darshan_core_shutdown() ...@@ -670,7 +670,7 @@ void darshan_core_shutdown()
sizeof(struct darshan_header), MPI_BYTE, &status); sizeof(struct darshan_header), MPI_BYTE, &status);
if(all_ret != MPI_SUCCESS) if(all_ret != MPI_SUCCESS)
{ {
fprintf(stderr, "darshan library warning: unable to write header to log file %s\n", darshan_core_fprintf(stderr, "darshan library warning: unable to write header to log file %s\n",
logfile_name); logfile_name);
unlink(logfile_name); unlink(logfile_name);
} }
...@@ -776,18 +776,18 @@ void darshan_core_shutdown() ...@@ -776,18 +776,18 @@ void darshan_core_shutdown()
if(my_rank == 0) if(my_rank == 0)
{ {
fprintf(stderr, "#darshan:<op>\t<nprocs>\t<time>\n"); darshan_core_fprintf(stderr, "#darshan:<op>\t<nprocs>\t<time>\n");
fprintf(stderr, "darshan:log_open\t%d\t%f\n", nprocs, open_slowest); darshan_core_fprintf(stderr, "darshan:log_open\t%d\t%f\n", nprocs, open_slowest);
fprintf(stderr, "darshan:job_write\t%d\t%f\n", nprocs, job_slowest); darshan_core_fprintf(stderr, "darshan:job_write\t%d\t%f\n", nprocs, job_slowest);
fprintf(stderr, "darshan:hash_write\t%d\t%f\n", nprocs, rec_slowest); darshan_core_fprintf(stderr, "darshan:hash_write\t%d\t%f\n", nprocs, rec_slowest);
fprintf(stderr, "darshan:header_write\t%d\t%f\n", nprocs, header_slowest); darshan_core_fprintf(stderr, "darshan:header_write\t%d\t%f\n", nprocs, header_slowest);
for(i = 0; i < DARSHAN_MAX_MODS; i++) for(i = 0; i < DARSHAN_MAX_MODS; i++)
{ {
if(global_mod_use_count[i]) if(global_mod_use_count[i])
fprintf(stderr, "darshan:%s_shutdown\t%d\t%f\n", darshan_module_names[i], darshan_core_fprintf(stderr, "darshan:%s_shutdown\t%d\t%f\n", darshan_module_names[i],
nprocs, mod_slowest[i]); nprocs, mod_slowest[i]);
} }
fprintf(stderr, "darshan:core_shutdown\t%d\t%f\n", nprocs, all_slowest); darshan_core_fprintf(stderr, "darshan:core_shutdown\t%d\t%f\n", nprocs, all_slowest);
} }
} }
...@@ -851,7 +851,7 @@ static void *darshan_init_mmap_log(struct darshan_core_runtime* core, int jobid) ...@@ -851,7 +851,7 @@ static void *darshan_init_mmap_log(struct darshan_core_runtime* core, int jobid)
mmap_fd = open(core->mmap_log_name, O_CREAT|O_RDWR|O_EXCL , 0644); mmap_fd = open(core->mmap_log_name, O_CREAT|O_RDWR|O_EXCL , 0644);
if(mmap_fd < 0) if(mmap_fd < 0)
{ {
fprintf(stderr, "darshan library warning: " darshan_core_fprintf(stderr, "darshan library warning: "
"unable to create darshan log file %s\n", core->mmap_log_name); "unable to create darshan log file %s\n", core->mmap_log_name);
return(NULL); return(NULL);
} }
...@@ -861,7 +861,7 @@ static void *darshan_init_mmap_log(struct darshan_core_runtime* core, int jobid) ...@@ -861,7 +861,7 @@ static void *darshan_init_mmap_log(struct darshan_core_runtime* core, int jobid)
ret = ftruncate(mmap_fd, mmap_size); ret = ftruncate(mmap_fd, mmap_size);
if(ret < 0) if(ret < 0)
{ {
fprintf(stderr, "darshan library warning: " darshan_core_fprintf(stderr, "darshan library warning: "
"unable to allocate darshan log file %s\n", core->mmap_log_name); "unable to allocate darshan log file %s\n", core->mmap_log_name);
close(mmap_fd); close(mmap_fd);
unlink(core->mmap_log_name); unlink(core->mmap_log_name);
...@@ -874,7 +874,7 @@ static void *darshan_init_mmap_log(struct darshan_core_runtime* core, int jobid) ...@@ -874,7 +874,7 @@ static void *darshan_init_mmap_log(struct darshan_core_runtime* core, int jobid)
mmap_p = mmap(NULL, mmap_size, PROT_WRITE, MAP_SHARED, mmap_fd, 0); mmap_p = mmap(NULL, mmap_size, PROT_WRITE, MAP_SHARED, mmap_fd, 0);
if(mmap_p == MAP_FAILED) if(mmap_p == MAP_FAILED)
{ {
fprintf(stderr, "darshan library warning: " darshan_core_fprintf(stderr, "darshan library warning: "
"unable to mmap darshan log file %s\n", core->mmap_log_name); "unable to mmap darshan log file %s\n", core->mmap_log_name);
close(mmap_fd); close(mmap_fd);
unlink(core->mmap_log_name); unlink(core->mmap_log_name);
...@@ -1078,13 +1078,13 @@ static void darshan_get_exe_and_mounts(struct darshan_core_runtime *core, ...@@ -1078,13 +1078,13 @@ static void darshan_get_exe_and_mounts(struct darshan_core_runtime *core,
if(strncmp(env_exclusions,"none",strlen(env_exclusions))>=0) if(strncmp(env_exclusions,"none",strlen(env_exclusions))>=0)
{ {
if (my_rank == 0) if (my_rank == 0)
fprintf(stderr, "Darshan info: no system dirs will be excluded\n"); darshan_core_fprintf(stderr, "Darshan info: no system dirs will be excluded\n");
darshan_path_exclusions[0]=NULL; darshan_path_exclusions[0]=NULL;
} }
else else
{ {
if (my_rank == 0) if (my_rank == 0)
fprintf(stderr, "Darshan info: the following system dirs will be excluded: %s\n", darshan_core_fprintf(stderr, "Darshan info: the following system dirs will be excluded: %s\n",
env_exclusions); env_exclusions);
string = strdup(env_exclusions); string = strdup(env_exclusions);
i = 0; i = 0;
...@@ -1329,7 +1329,7 @@ static void darshan_get_logfile_name(char* logfile_name, int jobid, struct tm* s ...@@ -1329,7 +1329,7 @@ static void darshan_get_logfile_name(char* logfile_name, int jobid, struct tm* s
{ {
if(strlen(user_logfile_name) >= (PATH_MAX-1)) if(strlen(user_logfile_name) >= (PATH_MAX-1))
{ {
fprintf(stderr, "darshan library warning: user log file name too long.\n"); darshan_core_fprintf(stderr, "darshan library warning: user log file name too long.\n");
logfile_name[0] = '\0'; logfile_name[0] = '\0';
} }
else else
...@@ -2133,6 +2133,25 @@ double darshan_core_wtime() ...@@ -2133,6 +2133,25 @@ double darshan_core_wtime()
return(PMPI_Wtime() - darshan_core->wtime_offset); return(PMPI_Wtime() - darshan_core->wtime_offset);
} }
#ifdef DARSHAN_PRELOAD
extern int (*__real_vfprintf)(FILE *stream, const char *format, va_list);
#else
extern int __real_vfprintf(FILE *stream, const char *format, va_list);
#endif
void darshan_core_fprintf(
FILE *stream, const char *format, ...)
{
va_list ap;
MAP_OR_FAIL(vfprintf);
va_start(ap, format);
__real_vfprintf(stream, format, ap);
va_end(ap);
return;
}
int darshan_core_excluded_path(const char *path) int darshan_core_excluded_path(const char *path)
{ {
char *exclude, *include; char *exclude, *include;
......
...@@ -137,7 +137,7 @@ hid_t DARSHAN_DECL(H5Fcreate)(const char *filename, unsigned flags, ...@@ -137,7 +137,7 @@ hid_t DARSHAN_DECL(H5Fcreate)(const char *filename, unsigned flags,
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
if(my_rank == 0) if(my_rank == 0)
{ {
fprintf(stderr, "Darshan HDF5 module error: runtime library version does not match Darshan module.\n"); darshan_core_fprintf(stderr, "Darshan HDF5 module error: runtime library version does not match Darshan module.\n");
} }
return(-1); return(-1);
} }
...@@ -185,7 +185,7 @@ hid_t DARSHAN_DECL(H5Fopen)(const char *filename, unsigned flags, ...@@ -185,7 +185,7 @@ hid_t DARSHAN_DECL(H5Fopen)(const char *filename, unsigned flags,
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank); MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
if(my_rank == 0) if(my_rank == 0)
{ {
fprintf(stderr, "Darshan HDF5 module error: runtime library version does not match Darshan module.\n"); darshan_core_fprintf(stderr, "Darshan HDF5 module error: runtime library version does not match Darshan module.\n");
} }
return(-1); return(-1);
} }
......
...@@ -251,7 +251,7 @@ static void lustre_shutdown( ...@@ -251,7 +251,7 @@ static void lustre_shutdown(
if(rec_ref) if(rec_ref)
rec_ref->record->base_rec.rank = -1; rec_ref->record->base_rec.rank = -1;
else else
fprintf(stderr, "WARNING: unexpected condition in Darshan, possibly triggered by memory corruption. Darshan log may be incorrect.\n"); darshan_core_fprintf(stderr, "WARNING: unexpected condition in Darshan, possibly triggered by memory corruption. Darshan log may be incorrect.\n");
} }
/* sort the array of files descending by rank so that we get all of the /* sort the array of files descending by rank so that we get all of the
......
...@@ -534,7 +534,6 @@ int DARSHAN_DECL(printf)(const char *format, ...) ...@@ -534,7 +534,6 @@ int DARSHAN_DECL(printf)(const char *format, ...)
return(ret); return(ret);
} }
int DARSHAN_DECL(fprintf)(FILE *stream, const char *format, ...) int DARSHAN_DECL(fprintf)(FILE *stream, const char *format, ...)
{ {
int ret; int ret;
......
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