Commit ad6ea64f authored by Philip Carns's avatar Philip Carns
Browse files

convert stdio module to use new apis

- eliminated 110 SLOC
- untested
parent 1a67e237
...@@ -90,9 +90,6 @@ ...@@ -90,9 +90,6 @@
#include <libgen.h> #include <libgen.h>
#include <pthread.h> #include <pthread.h>
#include "uthash.h"
#include "utlist.h"
#include "darshan.h" #include "darshan.h"
#include "darshan-dynamic.h" #include "darshan-dynamic.h"
...@@ -125,67 +122,14 @@ DARSHAN_FORWARD_DECL(fsetpos, int, (FILE *stream, const fpos_t *pos)); ...@@ -125,67 +122,14 @@ DARSHAN_FORWARD_DECL(fsetpos, int, (FILE *stream, const fpos_t *pos));
DARSHAN_FORWARD_DECL(fsetpos64, int, (FILE *stream, const fpos_t *pos)); DARSHAN_FORWARD_DECL(fsetpos64, int, (FILE *stream, const fpos_t *pos));
DARSHAN_FORWARD_DECL(rewind, void, (FILE *stream)); DARSHAN_FORWARD_DECL(rewind, void, (FILE *stream));
/* The stdio_file_runtime structure maintains necessary runtime metadata /* structure to track stdio stats at runtime */
* for the STDIO file record (darshan_stdio_record structure, defined in struct stdio_file_record_ref
* darshan-stdio-log-format.h) pointed to by 'file_record'. This metadata
* assists with the instrumenting of specific statistics in the file record.
* 'hlink' is a hash table link structure used to add/remove this record
* from the hash table of STDIO file records for this process.
*
* RATIONALE: the STDIO module needs to track some stateful, volatile
* information about each open file (like the current file offset, most recent
* access time, etc.) to aid in instrumentation, but this information can't be
* stored in the darshan_stdio_record struct because we don't want it to appear in
* the final darshan log file. We therefore associate a stdio_file_runtime
* struct with each darshan_stdio_record struct in order to track this information.
*
* NOTE: There is a one-to-one mapping of stdio_file_runtime structs to
* darshan_stdio_record structs.
*
* NOTE: The stdio_file_runtime struct contains a pointer to a darshan_stdio_record
* struct (see the *file_record member) rather than simply embedding an entire
* darshan_stdio_record struct. This is done so that all of the darshan_stdio_record
* structs can be kept contiguous in memory as a single array to simplify
* reduction, compression, and storage.
*/
struct stdio_file_runtime
{ {
struct darshan_stdio_record* file_record; struct darshan_stdio_file* file_rec;
int64_t offset; int64_t offset;
double last_meta_end; double last_meta_end;
double last_read_end; double last_read_end;
double last_write_end; double last_write_end;
UT_hash_handle hlink;
};
/* The stdio_file_runtime_ref structure is used to associate a STDIO
* stream with an already existing STDIO file record. This is
* necessary as many STDIO I/O functions take only an input stream,
* but STDIO file records are indexed by their full file paths (i.e., darshan
* record identifiers for STDIO files are created by hashing the file path).
* In other words, this structure is necessary as it allows us to look up a
* file record either by a pathname (stdio_file_runtime) or by STDIO stream
* (stdio_file_runtime_ref), depending on which parameters are
* available. This structure includes another hash table link, since separate
* hashes are maintained for stdio_file_runtime structures and stdio_file_runtime_ref
* structures.
*
* RATIONALE: In theory the FILE* information could be included in the
* stdio_file_runtime struct rather than in a separate structure here. The
* reason we don't do that is because the same file could be opened multiple
* times by a given process with different stream pointers and thus
* simulataneously referenced using different stream pointers. This practice is
* not common, but we must support it.
*
* NOTE: there are potentially multiple stdio_file_runtime_ref structures
* referring to a single stdio_file_runtime structure. Most of the time there is
* only one, however.
*/
struct stdio_file_runtime_ref
{
struct stdio_file_runtime* file;
FILE* stream;
UT_hash_handle hlink;
}; };
/* The stdio_runtime structure maintains necessary state for storing /* The stdio_runtime structure maintains necessary state for storing
...@@ -194,12 +138,9 @@ struct stdio_file_runtime_ref ...@@ -194,12 +138,9 @@ struct stdio_file_runtime_ref
*/ */
struct stdio_runtime struct stdio_runtime
{ {
struct stdio_file_runtime* file_runtime_array; void *rec_id_hash;
struct darshan_stdio_record* file_record_array; void *stream_hash;
int file_array_size; int file_rec_count;
int file_array_ndx;
struct stdio_file_runtime* file_hash;
struct stdio_file_runtime_ref* stream_hash;
}; };
static struct stdio_runtime *stdio_runtime = NULL; static struct stdio_runtime *stdio_runtime = NULL;
...@@ -209,82 +150,101 @@ static int darshan_mem_alignment = 1; ...@@ -209,82 +150,101 @@ static int darshan_mem_alignment = 1;
static int my_rank = -1; static int my_rank = -1;
static void stdio_runtime_initialize(void); static void stdio_runtime_initialize(void);
static struct stdio_file_runtime* stdio_file_by_name(const char *name); static void stdio_shutdown(
static struct stdio_file_runtime* stdio_file_by_name_setstream(const char* name, FILE *stream); MPI_Comm mod_comm,
static struct stdio_file_runtime* stdio_file_by_stream(FILE* stream); darshan_record_id *shared_recs,
static void stdio_file_close_stream(FILE *stream); int shared_rec_count,
void **stdio_buf,
static void stdio_begin_shutdown(void); int *stdio_buf_sz);
static void stdio_get_output_data(MPI_Comm mod_comm, darshan_record_id *shared_recs,
int shared_rec_count, void **stdio_buf, int *stdio_buf_sz);
static void stdio_shutdown(void);
static void stdio_record_reduction_op(void* infile_v, void* inoutfile_v, static void stdio_record_reduction_op(void* infile_v, void* inoutfile_v,
int *len, MPI_Datatype *datatype); int *len, MPI_Datatype *datatype);
static int stdio_record_compare(const void* a, const void* b); static struct stdio_file_record_ref *stdio_track_new_file_record(
darshan_record_id rec_id, const char *path);
static void stdio_cleanup_runtime();
#define STDIO_LOCK() pthread_mutex_lock(&stdio_runtime_mutex) #define STDIO_LOCK() pthread_mutex_lock(&stdio_runtime_mutex)
#define STDIO_UNLOCK() pthread_mutex_unlock(&stdio_runtime_mutex) #define STDIO_UNLOCK() pthread_mutex_unlock(&stdio_runtime_mutex)
#define STDIO_PRE_RECORD() do { \
STDIO_LOCK(); \
if(!stdio_runtime && !instrumentation_disabled) stdio_runtime_initialize(); \
if(!stdio_runtime) { \
STDIO_UNLOCK(); \
return(ret); \
} \
} while(0)
#define STDIO_POST_RECORD() do { \
STDIO_UNLOCK(); \
} while(0)
#define STDIO_RECORD_OPEN(__ret, __path, __tm1, __tm2) do { \ #define STDIO_RECORD_OPEN(__ret, __path, __tm1, __tm2) do { \
struct stdio_file_runtime* file; \ darshan_record_id rec_id; \
char* exclude; \ struct stdio_file_record_ref* rec_ref; \
int tmp_index = 0; \ char *newpath; \
if(__ret == NULL) break; \ if(__ret == NULL) break; \
while((exclude = darshan_path_exclusions[tmp_index])) { \ newpath = darshan_clean_file_path(__path); \
if(!(strncmp(exclude, __path, strlen(exclude)))) \ if(!newpath) newpath = (char*)__path; \
break; \ if(darshan_core_excluded_path(newpath)) { \
tmp_index++; \ if(newpath != (char*)__path) free(newpath); \
break; \
} \ } \
if(exclude) break; \ rec_id = darshan_core_gen_record_id(newpath); \
file = stdio_file_by_name_setstream(__path, __ret); \ rec_ref = darshan_lookup_record_ref(stdio_runtime->rec_id_hash, &rec_id, sizeof(darshan_record_id)); \
if(!file) break; \ if(!rec_ref) rec_ref = stdio_track_new_file_record(rec_id, newpath); \
file->offset = 0; \ if(!rec_ref) { \
file->file_record->counters[STDIO_OPENS] += 1; \ if(newpath != (char*)__path) free(newpath); \
if(file->file_record->fcounters[STDIO_F_OPEN_START_TIMESTAMP] == 0 || \ break; \
file->file_record->fcounters[STDIO_F_OPEN_START_TIMESTAMP] > __tm1) \ } \
file->file_record->fcounters[STDIO_F_OPEN_START_TIMESTAMP] = __tm1; \ rec_ref->offset = 0; \
file->file_record->fcounters[STDIO_F_OPEN_END_TIMESTAMP] = __tm2; \ rec_ref->file_rec->counters[STDIO_OPENS] += 1; \
DARSHAN_TIMER_INC_NO_OVERLAP(file->file_record->fcounters[STDIO_F_META_TIME], __tm1, __tm2, file->last_meta_end); \ if(rec_ref->file_rec->fcounters[STDIO_F_OPEN_START_TIMESTAMP] == 0 || \
rec_ref->file_rec->fcounters[STDIO_F_OPEN_START_TIMESTAMP] > __tm1) \
rec_ref->file_rec->fcounters[STDIO_F_OPEN_START_TIMESTAMP] = __tm1; \
rec_ref->file_rec->fcounters[STDIO_F_OPEN_END_TIMESTAMP] = __tm2; \
DARSHAN_TIMER_INC_NO_OVERLAP(rec_ref->file_rec->fcounters[STDIO_F_META_TIME], __tm1, __tm2, rec_ref->last_meta_end); \
darshan_add_record_ref(&(stdio_runtime->stream_hash), &(__ret), sizeof(__ret), rec_ref); \
if(newpath != (char*)__path) free(newpath); \
} while(0) } while(0)
#define STDIO_RECORD_READ(__fp, __bytes, __tm1, __tm2) do{ \ #define STDIO_RECORD_READ(__fp, __bytes, __tm1, __tm2) do{ \
struct stdio_file_record_ref* rec_ref; \
int64_t this_offset; \ int64_t this_offset; \
struct stdio_file_runtime* file; \ rec_ref = darshan_lookup_record_ref(stdio_runtime->stream_hash, &(__fp), sizeof(int)); \
file = stdio_file_by_stream(__fp); \ if(!rec_ref) break; \
if(!file) break; \ this_offset = rec_ref->offset; \
this_offset = file->offset; \ rec_ref->offset = this_offset + __bytes; \
file->offset = this_offset + __bytes; \ if(rec_ref->file_rec->counters[STDIO_MAX_BYTE_READ] < (this_offset + __bytes - 1)) \
if(file->file_record->counters[STDIO_MAX_BYTE_READ] < (this_offset + __bytes - 1)) \ rec_ref->file_rec->counters[STDIO_MAX_BYTE_READ] = (this_offset + __bytes - 1); \
file->file_record->counters[STDIO_MAX_BYTE_READ] = (this_offset + __bytes - 1); \ rec_ref->file_rec->counters[STDIO_BYTES_READ] += __bytes; \
file->file_record->counters[STDIO_BYTES_READ] += __bytes; \ rec_ref->file_rec->counters[STDIO_READS] += 1; \
file->file_record->counters[STDIO_READS] += 1; \ if(rec_ref->file_rec->fcounters[STDIO_F_READ_START_TIMESTAMP] == 0 || \
if(file->file_record->fcounters[STDIO_F_READ_START_TIMESTAMP] == 0 || \ rec_ref->file_rec->fcounters[STDIO_F_READ_START_TIMESTAMP] > __tm1) \
file->file_record->fcounters[STDIO_F_READ_START_TIMESTAMP] > __tm1) \ rec_ref->file_rec->fcounters[STDIO_F_READ_START_TIMESTAMP] = __tm1; \
file->file_record->fcounters[STDIO_F_READ_START_TIMESTAMP] = __tm1; \ rec_ref->file_rec->fcounters[STDIO_F_READ_END_TIMESTAMP] = __tm2; \
file->file_record->fcounters[STDIO_F_READ_END_TIMESTAMP] = __tm2; \ DARSHAN_TIMER_INC_NO_OVERLAP(rec_ref->file_rec->fcounters[STDIO_F_READ_TIME], __tm1, __tm2, rec_ref->last_write_end); \
DARSHAN_TIMER_INC_NO_OVERLAP(file->file_record->fcounters[STDIO_F_READ_TIME], __tm1, __tm2, file->last_write_end); \
} while(0) } while(0)
#define STDIO_RECORD_WRITE(__fp, __bytes, __tm1, __tm2, __fflush_flag) do{ \ #define STDIO_RECORD_WRITE(__fp, __bytes, __tm1, __tm2, __fflush_flag) do{ \
struct stdio_file_record_ref* rec_ref; \
int64_t this_offset; \ int64_t this_offset; \
struct stdio_file_runtime* file; \ rec_ref = darshan_lookup_record_ref(stdio_runtime->stream_hash, &(__fp), sizeof(int)); \
file = stdio_file_by_stream(__fp); \ if(!rec_ref) break; \
if(!file) break; \ this_offset = rec_ref->offset; \
this_offset = file->offset; \ rec_ref->offset = this_offset + __bytes; \
file->offset = this_offset + __bytes; \ if(rec_ref->file_rec->counters[STDIO_MAX_BYTE_WRITTEN] < (this_offset + __bytes - 1)) \
if(file->file_record->counters[STDIO_MAX_BYTE_WRITTEN] < (this_offset + __bytes - 1)) \ rec_ref->file_rec->counters[STDIO_MAX_BYTE_WRITTEN] = (this_offset + __bytes - 1); \
file->file_record->counters[STDIO_MAX_BYTE_WRITTEN] = (this_offset + __bytes - 1); \ rec_ref->file_rec->counters[STDIO_BYTES_WRITTEN] += __bytes; \
file->file_record->counters[STDIO_BYTES_WRITTEN] += __bytes; \
if(__fflush_flag) \ if(__fflush_flag) \
file->file_record->counters[STDIO_FLUSHES] += 1; \ rec_ref->file_rec->counters[STDIO_FLUSHES] += 1; \
else \ else \
file->file_record->counters[STDIO_WRITES] += 1; \ rec_ref->file_rec->counters[STDIO_WRITES] += 1; \
if(file->file_record->fcounters[STDIO_F_WRITE_START_TIMESTAMP] == 0 || \ if(rec_ref->file_rec->fcounters[STDIO_F_WRITE_START_TIMESTAMP] == 0 || \
file->file_record->fcounters[STDIO_F_WRITE_START_TIMESTAMP] > __tm1) \ rec_ref->file_rec->fcounters[STDIO_F_WRITE_START_TIMESTAMP] > __tm1) \
file->file_record->fcounters[STDIO_F_WRITE_START_TIMESTAMP] = __tm1; \ rec_ref->file_rec->fcounters[STDIO_F_WRITE_START_TIMESTAMP] = __tm1; \
file->file_record->fcounters[STDIO_F_WRITE_END_TIMESTAMP] = __tm2; \ rec_ref->file_rec->fcounters[STDIO_F_WRITE_END_TIMESTAMP] = __tm2; \
DARSHAN_TIMER_INC_NO_OVERLAP(file->file_record->fcounters[STDIO_F_WRITE_TIME], __tm1, __tm2, file->last_write_end); \ DARSHAN_TIMER_INC_NO_OVERLAP(rec_ref->file_rec->fcounters[STDIO_F_WRITE_TIME], __tm1, __tm2, rec_ref->last_write_end); \
} while(0) } while(0)
FILE* DARSHAN_DECL(fopen)(const char *path, const char *mode) FILE* DARSHAN_DECL(fopen)(const char *path, const char *mode)
...@@ -298,10 +258,9 @@ FILE* DARSHAN_DECL(fopen)(const char *path, const char *mode) ...@@ -298,10 +258,9 @@ FILE* DARSHAN_DECL(fopen)(const char *path, const char *mode)
ret = __real_fopen(path, mode); ret = __real_fopen(path, mode);
tm2 = darshan_core_wtime(); tm2 = darshan_core_wtime();
STDIO_LOCK(); STDIO_PRE_RECORD();
stdio_runtime_initialize();
STDIO_RECORD_OPEN(ret, path, tm1, tm2); STDIO_RECORD_OPEN(ret, path, tm1, tm2);
STDIO_UNLOCK(); STDIO_POST_RECORD();
return(ret); return(ret);
} }
...@@ -317,10 +276,9 @@ FILE* DARSHAN_DECL(fopen64)(const char *path, const char *mode) ...@@ -317,10 +276,9 @@ FILE* DARSHAN_DECL(fopen64)(const char *path, const char *mode)
ret = __real_fopen64(path, mode); ret = __real_fopen64(path, mode);
tm2 = darshan_core_wtime(); tm2 = darshan_core_wtime();
STDIO_LOCK(); STDIO_PRE_RECORD();
stdio_runtime_initialize();
STDIO_RECORD_OPEN(ret, path, tm1, tm2); STDIO_RECORD_OPEN(ret, path, tm1, tm2);
STDIO_UNLOCK(); STDIO_POST_RECORD();
return(ret); return(ret);
} }
...@@ -336,10 +294,9 @@ FILE* DARSHAN_DECL(fdopen)(int fd, const char *mode) ...@@ -336,10 +294,9 @@ FILE* DARSHAN_DECL(fdopen)(int fd, const char *mode)
ret = __real_fdopen(fd, mode); ret = __real_fdopen(fd, mode);
tm2 = darshan_core_wtime(); tm2 = darshan_core_wtime();
STDIO_LOCK(); STDIO_PRE_RECORD();
stdio_runtime_initialize();
STDIO_RECORD_OPEN(ret, "UNKNOWN-FDOPEN", tm1, tm2); STDIO_RECORD_OPEN(ret, "UNKNOWN-FDOPEN", tm1, tm2);
STDIO_UNLOCK(); STDIO_POST_RECORD();
return(ret); return(ret);
} }
...@@ -355,10 +312,9 @@ FILE* DARSHAN_DECL(freopen)(const char *path, const char *mode, FILE *stream) ...@@ -355,10 +312,9 @@ FILE* DARSHAN_DECL(freopen)(const char *path, const char *mode, FILE *stream)
ret = __real_freopen(path, mode, stream); ret = __real_freopen(path, mode, stream);
tm2 = darshan_core_wtime(); tm2 = darshan_core_wtime();
STDIO_LOCK(); STDIO_PRE_RECORD();
stdio_runtime_initialize();
STDIO_RECORD_OPEN(ret, path, tm1, tm2); STDIO_RECORD_OPEN(ret, path, tm1, tm2);
STDIO_UNLOCK(); STDIO_POST_RECORD();
return(ret); return(ret);
} }
...@@ -374,10 +330,9 @@ FILE* DARSHAN_DECL(freopen64)(const char *path, const char *mode, FILE *stream) ...@@ -374,10 +330,9 @@ FILE* DARSHAN_DECL(freopen64)(const char *path, const char *mode, FILE *stream)
ret = __real_freopen64(path, mode, stream); ret = __real_freopen64(path, mode, stream);
tm2 = darshan_core_wtime(); tm2 = darshan_core_wtime();
STDIO_LOCK(); STDIO_PRE_RECORD();
stdio_runtime_initialize();
STDIO_RECORD_OPEN(ret, path, tm1, tm2); STDIO_RECORD_OPEN(ret, path, tm1, tm2);
STDIO_UNLOCK(); STDIO_POST_RECORD();
return(ret); return(ret);
} }
...@@ -394,20 +349,19 @@ int DARSHAN_DECL(fflush)(FILE *fp) ...@@ -394,20 +349,19 @@ int DARSHAN_DECL(fflush)(FILE *fp)
ret = __real_fflush(fp); ret = __real_fflush(fp);
tm2 = darshan_core_wtime(); tm2 = darshan_core_wtime();
STDIO_LOCK(); STDIO_PRE_RECORD();
stdio_runtime_initialize();
if(ret >= 0) if(ret >= 0)
STDIO_RECORD_WRITE(fp, 0, tm1, tm2, 1); STDIO_RECORD_WRITE(fp, 0, tm1, tm2, 1);
STDIO_UNLOCK(); STDIO_POST_RECORD();
return(ret); return(ret);
} }
int DARSHAN_DECL(fclose)(FILE *fp) int DARSHAN_DECL(fclose)(FILE *fp)
{ {
struct stdio_file_runtime* file;
double tm1, tm2; double tm1, tm2;
int ret; int ret;
struct stdio_file_record_ref *rec_ref;
MAP_OR_FAIL(fclose); MAP_OR_FAIL(fclose);
...@@ -415,21 +369,20 @@ int DARSHAN_DECL(fclose)(FILE *fp) ...@@ -415,21 +369,20 @@ int DARSHAN_DECL(fclose)(FILE *fp)
ret = __real_fclose(fp); ret = __real_fclose(fp);
tm2 = darshan_core_wtime(); tm2 = darshan_core_wtime();
STDIO_LOCK(); STDIO_PRE_RECORD();
stdio_runtime_initialize(); rec_ref = darshan_lookup_record_ref(stdio_runtime->stream_hash, &fp, sizeof(fp));
file = stdio_file_by_stream(fp); if(rec_ref)
if(file)
{ {
if(file->file_record->fcounters[STDIO_F_CLOSE_START_TIMESTAMP] == 0 || if(rec_ref->file_rec->fcounters[STDIO_F_CLOSE_START_TIMESTAMP] == 0 ||
file->file_record->fcounters[STDIO_F_CLOSE_START_TIMESTAMP] > tm1) rec_ref->file_rec->fcounters[STDIO_F_CLOSE_START_TIMESTAMP] > tm1)
file->file_record->fcounters[STDIO_F_CLOSE_START_TIMESTAMP] = tm1; rec_ref->file_rec->fcounters[STDIO_F_CLOSE_START_TIMESTAMP] = tm1;
file->file_record->fcounters[STDIO_F_CLOSE_END_TIMESTAMP] = tm2; rec_ref->file_rec->fcounters[STDIO_F_CLOSE_END_TIMESTAMP] = tm2;
DARSHAN_TIMER_INC_NO_OVERLAP( DARSHAN_TIMER_INC_NO_OVERLAP(
file->file_record->fcounters[STDIO_F_META_TIME], rec_ref->file_rec->fcounters[STDIO_F_META_TIME],
tm1, tm2, file->last_meta_end); tm1, tm2, rec_ref->last_meta_end);
stdio_file_close_stream(fp); darshan_delete_record_ref(&(stdio_runtime->stream_hash), &fp, sizeof(fp));
} }
STDIO_UNLOCK(); STDIO_POST_RECORD();
return(ret); return(ret);
} }
...@@ -445,11 +398,10 @@ size_t DARSHAN_DECL(fwrite)(const void *ptr, size_t size, size_t nmemb, FILE *st ...@@ -445,11 +398,10 @@ size_t DARSHAN_DECL(fwrite)(const void *ptr, size_t size, size_t nmemb, FILE *st
ret = __real_fwrite(ptr, size, nmemb, stream); ret = __real_fwrite(ptr, size, nmemb, stream);
tm2 = darshan_core_wtime(); tm2 = darshan_core_wtime();
STDIO_LOCK(); STDIO_PRE_RECORD();
stdio_runtime_initialize();
if(ret > 0) if(ret > 0)
STDIO_RECORD_WRITE(stream, size*ret, tm1, tm2, 0); STDIO_RECORD_WRITE(stream, size*ret, tm1, tm2, 0);
STDIO_UNLOCK(); STDIO_POST_RECORD();
return(ret); return(ret);
} }
...@@ -466,11 +418,10 @@ int DARSHAN_DECL(fputc)(int c, FILE *stream) ...@@ -466,11 +418,10 @@ int DARSHAN_DECL(fputc)(int c, FILE *stream)
ret = __real_fputc(c, stream); ret = __real_fputc(c, stream);
tm2 = darshan_core_wtime(); tm2 = darshan_core_wtime();
STDIO_LOCK(); STDIO_PRE_RECORD();
stdio_runtime_initialize();
if(ret != EOF) if(ret != EOF)
STDIO_RECORD_WRITE(stream, 1, tm1, tm2, 0); STDIO_RECORD_WRITE(stream, 1, tm1, tm2, 0);
STDIO_UNLOCK(); STDIO_POST_RECORD();
return(ret); return(ret);
} }
...@@ -486,11 +437,10 @@ int DARSHAN_DECL(putw)(int w, FILE *stream) ...@@ -486,11 +437,10 @@ int DARSHAN_DECL(putw)(int w, FILE *stream)
ret = __real_putw(w, stream); ret = __real_putw(w, stream);
tm2 = darshan_core_wtime(); tm2 = darshan_core_wtime();
STDIO_LOCK(); STDIO_PRE_RECORD();
stdio_runtime_initialize();
if(ret != EOF) if(ret != EOF)
STDIO_RECORD_WRITE(stream, sizeof(int), tm1, tm2, 0); STDIO_RECORD_WRITE(stream, sizeof(int), tm1, tm2, 0);
STDIO_UNLOCK(); STDIO_POST_RECORD();
return(ret); return(ret);
} }
...@@ -508,11 +458,10 @@ int DARSHAN_DECL(fputs)(const char *s, FILE *stream) ...@@ -508,11 +458,10 @@ int DARSHAN_DECL(fputs)(const char *s, FILE *stream)
ret = __real_fputs(s, stream); ret = __real_fputs(s, stream);
tm2 = darshan_core_wtime(); tm2 = darshan_core_wtime();
STDIO_LOCK(); STDIO_PRE_RECORD();
stdio_runtime_initialize();
if(ret != EOF && ret > 0) if(ret != EOF && ret > 0)
STDIO_RECORD_WRITE(stream, strlen(s), tm1, tm2, 0); STDIO_RECORD_WRITE(stream, strlen(s), tm1, tm2, 0);
STDIO_UNLOCK(); STDIO_POST_RECORD();
return(ret); return(ret);
} }
...@@ -531,11 +480,10 @@ int DARSHAN_DECL(vfprintf)(FILE *stream, const char *format, va_list ap) ...@@ -531,11 +480,10 @@ int DARSHAN_DECL(vfprintf)(FILE *stream, const char *format, va_list ap)
end_off = ftell(stream); end_off = ftell(stream);
tm2 = darshan_core_wtime(); tm2 = darshan_core_wtime();
STDIO_LOCK(); STDIO_PRE_RECORD();
stdio_runtime_initialize();
if(ret > 0) if(ret > 0)
STDIO_RECORD_WRITE(stream, (end_off-start_off), tm1, tm2, 0); STDIO_RECORD_WRITE(stream, (end_off-start_off), tm1, tm2, 0);
STDIO_UNLOCK(); STDIO_POST_RECORD();
return(ret); return(ret);
} }
...@@ -561,11 +509,10 @@ int DARSHAN_DECL(fprintf)(FILE *stream, const char *format, ...) ...@@ -561,11 +509,10 @@ int DARSHAN_DECL(fprintf)(FILE *stream, const char *format, ...)
end_off = ftell(stream); end_off = ftell(stream);
tm2 = darshan_core_wtime(); tm2 = darshan_core_wtime();
STDIO_LOCK(); STDIO_PRE_RECORD();
stdio_runtime_initialize();
if(ret > 0) if(ret > 0)
STDIO_RECORD_WRITE(stream, (end_off-start_off), tm1, tm2, 0); STDIO_RECORD_WRITE(stream, (end_off-start_off), tm1, tm2, 0);
STDIO_UNLOCK(); STDIO_POST_RECORD();
return(ret); return(ret);
} }
...@@ -581,11 +528,10 @@ size_t DARSHAN_DECL(fread)(void *ptr, size_t size, size_t nmemb, FILE *stream) ...@@ -581,11 +528,10 @@ size_t DARSHAN_DECL(fread)(void *ptr, size_t size, size_t nmemb, FILE *stream)
ret = __real_fread(ptr, size, nmemb, stream); ret = __real_fread(ptr, size, nmemb, stream);
tm2 = darshan_core_wtime(); tm2 = darshan_core_wtime();
STDIO_LOCK(); STDIO_PRE_RECORD();
stdio_runtime_initialize();
if(ret > 0) if(ret > 0)
STDIO_RECORD_READ(stream, size*ret, tm1, tm2); STDIO_RECORD_READ(stream, size*ret, tm1, tm2);
STDIO_UNLOCK(); STDIO_POST_RECORD();
return(ret); return(ret);
} }
...@@ -601,11 +547,10 @@ size_t DARSHAN_DECL(fgetc)(FILE *stream) ...@@ -601,11 +547,10 @@ size_t DARSHAN_DECL(fgetc)(FILE *stream)
ret = __real_fgetc(stream); ret = __real_fgetc(stream);
tm2 = darshan_core_wtime(); tm2 = darshan_core_wtime();
STDIO_LOCK(); STDIO_PRE_RECORD();
stdio_runtime_initialize();
if(ret != EOF) if(ret != EOF)
STDIO_RECORD_READ(stream, 1, tm1, tm2); STDIO_RECORD_READ(stream, 1, tm1, tm2);
STDIO_UNLOCK(); STDIO_POST_RECORD();
return(ret); return(ret);
} }
...@@ -622,11 +567,10 @@ size_t DARSHAN_DECL(_IO_getc)(FILE *stream) ...@@ -622,11 +567,10 @@ size_t DARSHAN_DECL(_IO_getc)(FILE *stream)
ret = __real__IO_getc(stream); ret = __real__IO_getc(stream);
tm2 = darshan_core_wtime(); tm2 = darshan_core_wtime();
STDIO_LOCK(); STDIO_PRE_RECORD();
stdio_runtime_initialize();
if(ret != EOF) if(ret != EOF)
STDIO_RECORD_READ(stream, 1, tm1, tm2); STDIO_RECORD_READ(stream, 1, tm1, tm2);
STDIO_UNLOCK(); STDIO_POST_RECORD();
return(ret); return(ret);
} }
...@@ -643,11 +587,10 @@ size_t DARSHAN_DECL(_IO_putc)(int c, FILE *stream) ...@@ -643,11 +587,10 @@ size_t DARSHAN_DECL(_IO_putc)(int c, FILE *stream)
ret = __real__IO_putc(c, stream); ret = __real__IO_putc(c, stream);
tm2 = da