summaryrefslogtreecommitdiff
path: root/src/or/connection.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2007-04-23 03:04:46 +0000
committerNick Mathewson <nickm@torproject.org>2007-04-23 03:04:46 +0000
commit473c266fc2c7ca4b0c5ccd2f37f9af04dddd4920 (patch)
treeb5d1248ebbc6a63b7c889231e43232f09d119048 /src/or/connection.c
parent5cf600b57a138c70d7900a6259a27b9b2f8fc771 (diff)
downloadtor-473c266fc2c7ca4b0c5ccd2f37f9af04dddd4920.tar.gz
tor-473c266fc2c7ca4b0c5ccd2f37f9af04dddd4920.zip
r12496@catbus: nickm | 2007-04-22 23:04:05 -0400
When logging memory usage, break down memory used in buffers by buffer type. svn:r10004
Diffstat (limited to 'src/or/connection.c')
-rw-r--r--src/or/connection.c50
1 files changed, 49 insertions, 1 deletions
diff --git a/src/or/connection.c b/src/or/connection.c
index efb5e3b255..7824e3844f 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -389,7 +389,6 @@ connection_free_all(void)
connection_t **carray;
get_connection_array(&carray,&n);
-
/* We don't want to log any messages to controllers. */
for (i=0;i<n;i++)
if (carray[i]->type == CONN_TYPE_CONTROL)
@@ -2503,6 +2502,55 @@ connection_reached_eof(connection_t *conn)
}
}
+/** Log how many bytes are used by buffers of different kinds and sizes. */
+void
+connection_dump_buffer_mem_stats(int severity)
+{
+ uint64_t used_by_type[_CONN_TYPE_MAX+1];
+ uint64_t alloc_by_type[_CONN_TYPE_MAX+1];
+ int n_conns_by_type[_CONN_TYPE_MAX+1];
+ uint64_t total_alloc = 0;
+ uint64_t total_used = 0;
+ int i, n;
+ connection_t **carray;
+
+ memset(used_by_type, 0, sizeof(used_by_type));
+ memset(alloc_by_type, 0, sizeof(alloc_by_type));
+ memset(n_conns_by_type, 0, sizeof(n_conns_by_type));
+
+ get_connection_array(&carray,&n);
+
+ for (i=0; i<n; ++i) {
+ connection_t *c = carray[i];
+ int tp = c->type;
+ ++n_conns_by_type[tp];
+ if (c->inbuf) {
+ used_by_type[tp] += buf_datalen(c->inbuf);
+ alloc_by_type[tp] += buf_capacity(c->inbuf);
+ }
+ if (c->outbuf) {
+ used_by_type[tp] += buf_datalen(c->outbuf);
+ alloc_by_type[tp] += buf_capacity(c->outbuf);
+ }
+ }
+ for (i=0; i <= _CONN_TYPE_MAX; ++i) {
+ total_used += used_by_type[i];
+ total_alloc += alloc_by_type[i];
+ }
+
+ log(severity, LD_GENERAL,
+ "In buffers for %d connections: "U64_FORMAT" used/"U64_FORMAT" allocated",
+ n, U64_PRINTF_ARG(total_used), U64_PRINTF_ARG(total_alloc));
+ for (i=_CONN_TYPE_MIN; i <= _CONN_TYPE_MAX; ++i) {
+ if (!n_conns_by_type[i])
+ continue;
+ log(severity, LD_GENERAL,
+ " For %d %s connections: "U64_FORMAT" used/"U64_FORMAT" allocated",
+ n_conns_by_type[i], conn_type_to_string(i),
+ U64_PRINTF_ARG(used_by_type[i]), U64_PRINTF_ARG(alloc_by_type[i]));
+ }
+}
+
/** Verify that connection <b>conn</b> has all of its invariants
* correct. Trigger an assert if anything is invalid.
*/