[or-cvs] r11232: Optionally export mallinfo() output on the DirPort (in tor/trunk: . src/or)
weasel at seul.org
weasel at seul.org
Mon Aug 20 22:11:56 UTC 2007
Author: weasel
Date: 2007-08-20 18:11:56 -0400 (Mon, 20 Aug 2007)
New Revision: 11232
Modified:
tor/trunk/ChangeLog
tor/trunk/src/or/directory.c
Log:
Optionally export mallinfo() output on the DirPort
Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog 2007-08-20 21:56:33 UTC (rev 11231)
+++ tor/trunk/ChangeLog 2007-08-20 22:11:56 UTC (rev 11232)
@@ -15,8 +15,11 @@
- Let directory authorities startup even when they can't generate
a descriptor immediately, e.g. because they don't know their
address.
+ o Minor features (misc):
+ - Optionally (if built with -DEXPORTMEMINFO) export the output
+ of mallinfo via http, as tor/mallinfo.txt. Only accessible
+ from localhost.
-
Changes in version 0.2.0.5-alpha - 2007-08-19
o Removed features:
- Version 1 directories are no longer generated in full. Instead,
Modified: tor/trunk/src/or/directory.c
===================================================================
--- tor/trunk/src/or/directory.c 2007-08-20 21:56:33 UTC (rev 11231)
+++ tor/trunk/src/or/directory.c 2007-08-20 22:11:56 UTC (rev 11232)
@@ -6,6 +6,9 @@
"$Id$";
#include "or.h"
+#if defined(EXPORTMEMINFO) && defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO)
+#include <malloc.h>
+#endif
/**
* \file directory.c
@@ -2193,6 +2196,46 @@
goto done;
}
+#if defined(EXPORTMEMINFO) && defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO)
+#define ADD_MALLINFO_LINE(x) do { \
+ tor_snprintf(tmp, sizeof(tmp), "%s %d\n", #x, mi.x); \
+ smartlist_add(lines, tor_strdup(tmp)); \
+ } while(0);
+
+ if (!strcmp(url,"/tor/mallinfo.txt") &&
+ (conn->_base.addr == 0x7f000001ul)) {
+ char *result;
+ size_t len;
+ struct mallinfo mi;
+ memset(&mi, 0, sizeof(mi));
+ smartlist_t *lines;
+
+ mi = mallinfo();
+ lines = smartlist_create();
+ char tmp[256];
+
+ ADD_MALLINFO_LINE(arena)
+ ADD_MALLINFO_LINE(ordblks)
+ ADD_MALLINFO_LINE(smblks)
+ ADD_MALLINFO_LINE(hblks)
+ ADD_MALLINFO_LINE(hblkhd)
+ ADD_MALLINFO_LINE(usmblks)
+ ADD_MALLINFO_LINE(fsmblks)
+ ADD_MALLINFO_LINE(uordblks)
+ ADD_MALLINFO_LINE(fordblks)
+ ADD_MALLINFO_LINE(keepcost)
+
+ result = smartlist_join_strings(lines, "", 0, NULL);
+ SMARTLIST_FOREACH(lines, char *, cp, tor_free(cp));
+ smartlist_free(lines);
+
+ len = strlen(result);
+ write_http_response_header(conn, len, 0, 0);
+ connection_write_to_buf(result, len, TO_CONN(conn));
+ tor_free(result);
+ }
+#endif
+
/* we didn't recognize the url */
write_http_status_line(conn, 404, "Not found");
More information about the tor-commits
mailing list