chiark / gitweb /
report cache size with MDEBUG
authorrjk@greenend.org.uk <>
Sun, 29 Jul 2007 17:10:55 +0000 (18:10 +0100)
committerrjk@greenend.org.uk <>
Sun, 29 Jul 2007 17:10:55 +0000 (18:10 +0100)
disobedience/disobedience.c
lib/cache.c
lib/cache.h

index c37d0bcf82aace38ea037b3711ca3de07c870f5c..cb5bb33edd35da0ec289ee7f5e8f078ec076f91d 100644 (file)
@@ -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)
index 1379f666008067a38894fc321a650aee877c2d1f..c6624e89d0f4b6ba04a0f2b39670bd64601de4a2 100644 (file)
@@ -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
index 7a49fd9079df1bf96fda5b18f7d6bae386e868d4..48aba1c80e88a61eed830ab446c88df344e4d0e4 100644 (file)
@@ -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 */
 
 /*