diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/common/util.c | 18 | ||||
-rw-r--r-- | src/common/util.h | 5 | ||||
-rw-r--r-- | src/or/main.c | 1 |
3 files changed, 24 insertions, 0 deletions
diff --git a/src/common/util.c b/src/common/util.c index 991cda1a97..580f078afe 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -213,6 +213,24 @@ _tor_free(void *mem) tor_free(mem); } +/** DOCDOC */ +void +tor_log_mallinfo(int severity) +{ +#ifdef HAVE_MALLINFO + struct mallinfo mi; + memset(&mi, 0, sizeof(mi)); + mi = mallinfo(); + log(severity, LD_MM, + "mallinfo() said: arena=%d, ordblks=%d, smblks=%d, hblks=%d, " + "hblkhd=%d, usmblks=%d, fsmblks=%d, uordblks=%d, fordblks=%d, " + "keepcost=%d", + mi.arena, mi.ordblks, mi.smblks, mi.hblks, + mi.hblkhd, mi.usmblks, mi.fsmblks, mi.uordblks, mi.fordblks, + mi.keepcost); +#endif +} + /* ===== * Math * ===== */ diff --git a/src/common/util.h b/src/common/util.h index 3cd19c06c0..b0db03f149 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -23,6 +23,9 @@ #ifdef HAVE_TIME_H #include <time.h> #endif +#ifdef HAVE_MALLOC_H +#include <malloc.h> +#endif /* Replace assert() with a variant that sends failures to the log before * calling assert() normally. @@ -105,6 +108,8 @@ extern int dmalloc_free(const char *file, const int line, void *pnt, #define tor_strndup(s, n) _tor_strndup(s, n DMALLOC_ARGS) #define tor_memdup(s, n) _tor_memdup(s, n DMALLOC_ARGS) +void tor_log_mallinfo(int severity); + /** Return the offset of <b>member</b> within the type <b>tp</b>, in bytes */ #if defined(__GNUC__) && __GNUC__ > 3 #define STRUCT_OFFSET(tp, member) __builtin_offsetof(tp, member) diff --git a/src/or/main.c b/src/or/main.c index 25a0f32616..0086168a4d 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -1550,6 +1550,7 @@ dumpmemusage(int severity) dump_routerlist_mem_usage(severity); dump_cell_pool_usage(severity); buf_dump_freelist_sizes(severity); + tor_log_mallinfo(severity); } /** Write all statistics to the log, with log level 'severity'. Called |