aboutsummaryrefslogtreecommitdiff
path: root/src/common/memarea.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2008-03-26 17:50:27 +0000
committerNick Mathewson <nickm@torproject.org>2008-03-26 17:50:27 +0000
commite8cc756c132de678777f8439e13757890b9e90aa (patch)
tree008abab7a2acc9bebcc7afed67c1a906a26f52ba /src/common/memarea.c
parent745f3c859afff19bb6c28eef41b5b7312a9c5c35 (diff)
downloadtor-e8cc756c132de678777f8439e13757890b9e90aa.tar
tor-e8cc756c132de678777f8439e13757890b9e90aa.tar.gz
r19072@catbus: nickm | 2008-03-26 13:50:24 -0400
Add code to debug memory area size. Use results of this code to set a couple of area sizes more sanely. svn:r14201
Diffstat (limited to 'src/common/memarea.c')
-rw-r--r--src/common/memarea.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/common/memarea.c b/src/common/memarea.c
index 916010cfd..743a451a8 100644
--- a/src/common/memarea.c
+++ b/src/common/memarea.c
@@ -197,6 +197,22 @@ memarea_strndup(memarea_t *area, const char *s, size_t n)
return result;
}
+/** Set <b>allocated_out</b> to the number of bytes allocated in <b>area</b>,
+ * and <b>used_out</b> to the number of bytes currently used. */
+void
+memarea_get_stats(memarea_t *area, size_t *allocated_out, size_t *used_out)
+{
+ size_t a = 0, u = 0;
+ memarea_chunk_t *chunk;
+ for (chunk = area->first; chunk; chunk = chunk->next_chunk) {
+ a += CHUNK_HEADER_SIZE + chunk->mem_size;
+ tor_assert(chunk->next_mem >= chunk->u.mem);
+ u += CHUNK_HEADER_SIZE + (chunk->next_mem - chunk->u.mem);
+ }
+ *allocated_out = a;
+ *used_out = u;
+}
+
/** Assert that <b>area</b> is okay. */
void
memarea_assert_ok(memarea_t *area)