mirror of
https://github.com/matrix-construct/construct
synced 2024-11-17 07:20:55 +01:00
ircd: irc_dictionary: also show dictionary stats
This commit is contained in:
parent
99b461bb2f
commit
21d5a11cb8
3 changed files with 32 additions and 8 deletions
|
@ -149,5 +149,6 @@ extern void *irc_dictionary_delete(struct Dictionary *dtree, const char *key);
|
||||||
extern unsigned int irc_dictionary_size(struct Dictionary *dtree);
|
extern unsigned int irc_dictionary_size(struct Dictionary *dtree);
|
||||||
|
|
||||||
void irc_dictionary_stats(struct Dictionary *dict, void (*cb)(const char *line, void *privdata), void *privdata);
|
void irc_dictionary_stats(struct Dictionary *dict, void (*cb)(const char *line, void *privdata), void *privdata);
|
||||||
|
void irc_dictionary_stats_walk(void (*cb)(const char *line, void *privdata), void *privdata);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -37,8 +37,12 @@ struct Dictionary
|
||||||
unsigned int count;
|
unsigned int count;
|
||||||
char *id;
|
char *id;
|
||||||
unsigned int dirty:1;
|
unsigned int dirty:1;
|
||||||
|
|
||||||
|
rb_dlink_node node;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static rb_dlink_list dictionary_list = {NULL, NULL, 0};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* irc_dictionary_create(const char *name, DCF compare_cb)
|
* irc_dictionary_create(const char *name, DCF compare_cb)
|
||||||
*
|
*
|
||||||
|
@ -63,6 +67,8 @@ struct Dictionary *irc_dictionary_create(const char *name,
|
||||||
dtree->compare_cb = compare_cb;
|
dtree->compare_cb = compare_cb;
|
||||||
dtree->id = rb_strdup(name);
|
dtree->id = rb_strdup(name);
|
||||||
|
|
||||||
|
rb_dlinkAdd(dtree, &dtree->node, &dictionary_list);
|
||||||
|
|
||||||
return dtree;
|
return dtree;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -444,6 +450,8 @@ void irc_dictionary_destroy(struct Dictionary *dtree,
|
||||||
rb_free(n);
|
rb_free(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rb_dlinkDelete(&dtree->node, &dictionary_list);
|
||||||
|
|
||||||
rb_free(dtree);
|
rb_free(dtree);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -818,16 +826,19 @@ void irc_dictionary_stats(struct Dictionary *dict, void (*cb)(const char *line,
|
||||||
|
|
||||||
s_assert(dict != NULL);
|
s_assert(dict != NULL);
|
||||||
|
|
||||||
if (dict->id != NULL)
|
|
||||||
rb_snprintf(str, sizeof str, "Dictionary stats for %s (%d)",
|
|
||||||
dict->id, dict->count);
|
|
||||||
else
|
|
||||||
rb_snprintf(str, sizeof str, "Dictionary stats for <%p> (%d)",
|
|
||||||
(void *)dict, dict->count);
|
|
||||||
cb(str, privdata);
|
cb(str, privdata);
|
||||||
maxdepth = 0;
|
maxdepth = 0;
|
||||||
sum = stats_recurse(dict->root, 0, &maxdepth);
|
sum = stats_recurse(dict->root, 0, &maxdepth);
|
||||||
rb_snprintf(str, sizeof str, "Depth sum %d Avg depth %d Max depth %d", sum, sum / dict->count, maxdepth);
|
rb_snprintf(str, sizeof str, "%s: Objects: %d, Depth sum: %d, Avg depth: %d, Max depth: %d.", dict->id, dict->count, sum, sum / dict->count, maxdepth);
|
||||||
cb(str, privdata);
|
cb(str, privdata);
|
||||||
return;
|
}
|
||||||
|
|
||||||
|
void irc_dictionary_stats_walk(void (*cb)(const char *line, void *privdata), void *privdata)
|
||||||
|
{
|
||||||
|
rb_dlink_node *ptr;
|
||||||
|
|
||||||
|
RB_DLINK_FOREACH(ptr, dictionary_list.head)
|
||||||
|
{
|
||||||
|
irc_dictionary_stats(ptr->data, cb, privdata);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -272,10 +272,22 @@ stats_delay(struct Client *source_p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
stats_hash_cb(const char *buf, void *client_p)
|
||||||
|
{
|
||||||
|
sendto_one_numeric(client_p, RPL_STATSDEBUG, "B :%s", buf);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
stats_hash(struct Client *source_p)
|
stats_hash(struct Client *source_p)
|
||||||
{
|
{
|
||||||
hash_stats(source_p);
|
hash_stats(source_p);
|
||||||
|
|
||||||
|
sendto_one_numeric(source_p, RPL_STATSDEBUG, "B :Dictionary stats:");
|
||||||
|
irc_dictionary_stats_walk(stats_hash_cb, source_p);
|
||||||
|
|
||||||
|
sendto_one_numeric(source_p, RPL_STATSDEBUG, "B :Radix tree stats:");
|
||||||
|
irc_radixtree_stats_walk(stats_hash_cb, source_p);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Reference in a new issue