r14024@catbus: nickm | 2007-07-30 14:13:58 -0400

Glibc (and maybe others) define a mallinfo() that can be used to see how the platform malloc is acting inside.  When we have it, dump its output on dumpmemusage().


svn:r10996
This commit is contained in:
Nick Mathewson
2007-07-30 18:14:14 +00:00
parent 9fb77a6479
commit 45c82b1d85
5 changed files with 31 additions and 4 deletions
+18
View File
@@ -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
* ===== */
+5
View File
@@ -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)
+1
View File
@@ -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