mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
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:
@@ -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
|
||||
* ===== */
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user