summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2007-07-30 18:14:14 +0000
committerNick Mathewson <nickm@torproject.org>2007-07-30 18:14:14 +0000
commit45c82b1d8555901b6992bf9a30120fbb35a005ab (patch)
treef4856594ac021a4b9988433f782d2516dfb56606 /src/common
parent9fb77a6479a079aeb5698272c68bd50acdffe401 (diff)
downloadtor-45c82b1d8555901b6992bf9a30120fbb35a005ab.tar.gz
tor-45c82b1d8555901b6992bf9a30120fbb35a005ab.zip
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
Diffstat (limited to 'src/common')
-rw-r--r--src/common/util.c18
-rw-r--r--src/common/util.h5
2 files changed, 23 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)