Skip to content
Snippets Groups Projects
Commit 03f028d9 authored by Peter W. Draper's avatar Peter W. Draper
Browse files

Make error report about memory use more interesting by keeping a record of the...

Make error report about memory use more interesting by keeping a record of the failed allocation, also keep one error dump per rank (stop overwrites)
parent 6ad718c8
No related branches found
No related tags found
1 merge request!757Memory allocations logger
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
/* If reporting memory usage, try to dump that when exiting in error. */ /* If reporting memory usage, try to dump that when exiting in error. */
#ifdef SWIFT_MEMUSE_REPORTS #ifdef SWIFT_MEMUSE_REPORTS
#define memdump(rank) memuse_log_dump("memuse-error-report.txt"); #define memdump(rank) memuse_log_dump_error(rank);
#else #else
#define memdump(rank) #define memdump(rank)
#endif #endif
......
...@@ -146,6 +146,8 @@ void memuse_log_allocation(const char *label, void *ptr, int allocated, ...@@ -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. * @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) { void memuse_log_dump(const char *filename) {
...@@ -176,6 +178,18 @@ void memuse_log_dump(const char *filename) { ...@@ -176,6 +178,18 @@ void memuse_log_dump(const char *filename) {
fclose(fd); 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 */ #endif /* SWIFT_MEMUSE_REPORTS */
/** /**
......
...@@ -32,6 +32,7 @@ const char *memuse_process(int inmb); ...@@ -32,6 +32,7 @@ const char *memuse_process(int inmb);
#ifdef SWIFT_MEMUSE_REPORTS #ifdef SWIFT_MEMUSE_REPORTS
void memuse_log_dump(const char *filename); 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, void memuse_log_allocation(const char *label, void *ptr, int allocated,
size_t size); size_t size);
#else #else
...@@ -57,7 +58,12 @@ __attribute__((always_inline)) inline int swift_memalign(const char *label, ...@@ -57,7 +58,12 @@ __attribute__((always_inline)) inline int swift_memalign(const char *label,
size_t size) { size_t size) {
int result = posix_memalign(memptr, alignment, size); int result = posix_memalign(memptr, alignment, size);
#ifdef SWIFT_MEMUSE_REPORTS #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 #endif
return result; return result;
} }
...@@ -77,7 +83,12 @@ __attribute__((always_inline)) inline void *swift_malloc(const char *label, ...@@ -77,7 +83,12 @@ __attribute__((always_inline)) inline void *swift_malloc(const char *label,
size_t size) { size_t size) {
void *memptr = malloc(size); void *memptr = malloc(size);
#ifdef SWIFT_MEMUSE_REPORTS #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 #endif
return memptr; return memptr;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment