diff --git a/src/error.h b/src/error.h index ee9a6765b6215482751d5b6c498e9e16bc04b8a0..de4e9fa44c73d91524dfd307a3ad19b6cad3421f 100644 --- a/src/error.h +++ b/src/error.h @@ -46,7 +46,7 @@ /* If reporting memory usage, try to dump that when exiting in error. */ #ifdef SWIFT_MEMUSE_REPORTS -#define memdump(rank) memuse_log_dump("memuse-error-report.txt"); +#define memdump(rank) memuse_log_dump_error(rank); #else #define memdump(rank) #endif diff --git a/src/memuse.c b/src/memuse.c index 02b5334c6921faf22c2dfbc5169380370c436504..0c74bea4ed63e4b8d0d2b6dfbbc0de095192abf5 100644 --- a/src/memuse.c +++ b/src/memuse.c @@ -146,6 +146,8 @@ void memuse_log_allocation(const char *label, void *ptr, int allocated, /** * @brief dump the log to a file and reset, if anything to dump. + * + * @param filename name of file for log dump. */ void memuse_log_dump(const char *filename) { @@ -176,6 +178,18 @@ void memuse_log_dump(const char *filename) { fclose(fd); } +/** + * @brief dump the log for using the given rank to generate a standard + * name for the output. Used when exiting in error. + * + * @param rank the rank exiting in error. + */ +void memuse_log_dump_error(int rank) { + char filename[60]; + sprintf(filename, "memuse-error-report-rank%d.txt", rank); + memuse_log_dump(filename); +} + #endif /* SWIFT_MEMUSE_REPORTS */ /** diff --git a/src/memuse.h b/src/memuse.h index e9bb16733c2cd0b1fe8440e4fbbb41356afdcd4b..7df4a2efb8b722d893d1e0d34340f59e78591f01 100644 --- a/src/memuse.h +++ b/src/memuse.h @@ -32,6 +32,7 @@ const char *memuse_process(int inmb); #ifdef SWIFT_MEMUSE_REPORTS void memuse_log_dump(const char *filename); +void memuse_log_dump_error(int rank); void memuse_log_allocation(const char *label, void *ptr, int allocated, size_t size); #else @@ -57,7 +58,12 @@ __attribute__((always_inline)) inline int swift_memalign(const char *label, size_t size) { int result = posix_memalign(memptr, alignment, size); #ifdef SWIFT_MEMUSE_REPORTS - if (result == 0) memuse_log_allocation(label, *memptr, 1, size); + if (result == 0) { + memuse_log_allocation(label, *memptr, 1, size); + } else { + /* Failed allocations are interesting as well. */ + memuse_log_allocation(label, NULL, 1, size); + } #endif return result; } @@ -77,7 +83,12 @@ __attribute__((always_inline)) inline void *swift_malloc(const char *label, size_t size) { void *memptr = malloc(size); #ifdef SWIFT_MEMUSE_REPORTS - if (memptr != NULL) memuse_log_allocation(label, memptr, 1, size); + if (memptr != NULL) { + memuse_log_allocation(label, memptr, 1, size); + } else { + /* Failed allocations are interesting as well. */ + memuse_log_allocation(label, NULL, 1, size); + } #endif return memptr; }