From 0b7c89091fed1feb9a45a594c133a5d122dea692 Mon Sep 17 00:00:00 2001 Message-Id: <0b7c89091fed1feb9a45a594c133a5d122dea692.1714143742.git.mdw@distorted.org.uk> From: Mark Wooding Date: Sun, 29 Jul 2007 18:10:55 +0100 Subject: [PATCH] report cache size with MDEBUG Organization: Straylight/Edgeware From: rjk@greenend.org.uk <> --- disobedience/disobedience.c | 30 ++++++++++++++++++++++++++++++ lib/cache.c | 4 ++++ lib/cache.h | 3 +++ 3 files changed, 37 insertions(+) diff --git a/disobedience/disobedience.c b/disobedience/disobedience.c index c37d0bc..cb5bb33 100644 --- a/disobedience/disobedience.c +++ b/disobedience/disobedience.c @@ -251,6 +251,28 @@ static void log_volume(void attribute((unused)) *v, } } +#if MDEBUG +static int widget_count, container_count; + +static void count_callback(GtkWidget *w, + gpointer attribute((unused)) data) { + ++widget_count; + if(GTK_IS_CONTAINER(w)) { + ++container_count; + gtk_container_foreach(GTK_CONTAINER(w), count_callback, 0); + } +} + +static void count_widgets(void) { + widget_count = 0; + container_count = 1; + if(toplevel) + gtk_container_foreach(GTK_CONTAINER(toplevel), count_callback, 0); + fprintf(stderr, "widget count: %8d container count: %8d\n", + widget_count, container_count); +} +#endif + /* Called once every 10 minutes */ static gboolean periodic(gpointer attribute((unused)) data) { D(("periodic")); @@ -259,6 +281,10 @@ static gboolean periodic(gpointer attribute((unused)) data) { /* Update everything to be sure that the connection to the server hasn't * mysteriously gone stale on us. */ all_update(); +#if MDEBUG + count_widgets(); + fprintf(stderr, "cache size: %zu\n", cache_count()); +#endif return TRUE; /* don't remove me */ } @@ -349,7 +375,11 @@ int main(int argc, char **argv) { return 1; /* already reported an error */ disorder_eclient_log(logclient, &gdisorder_log_callbacks, 0); /* periodic operations (e.g. expiring the cache) */ +#if MDEBUG + g_timeout_add(5000/*milliseconds*/, periodic, 0); +#else g_timeout_add(600000/*milliseconds*/, periodic, 0); +#endif /* The point of this is to try and get a handle on mysterious * unresponsiveness. It's not very useful in production use. */ if(0) diff --git a/lib/cache.c b/lib/cache.c index 1379f66..c6624e8 100644 --- a/lib/cache.c +++ b/lib/cache.c @@ -97,6 +97,10 @@ void cache_clean(const struct cache_type *type) { hash_foreach(h, clean_callback, (void *)type); } +size_t cache_count(void) { + return h ? hash_count(h) : 0; +} + /* Local Variables: c-basic-offset:2 diff --git a/lib/cache.h b/lib/cache.h index 7a49fd9..48aba1c 100644 --- a/lib/cache.h +++ b/lib/cache.h @@ -41,6 +41,9 @@ void cache_expire(void); void cache_clean(const struct cache_type *type); /* Clean all elements of a particular type, or all elements if TYPE=0 */ +size_t cache_count(void); +/* Return the size of the cache */ + #endif /* CACHE_H */ /* -- [mdw]