[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r14201: Add code to debug memory area size. Use results of this code (in tor/trunk: . src/common src/or)
Author: nickm
Date: 2008-03-26 13:50:27 -0400 (Wed, 26 Mar 2008)
New Revision: 14201
Modified:
tor/trunk/
tor/trunk/src/common/memarea.c
tor/trunk/src/common/memarea.h
tor/trunk/src/or/routerparse.c
Log:
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.
Property changes on: tor/trunk
___________________________________________________________________
svk:merge ticket from /tor/trunk [r19072] on 8246c3cf-6607-4228-993b-4d95d33730f1
Modified: tor/trunk/src/common/memarea.c
===================================================================
--- tor/trunk/src/common/memarea.c 2008-03-26 17:25:28 UTC (rev 14200)
+++ tor/trunk/src/common/memarea.c 2008-03-26 17:50:27 UTC (rev 14201)
@@ -197,6 +197,22 @@
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)
Modified: tor/trunk/src/common/memarea.h
===================================================================
--- tor/trunk/src/common/memarea.h 2008-03-26 17:25:28 UTC (rev 14200)
+++ tor/trunk/src/common/memarea.h 2008-03-26 17:50:27 UTC (rev 14201)
@@ -17,6 +17,8 @@
void *memarea_memdup(memarea_t *area, const void *s, size_t n);
char *memarea_strdup(memarea_t *area, const char *s);
char *memarea_strndup(memarea_t *area, const char *s, size_t n);
+void memarea_get_stats(memarea_t *area,
+ size_t *allocated_out, size_t *used_out);
void memarea_assert_ok(memarea_t *area);
#endif
Modified: tor/trunk/src/or/routerparse.c
===================================================================
--- tor/trunk/src/or/routerparse.c 2008-03-26 17:25:28 UTC (rev 14200)
+++ tor/trunk/src/or/routerparse.c 2008-03-26 17:50:27 UTC (rev 14201)
@@ -446,6 +446,19 @@
static crypto_pk_env_t *find_dir_signing_key(const char *str, const char *eos);
static int tor_version_same_series(tor_version_t *a, tor_version_t *b);
+#undef DEBUG_AREA_ALLOC
+
+#ifdef DEBUG_AREA_ALLOC
+#define DUMP_AREA(a,name) STMT_BEGIN \
+ size_t alloc=0, used=0; \
+ memarea_get_stats((a),&alloc,&used); \
+ log_debug(LD_MM, "Area for %s has %lu allocated; using %lu.", \
+ name, (unsigned long)alloc, (unsigned long)used); \
+ STMT_END
+#else
+#define DUMP_AREA(a,name) STMT_NIL
+#endif
+
/** Set <b>digest</b> to the SHA-1 digest of the hash of the directory in
* <b>s</b>. Return 0 on success, -1 on failure.
*/
@@ -715,8 +728,10 @@
SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_free(t));
smartlist_free(tokens);
}
- if (area)
+ if (area) {
+ DUMP_AREA(area, "v1 directory");
memarea_drop_all(area);
+ }
return r;
}
@@ -778,8 +793,10 @@
SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_free(t));
smartlist_free(tokens);
}
- if (area)
+ if (area) {
+ DUMP_AREA(area, "v1 running-routers");
memarea_drop_all(area);
+ }
return r;
}
@@ -824,7 +841,10 @@
done:
if (tok) token_free(tok);
- if (area) memarea_drop_all(area);
+ if (area) {
+ DUMP_AREA(area, "dir-signing-key token");
+ memarea_drop_all(area);
+ }
return key;
}
@@ -1086,7 +1106,7 @@
while (end > s+2 && *(end-1) == '\n' && *(end-2) == '\n')
--end;
- area = memarea_new(8192);
+ area = memarea_new(4096);
tokens = smartlist_create();
if (prepend_annotations) {
if (tokenize_string(area,prepend_annotations,NULL,tokens,
@@ -1367,8 +1387,10 @@
if (exit_policy_tokens) {
smartlist_free(exit_policy_tokens);
}
- if (area)
+ if (area) {
+ DUMP_AREA(area, "routerinfo");
memarea_drop_all(area);
+ }
return router;
}
@@ -1487,8 +1509,10 @@
SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_free(t));
smartlist_free(tokens);
}
- if (area)
+ if (area) {
+ DUMP_AREA(area, "extrainfo");
memarea_drop_all(area);
+ }
return extrainfo;
}
@@ -1635,8 +1659,10 @@
err:
authority_cert_free(cert);
SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_free(t));
- if (area)
+ if (area) {
+ DUMP_AREA(area, "authority cert");
memarea_drop_all(area);
+ }
smartlist_free(tokens);
return NULL;
}
@@ -1824,8 +1850,10 @@
done:
SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_free(t));
smartlist_clear(tokens);
- if (area)
+ if (area) {
+ DUMP_AREA(area, "routerstatus entry");
memarea_clear(area);
+ }
*s = eos;
return rs;
@@ -2017,8 +2045,10 @@
smartlist_free(tokens);
SMARTLIST_FOREACH(footer_tokens, directory_token_t *, t, token_free(t));
smartlist_free(footer_tokens);
- if (area)
+ if (area) {
+ DUMP_AREA(area, "v2 networkstatus");
memarea_drop_all(area);
+ }
return ns;
}
@@ -2392,8 +2422,10 @@
SMARTLIST_FOREACH(footer_tokens, directory_token_t *, t, token_free(t));
smartlist_free(footer_tokens);
}
- if (area)
+ if (area) {
+ DUMP_AREA(area, "v3 networkstatus");
memarea_drop_all(area);
+ }
if (rs_area)
memarea_drop_all(rs_area);
@@ -2506,8 +2538,10 @@
done:
SMARTLIST_FOREACH(tokens, directory_token_t *, t, token_free(t));
smartlist_free(tokens);
- if (area)
+ if (area) {
+ DUMP_AREA(area, "detached signatures");
memarea_drop_all(area);
+ }
return sigs;
}
@@ -2541,7 +2575,7 @@
}
eos = cp + strlen(cp);
- area = memarea_new(512);
+ area = memarea_new(128);
tok = get_next_token(area, &cp, eos, routerdesc_token_table);
if (tok->tp == _ERR) {
log_warn(LD_DIR, "Error reading address policy: %s", tok->error);
@@ -2559,8 +2593,10 @@
r = NULL;
done:
token_free(tok);
- if (area)
+ if (area) {
+ DUMP_AREA(area, "policy item");
memarea_drop_all(area);
+ }
return r;
}