Dump bytes held to store descriptors.

svn:r5443
This commit is contained in:
Nick Mathewson 2005-11-23 06:00:58 +00:00
parent 7d7bb95f36
commit fbf8a8c25f
3 changed files with 21 additions and 12 deletions

View File

@ -1221,6 +1221,7 @@ dumpmemusage(int severity)
nfds);
log(severity, LD_GENERAL, "In rephist: "U64_FORMAT" used by %d Tors.",
U64_PRINTF_ARG(rephist_total_alloc), rephist_total_num);
dump_routerlist_mem_usage(severity);
}
/** Write all statistics to the log, with log level 'severity'. Called

View File

@ -883,8 +883,6 @@ typedef struct {
/** List of signed_descriptor_t for older router descriptors we're
* caching. */
smartlist_t *old_routers;
/** For debugging: tracks RAM usage in signed descriptors. */
uint32_t signed_descriptor_bytes;
} routerlist_t;
/** Information on router used when extending a circuit. (We don't need a
@ -2163,6 +2161,7 @@ int router_digest_is_trusted_dir(const char *digest);
routerlist_t *router_get_routerlist(void);
void routerlist_reset_warnings(void);
void routerlist_free(routerlist_t *routerlist);
void dump_routerlist_mem_usage(int severity);
void routerlist_remove(routerlist_t *rl, routerinfo_t *ri, int idx,
int make_old);
void routerinfo_free(routerinfo_t *router);

View File

@ -1127,6 +1127,25 @@ routerlist_free(routerlist_t *rl)
tor_free(rl);
}
void
dump_routerlist_mem_usage(int severity)
{
uint64_t livedescs = 0;
uint64_t olddescs = 0;
if (!routerlist)
return;
SMARTLIST_FOREACH(routerlist->routers, routerinfo_t *, r,
livedescs += r->cache_info.signed_descriptor_len);
SMARTLIST_FOREACH(routerlist->old_routers, signed_descriptor_t *, sd,
livedescs += sd->signed_descriptor_len);
log(severity, LD_GENERAL,
"In %d live descriptors: "U64_FORMAT" bytes. "
"In %d old descriptors: "U64_FORMAT" bytes.",
smartlist_len(routerlist->routers), U64_PRINTF_ARG(livedescs),
smartlist_len(routerlist->old_routers), U64_PRINTF_ARG(olddescs));
}
static INLINE int
_routerlist_find_elt(smartlist_t *sl, void *ri, int idx)
{
@ -1150,7 +1169,6 @@ routerlist_insert(routerlist_t *rl, routerinfo_t *ri)
digestmap_set(rl->desc_digest_map, ri->cache_info.signed_descriptor_digest,
&(ri->cache_info));
smartlist_add(rl->routers, ri);
rl->signed_descriptor_bytes += ri->cache_info.signed_descriptor_len;
// routerlist_assert_ok(rl);
}
@ -1161,7 +1179,6 @@ routerlist_insert_old(routerlist_t *rl, routerinfo_t *ri)
signed_descriptor_t *sd = signed_descriptor_from_routerinfo(ri);
digestmap_set(rl->desc_digest_map, sd->signed_descriptor_digest, sd);
smartlist_add(rl->old_routers, sd);
rl->signed_descriptor_bytes += sd->signed_descriptor_len;
} else {
routerinfo_free(ri);
}
@ -1190,7 +1207,6 @@ routerlist_remove(routerlist_t *rl, routerinfo_t *ri, int idx, int make_old)
} else {
ri_tmp = digestmap_remove(rl->desc_digest_map,
ri->cache_info.signed_descriptor_digest);
rl->signed_descriptor_bytes -= ri->cache_info.signed_descriptor_len;
tor_assert(ri_tmp == ri);
routerinfo_free(ri);
}
@ -1207,7 +1223,6 @@ routerlist_remove_old(routerlist_t *rl, signed_descriptor_t *sd, int idx)
smartlist_del(rl->old_routers, idx);
sd_tmp = digestmap_remove(rl->desc_digest_map,
sd->signed_descriptor_digest);
rl->signed_descriptor_bytes -= sd->signed_descriptor_len;
tor_assert(sd_tmp == sd);
signed_descriptor_free(sd);
routerlist_assert_ok(rl);
@ -1229,7 +1244,6 @@ routerlist_replace(routerlist_t *rl, routerinfo_t *ri_old,
} else {
warn(LD_BUG, "Appending entry from routerlist_replace.");
routerlist_insert(rl, ri_new);
rl->signed_descriptor_bytes += ri_new->cache_info.signed_descriptor_len;
return;
}
if (memcmp(ri_old->cache_info.identity_digest, ri_new->cache_info.identity_digest, DIGEST_LEN)) {
@ -1238,7 +1252,6 @@ routerlist_replace(routerlist_t *rl, routerinfo_t *ri_old,
}
digestmap_set(rl->identity_map, ri_new->cache_info.identity_digest, ri_new);
digestmap_set(rl->desc_digest_map, ri_new->cache_info.signed_descriptor_digest, &(ri_new->cache_info));
rl->signed_descriptor_bytes += ri_new->cache_info.signed_descriptor_len;
if (make_old && get_options()->DirPort) {
signed_descriptor_t *sd = signed_descriptor_from_routerinfo(ri_old);
@ -1251,7 +1264,6 @@ routerlist_replace(routerlist_t *rl, routerinfo_t *ri_old,
/* digests don't match; digestmap_set didn't replace */
digestmap_remove(rl->desc_digest_map, ri_old->cache_info.signed_descriptor_digest);
}
rl->signed_descriptor_bytes -= ri_old->cache_info.signed_descriptor_len;
routerinfo_free(ri_old);
}
// routerlist_assert_ok(rl);
@ -3264,7 +3276,6 @@ routerlist_assert_ok(routerlist_t *rl)
tor_assert(r == r2);
sd2 = digestmap_get(rl->desc_digest_map, r->cache_info.signed_descriptor_digest);
tor_assert(&(r->cache_info) == sd2);
bytes += r->cache_info.signed_descriptor_len;
});
SMARTLIST_FOREACH(rl->old_routers, signed_descriptor_t *, sd,
{
@ -3272,9 +3283,7 @@ routerlist_assert_ok(routerlist_t *rl)
tor_assert(sd != &(r2->cache_info));
sd2 = digestmap_get(rl->desc_digest_map, sd->signed_descriptor_digest);
tor_assert(sd == sd2);
bytes += sd->signed_descriptor_len;
});
tor_assert(bytes == rl->signed_descriptor_bytes);
iter = digestmap_iter_init(rl->identity_map);
while (!digestmap_iter_done(iter)) {
const char *d;