]> git.street.me.uk Git - andy/viking.git/commitdiff
Add map cache information to be accessible from the GUI only in debug mode.
authorRob Norris <rw_norris@hotmail.com>
Sun, 13 Jul 2014 11:16:40 +0000 (12:16 +0100)
committerRob Norris <rw_norris@hotmail.com>
Sun, 13 Jul 2014 11:54:33 +0000 (12:54 +0100)
src/mapcache.c
src/mapcache.h
src/vikwindow.c

index eaa3fb2ba0019055b419e4cfc8492b3c641301e6..2641a9fa6799c152af6aad2f0d7d39ddaae51b69 100644 (file)
@@ -125,7 +125,6 @@ void a_mapcache_add ( GdkPixbuf *pixbuf, gint x, gint y, gint z, guint16 type, g
 {
   guint nn = name ? g_str_hash ( name ) : 0;
   gchar *key = g_strdup_printf ( HASHKEY_FORMAT_STRING, x, y, z, type, zoom, nn, alpha, xshrinkfactor, yshrinkfactor );
-  static int tmp = 0;
 
   g_mutex_lock(mc_mutex);
   cache_add(key, pixbuf);
@@ -151,7 +150,8 @@ void a_mapcache_add ( GdkPixbuf *pixbuf, gint x, gint y, gint z, guint16 type, g
   }
   g_mutex_unlock(mc_mutex);
 
-  if ( (++tmp == 100 ))  { g_print("DEBUG: queue count=%d size=%u\n", queue_count, cache_size ); tmp=0; }
+  static int tmp = 0;
+  if ( (++tmp == 100 )) { g_debug("DEBUG: cache count=%d size=%u list count=%d\n", g_hash_table_size(cache), cache_size, queue_count ); tmp=0; }
 }
 
 GdkPixbuf *a_mapcache_get ( gint x, gint y, gint z, guint16 type, gint zoom, guint8 alpha, gdouble xshrinkfactor, gdouble yshrinkfactor, const gchar* name )
@@ -235,3 +235,15 @@ void a_mapcache_uninit ()
   /* free list */
   cache = NULL;
 }
+
+// Size of mapcache in memory
+gint a_mapcache_get_size ()
+{
+  return cache_size;
+}
+
+// Count of items in the mapcache
+gint a_mapcache_get_count ()
+{
+  return g_hash_table_size ( cache );
+}
index 3227fea9f6533bc1e599b3c792594b9eb0f41e09..6c68e4be063c97d045ce4d3f2e0738b2f78c671c 100644 (file)
@@ -34,6 +34,9 @@ void a_mapcache_remove_all_shrinkfactors ( gint x, gint y, gint z, guint16 type,
 void a_mapcache_flush ();
 void a_mapcache_uninit ();
 
+gint a_mapcache_get_size ();
+gint a_mapcache_get_count ();
+
 G_END_DECLS
 
 #endif
index e783e9a64f1d7570df3db4bda857d1891c5547d1..55602581445d718419bb116066de482fef305249 100644 (file)
@@ -2351,6 +2351,14 @@ static void help_about_cb ( GtkAction *a, VikWindow *vw )
   a_dialog_about(GTK_WINDOW(vw));
 }
 
+static void help_cache_info_cb ( GtkAction *a, VikWindow *vw )
+{
+  // NB: No i18n as this is just for debug
+  char sz[64];
+  g_sprintf(sz, "Map Cache size is %d with %d items", a_mapcache_get_size(), a_mapcache_get_count());
+  a_dialog_info_msg_extra ( GTK_WINDOW(vw), "%s", sz );
+}
+
 static void menu_delete_layer_cb ( GtkAction *a, VikWindow *vw )
 {
   if ( vik_layers_panel_get_selected ( vw->viking_vlp ) )
@@ -4055,6 +4063,10 @@ static GtkActionEntry entries[] = {
   { "About",     GTK_STOCK_ABOUT,        N_("_About"),                        NULL,         NULL,                                           (GCallback)help_about_cb    },
 };
 
+static GtkActionEntry debug_entries[] = {
+  { "MapCacheInfo", NULL,                "_Map Cache Info",                   NULL,         NULL,                                           (GCallback)help_cache_info_cb    },
+};
+
 static GtkActionEntry entries_gpsbabel[] = {
   { "ExportKML", NULL,                   N_("_KML..."),                      NULL,         N_("Export as KML"),                                (GCallback)export_to_kml },
 };
@@ -4115,6 +4127,14 @@ static void window_create_ui( VikWindow *window )
   gtk_action_group_add_actions (action_group, entries, G_N_ELEMENTS (entries), window);
   gtk_action_group_add_toggle_actions (action_group, toggle_entries, G_N_ELEMENTS (toggle_entries), window);
   gtk_action_group_add_radio_actions (action_group, mode_entries, G_N_ELEMENTS (mode_entries), 4, (GCallback)window_change_coord_mode_cb, window);
+  if ( vik_debug ) {
+    if ( gtk_ui_manager_add_ui_from_string ( uim,
+         "<ui><menubar name='MainMenu'><menu action='Help'><menuitem action='MapCacheInfo'/></menu></menubar></ui>",
+         -1, NULL ) ) {
+      gtk_action_group_add_actions (action_group, debug_entries, G_N_ELEMENTS (debug_entries), window);
+    }
+  }
+
 
   // Use this to see if GPSBabel is available:
   if ( a_babel_available () ) {