From d72958deef26f9e8b81f83ecd8f0a627e20c5c9e Mon Sep 17 00:00:00 2001 From: Shane Snyder Date: Tue, 31 Mar 2015 17:05:04 -0500 Subject: [PATCH] more posix wrappers: stat family --- darshan-posix-log-format.h | 6 +- darshan-runtime/darshan-posix-ld-opts | 6 + darshan-runtime/lib/darshan-posix.c | 197 +++++++++++++++++++++++++- darshan-util/darshan-posix-parser.c | 6 + 4 files changed, 210 insertions(+), 5 deletions(-) diff --git a/darshan-posix-log-format.h b/darshan-posix-log-format.h index 23e8b29..e699ab5 100644 --- a/darshan-posix-log-format.h +++ b/darshan-posix-log-format.h @@ -15,8 +15,8 @@ enum darshan_posix_indices POSIX_READS, /* count of posix reads */ POSIX_WRITES, /* count of posix writes */ POSIX_SEEKS, /* count of posix seeks */ -#if 0 POSIX_STATS, /* count of posix stat/lstat/fstats */ +#if 0 POSIX_MMAPS, /* count of posix mmaps */ #endif POSIX_FOPENS, /* count of posix fopens */ @@ -39,8 +39,8 @@ enum darshan_posix_indices MEM_NOT_ALIGNED, /* count of accesses not mem aligned */ MEM_ALIGNMENT, /* mem alignment in bytes */ FILE_NOT_ALIGNED, /* count of accesses not file aligned */ - FILE_ALIGNMENT, /* file alignment in bytes */ #endif + FILE_ALIGNMENT, /* file alignment in bytes */ POSIX_MAX_READ_TIME_SIZE, POSIX_MAX_WRITE_TIME_SIZE, #if 0 @@ -84,7 +84,9 @@ enum darshan_posix_indices ACCESS3_COUNT, ACCESS4_COUNT, DEVICE, /* device id reported by stat */ +#endif SIZE_AT_OPEN, +#if 0 FASTEST_RANK, FASTEST_RANK_BYTES, SLOWEST_RANK, diff --git a/darshan-runtime/darshan-posix-ld-opts b/darshan-runtime/darshan-posix-ld-opts index 581d6b9..dea658e 100644 --- a/darshan-runtime/darshan-posix-ld-opts +++ b/darshan-runtime/darshan-posix-ld-opts @@ -17,6 +17,12 @@ --wrap=lseek --wrap=lseek64 --wrap=fseek +--wrap=__xstat +--wrap=__xstat64 +--wrap=__lxstat +--wrap=__lxstat64 +--wrap=__fxstat +--wrap=__fxstat64 --wrap=fsync --wrap=fdatasync --wrap=close diff --git a/darshan-runtime/lib/darshan-posix.c b/darshan-runtime/lib/darshan-posix.c index 94a800b..41b2838 100644 --- a/darshan-runtime/lib/darshan-posix.c +++ b/darshan-runtime/lib/darshan-posix.c @@ -56,12 +56,20 @@ DARSHAN_FORWARD_DECL(fwrite, size_t, (const void *ptr, size_t size, size_t nmemb DARSHAN_FORWARD_DECL(lseek, off_t, (int fd, off_t offset, int whence)); DARSHAN_FORWARD_DECL(lseek64, off64_t, (int fd, off64_t offset, int whence)); DARSHAN_FORWARD_DECL(fseek, int, (FILE *stream, long offset, int whence)); -/* stats */ -/* mmaps */ +DARSHAN_FORWARD_DECL(__xstat, int, (int vers, const char* path, struct stat *buf)); +DARSHAN_FORWARD_DECL(__xstat64, int, (int vers, const char* path, struct stat64 *buf)); +DARSHAN_FORWARD_DECL(__lxstat, int, (int vers, const char* path, struct stat *buf)); +DARSHAN_FORWARD_DECL(__lxstat64, int, (int vers, const char* path, struct stat64 *buf)); +DARSHAN_FORWARD_DECL(__fxstat, int, (int vers, int fd, struct stat *buf)); +DARSHAN_FORWARD_DECL(__fxstat64, int, (int vers, int fd, struct stat64 *buf)); +/* TODO mmaps */ DARSHAN_FORWARD_DECL(fsync, int, (int fd)); DARSHAN_FORWARD_DECL(fdatasync, int, (int fd)); DARSHAN_FORWARD_DECL(close, int, (int fd)); DARSHAN_FORWARD_DECL(fclose, int, (FILE *fp)); +/* TODO mkstemp */ +/* TODO aio */ +/* TODO listio */ static void posix_runtime_initialize(void); static struct posix_file_runtime* posix_file_by_name(const char *name); @@ -275,6 +283,33 @@ static int my_rank = -1; DARSHAN_COUNTER_SET(file->file_record, POSIX_MAX_WRITE_TIME_SIZE, __ret); } \ } while(0) +#define POSIX_LOOKUP_RECORD_STAT(__path, __statbuf, __tm1, __tm2) do { \ + char* exclude; \ + int tmp_index = 0; \ + struct posix_file_runtime* file; \ + while((exclude = darshan_path_exclusions[tmp_index])) { \ + if(!(strncmp(exclude, __path, strlen(exclude)))) \ + break; \ + tmp_index++; \ + } \ + if(exclude) break; \ + file = posix_file_by_name(__path); \ + if(file) \ + { \ + POSIX_RECORD_STAT(file, __statbuf, __tm1, __tm2); \ + } \ +} while(0) + +#define POSIX_RECORD_STAT(__file, __statbuf, __tm1, __tm2) do { \ + if(!DARSHAN_COUNTER_VALUE((__file)->file_record, POSIX_STATS) && !DARSHAN_COUNTER_VALUE((__file)->file_record, POSIX_OPENS)){ \ + DARSHAN_COUNTER_SET((__file)->file_record, FILE_ALIGNMENT, (__statbuf)->st_blksize); \ + DARSHAN_COUNTER_SET((__file)->file_record, SIZE_AT_OPEN, (__statbuf)->st_size); \ + }\ + (__file)->file_record->rank = my_rank; \ + DARSHAN_COUNTER_F_INC_NO_OVERLAP((__file)->file_record, __tm1, __tm2, (__file)->last_meta_end, POSIX_F_META_TIME); \ + DARSHAN_COUNTER_INC((__file)->file_record, POSIX_STATS, 1); \ +} while(0) + /********************************************************** * Wrappers for POSIX I/O functions of interest * **********************************************************/ @@ -764,7 +799,7 @@ int DARSHAN_DECL(fseek)(FILE *stream, long offset, int whence) file = posix_file_by_fd(fileno(stream)); if(file) { - file->offset = ftell(stream); /* TODO: this seems wrong. ftell? */ + file->offset = ftell(stream); DARSHAN_COUNTER_F_INC_NO_OVERLAP(file->file_record, tm1, tm2, file->last_meta_end, POSIX_F_META_TIME); DARSHAN_COUNTER_INC(file->file_record, POSIX_FSEEKS, 1); @@ -775,6 +810,162 @@ int DARSHAN_DECL(fseek)(FILE *stream, long offset, int whence) return(ret); } +int DARSHAN_DECL(__xstat)(int vers, const char *path, struct stat *buf) +{ + int ret; + double tm1, tm2; + + MAP_OR_FAIL(__xstat); + + tm1 = darshan_core_wtime(); + ret = __real___xstat(vers, path, buf); + tm2 = darshan_core_wtime(); + + if(ret < 0 || !S_ISREG(buf->st_mode)) + return(ret); + + POSIX_LOCK(); + posix_runtime_initialize(); + POSIX_LOOKUP_RECORD_STAT(path, buf, tm1, tm2); + POSIX_UNLOCK(); + + return(ret); +} + +int DARSHAN_DECL(__xstat64)(int vers, const char *path, struct stat64 *buf) +{ + int ret; + double tm1, tm2; + + MAP_OR_FAIL(__xstat64); + + tm1 = darshan_core_wtime(); + ret = __real___xstat64(vers, path, buf); + tm2 = darshan_core_wtime(); + + if(ret < 0 || !S_ISREG(buf->st_mode)) + return(ret); + + POSIX_LOCK(); + posix_runtime_initialize(); + POSIX_LOOKUP_RECORD_STAT(path, buf, tm1, tm2); + POSIX_UNLOCK(); + + return(ret); +} + +int DARSHAN_DECL(__lxstat)(int vers, const char *path, struct stat *buf) +{ + int ret; + double tm1, tm2; + + MAP_OR_FAIL(__lxstat); + + tm1 = darshan_core_wtime(); + ret = __real___lxstat(vers, path, buf); + tm2 = darshan_core_wtime(); + + if(ret < 0 || !S_ISREG(buf->st_mode)) + return(ret); + + POSIX_LOCK(); + posix_runtime_initialize(); + POSIX_LOOKUP_RECORD_STAT(path, buf, tm1, tm2); + POSIX_UNLOCK(); + + return(ret); +} + +int DARSHAN_DECL(__lxstat64)(int vers, const char *path, struct stat64 *buf) +{ + int ret; + double tm1, tm2; + + MAP_OR_FAIL(__lxstat64); + + tm1 = darshan_core_wtime(); + ret = __real___lxstat64(vers, path, buf); + tm2 = darshan_core_wtime(); + + if(ret < 0 || !S_ISREG(buf->st_mode)) + return(ret); + + POSIX_LOCK(); + posix_runtime_initialize(); + POSIX_LOOKUP_RECORD_STAT(path, buf, tm1, tm2); + POSIX_UNLOCK(); + + return(ret); +} + +int DARSHAN_DECL(__fxstat)(int vers, int fd, struct stat *buf) +{ + int ret; + struct posix_file_runtime* file; + double tm1, tm2; + + MAP_OR_FAIL(__fxstat); + + tm1 = darshan_core_wtime(); + ret = __real___fxstat(vers, fd, buf); + tm2 = darshan_core_wtime(); + + if(ret < 0 || !S_ISREG(buf->st_mode)) + return(ret); + + /* TODO */ +#if 0 + /* skip logging if this was triggered internally */ + if((void*)buf == (void*)&cp_stat_buf) + return(ret); +#endif + + POSIX_LOCK(); + posix_runtime_initialize(); + file = posix_file_by_fd(fd); + if(file) + { + POSIX_RECORD_STAT(file, buf, tm1, tm2); + } + POSIX_UNLOCK(); + + return(ret); +} + +int DARSHAN_DECL(__fxstat64)(int vers, int fd, struct stat64 *buf) +{ + int ret; + struct posix_file_runtime* file; + double tm1, tm2; + + MAP_OR_FAIL(__fxstat64); + + tm1 = darshan_core_wtime(); + ret = __real___fxstat64(vers, fd, buf); + tm2 = darshan_core_wtime(); + + if(ret < 0 || !S_ISREG(buf->st_mode)) + return(ret); + + /* TODO */ +#if 0 + /* skip logging if this was triggered internally */ + if((void*)buf == (void*)&cp_stat_buf) + return(ret); +#endif + + POSIX_LOCK(); + posix_runtime_initialize(); + file = posix_file_by_fd(fd); + if(file) + { + POSIX_RECORD_STAT(file, buf, tm1, tm2); + } + POSIX_UNLOCK(); + + return(ret); +} + int DARSHAN_DECL(fsync)(int fd) { int ret; diff --git a/darshan-util/darshan-posix-parser.c b/darshan-util/darshan-posix-parser.c index bc7e324..eddf56c 100644 --- a/darshan-util/darshan-posix-parser.c +++ b/darshan-util/darshan-posix-parser.c @@ -174,6 +174,7 @@ int main(int argc, char **argv) "\t\tPOSIX_READS:\t%"PRIu64"\n" "\t\tPOSIX_WRITES:\t%"PRIu64"\n" "\t\tPOSIX_SEEKS:\t%"PRIu64"\n" + "\t\tPOSIX_STATS:\t%"PRIu64"\n" "\t\tPOSIX_FOPENS:\t%"PRIu64"\n" "\t\tPOSIX_FREADS:\t%"PRIu64"\n" "\t\tPOSIX_FWRITES:\t%"PRIu64"\n" @@ -190,8 +191,10 @@ int main(int argc, char **argv) "\t\tPOSIX_SEQ_READS:\t%"PRIu64"\n" "\t\tPOSIX_SEQ_WRITES:\t%"PRIu64"\n" "\t\tPOSIX_RW_SWITCHES:\t%"PRIu64"\n" + "\t\tFILE_ALIGNMENT:\t%"PRIu64"\n" "\t\tPOSIX_MAX_READ_TIME_SIZE:\t%"PRIu64"\n" "\t\tPOSIX_MAX_WRITE_TIME_SIZE:\t%"PRIu64"\n" + "\t\tSIZE_AT_OPEN:\t%"PRIu64"\n" "\t\tPOSIX_F_OPEN_TIMESTAMP:\t%lf\n" "\t\tPOSIX_F_READ_START_TIMESTAMP:\t%lf\n" "\t\tPOSIX_F_WRITE_START_TIMESTAMP:\t%lf\n" @@ -206,6 +209,7 @@ int main(int argc, char **argv) next_file.counters[POSIX_READS], next_file.counters[POSIX_WRITES], next_file.counters[POSIX_SEEKS], + next_file.counters[POSIX_STATS], next_file.counters[POSIX_FOPENS], next_file.counters[POSIX_FREADS], next_file.counters[POSIX_FWRITES], @@ -222,8 +226,10 @@ int main(int argc, char **argv) next_file.counters[POSIX_SEQ_READS], next_file.counters[POSIX_SEQ_WRITES], next_file.counters[POSIX_RW_SWITCHES], + next_file.counters[FILE_ALIGNMENT], next_file.counters[POSIX_MAX_READ_TIME_SIZE], next_file.counters[POSIX_MAX_WRITE_TIME_SIZE], + next_file.counters[SIZE_AT_OPEN], next_file.fcounters[POSIX_F_OPEN_TIMESTAMP], next_file.fcounters[POSIX_F_READ_START_TIMESTAMP], next_file.fcounters[POSIX_F_WRITE_START_TIMESTAMP], -- 2.26.2