From 087550e5ac7d8800952aa7aaae29317f492c9768 Mon Sep 17 00:00:00 2001 From: Akira TAGOH Date: Thu, 15 Jun 2006 03:46:45 +0000 Subject: * hieroglyph/hgallocator-bfit.c (_hg_allocator_bfit_real_garbage_collection): use a flag instead of mutex lock. * src/visualizer.c (hg_memory_visualizer_real_destroy): free a node in pool_name_list. (_hg_memory_visualizer_compare_pool_name_list): new function. (hg_memory_visualizer_remove_pool): new function. * src/hgspy.c (_hgspy_vm_thread): finalize vm instance. (_hgspy_pool_updated_cb): allow NULL for name and add None item to menu when no menuitem is added. (_hgspy_update_vm_status): clear text when name is NULL. * src/hgspy_helper.c (helper_init): watch hg_mem_pool_destroy as well. (hg_mem_pool_destroy): new function. --- src/hgspy.c | 43 ++++++++++++++++++++++--------------- src/hgspy_helper.c | 17 +++++++++++++++ src/visualizer.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++---- src/visualizer.h | 2 ++ 4 files changed, 104 insertions(+), 21 deletions(-) (limited to 'src') diff --git a/src/hgspy.c b/src/hgspy.c index 0c4d56e..922e920 100644 --- a/src/hgspy.c +++ b/src/hgspy.c @@ -64,6 +64,7 @@ _hgspy_vm_thread(gpointer data) libretto_vm_init(); spy->vm = libretto_vm_new(LB_EMULATION_LEVEL_1); libretto_vm_startjob(spy->vm, spy->file, TRUE); + libretto_vm_finalize(); return NULL; } @@ -202,7 +203,6 @@ _hgspy_pool_updated_cb(HgMemoryVisualizer *visual, gulong sigid; g_return_if_fail (HG_IS_MEMORY_VISUALIZER (visual)); - g_return_if_fail (list != NULL); bin = gtk_ui_manager_get_widget(spy->ui, "/MenuBar/ViewMenu/PoolMenu"); menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM (bin)); @@ -229,6 +229,12 @@ _hgspy_pool_updated_cb(HgMemoryVisualizer *visual, gtk_menu_shell_append(GTK_MENU_SHELL (menu), menuitem); gtk_widget_show(menuitem); } + if (sigwidget == NULL) { + menuitem = gtk_menu_item_new_with_label(_("None")); + gtk_menu_shell_append(GTK_MENU_SHELL (menu), menuitem); + gtk_widget_set_sensitive(menuitem, FALSE); + gtk_widget_show(menuitem); + } g_object_set_data(G_OBJECT (menu), "signal-widget-list", sigwidget); gtk_menu_item_set_submenu(GTK_MENU_ITEM (bin), menu); } @@ -244,9 +250,7 @@ _hgspy_draw_updated_cb(HgMemoryVisualizer *visual, g_return_if_fail (data != NULL); name = hg_memory_visualizer_get_current_pool_name(visual); - if (name) { - _hgspy_update_vm_status(visual, spy, name); - } + _hgspy_update_vm_status(visual, spy, name); } static void @@ -259,19 +263,24 @@ _hgspy_update_vm_status(HgMemoryVisualizer *visual, g_return_if_fail (HG_IS_MEMORY_VISUALIZER (visual)); g_return_if_fail (spy != NULL); - g_return_if_fail (name != NULL); - - total = hg_memory_visualizer_get_max_size(visual, name); - p = g_strdup_printf("%d", total); - gtk_entry_set_text(GTK_ENTRY (spy->total_vm_size), p); - g_free(p); - used = hg_memory_visualizer_get_used_size(visual, name); - p = g_strdup_printf("%d", used); - gtk_entry_set_text(GTK_ENTRY (spy->used_vm_size), p); - g_free(p); - p = g_strdup_printf("%d", total - used); - gtk_entry_set_text(GTK_ENTRY (spy->free_vm_size), p); - g_free(p); + + if (name) { + total = hg_memory_visualizer_get_max_size(visual, name); + p = g_strdup_printf("%d", total); + gtk_entry_set_text(GTK_ENTRY (spy->total_vm_size), p); + g_free(p); + used = hg_memory_visualizer_get_used_size(visual, name); + p = g_strdup_printf("%d", used); + gtk_entry_set_text(GTK_ENTRY (spy->used_vm_size), p); + g_free(p); + p = g_strdup_printf("%d", total - used); + gtk_entry_set_text(GTK_ENTRY (spy->free_vm_size), p); + g_free(p); + } else { + gtk_entry_set_text(GTK_ENTRY (spy->total_vm_size), ""); + gtk_entry_set_text(GTK_ENTRY (spy->used_vm_size), ""); + gtk_entry_set_text(GTK_ENTRY (spy->free_vm_size), ""); + } } /* diff --git a/src/hgspy_helper.c b/src/hgspy_helper.c index 14ac3ae..8eff821 100644 --- a/src/hgspy_helper.c +++ b/src/hgspy_helper.c @@ -32,6 +32,7 @@ #include "visualizer.h" +static gpointer __hg_mem_pool_destroy = NULL; static gpointer __hg_mem_pool_add_heap = NULL; static gpointer __hg_mem_alloc_with_flags = NULL; static gpointer __hg_mem_free = NULL; @@ -51,6 +52,10 @@ helper_init(void) g_warning("Failed g_module_open: %s", g_module_error()); exit(1); } + if (!g_module_symbol(__handle, "hg_mem_pool_destroy", &__hg_mem_pool_destroy)) { + g_warning("Failed g_module_symbol: %s", g_module_error()); + exit(1); + } if (!g_module_symbol(__handle, "hg_mem_pool_add_heap", &__hg_mem_pool_add_heap)) { g_warning("Failed g_module_symbol: %s", g_module_error()); exit(1); @@ -81,6 +86,18 @@ helper_finalize(void) /* * preload functions */ +void +hg_mem_pool_destroy(HgMemPool *pool) +{ + gchar *pool_name = g_strdup(hg_mem_pool_get_name(pool)); + + ((void (*) (HgMemPool *))__hg_mem_pool_destroy) (pool); + + hg_memory_visualizer_remove_pool(HG_MEMORY_VISUALIZER (visual), + pool_name); + g_free(pool_name); +} + void hg_mem_pool_add_heap(HgMemPool *pool, HgHeap *heap) diff --git a/src/visualizer.c b/src/visualizer.c index 86178c1..c324e7b 100644 --- a/src/visualizer.c +++ b/src/visualizer.c @@ -66,7 +66,7 @@ struct _HgMemoryVisualizer { GHashTable *pool2used_size; GHashTable *pool2array; GSList *pool_name_list; - const gchar *current_pool_name; + gchar *current_pool_name; struct Heap2Offset *current_h2o; gboolean need_update; guint idle_id; @@ -153,6 +153,10 @@ hg_memory_visualizer_real_destroy(GtkObject *object) visual->pool2array = NULL; } if (visual->pool_name_list) { + GSList *l; + + for (l = visual->pool_name_list; l != NULL; l = g_slist_next(l)) + g_free(l->data); g_slist_free(visual->pool_name_list); visual->pool_name_list = NULL; } @@ -577,6 +581,13 @@ _hg_memory_visualizer_redraw_in_pixmap(HgMemoryVisualizer *visual) } } +static gint +_hg_memory_visualizer_compare_pool_name_list(gconstpointer a, + gconstpointer b) +{ + return strcmp(a, b); +} + /* * Public Functions */ @@ -686,12 +697,49 @@ hg_memory_visualizer_set_heap_state(HgMemoryVisualizer *visual, visual->pool_name_list = g_slist_append(visual->pool_name_list, g_strdup(name)); if (visual->current_pool_name == NULL) { - visual->current_pool_name = name; + visual->current_pool_name = g_strdup(name); visual->current_h2o = h2o; } g_signal_emit(visual, signals[POOL_UPDATED], 0, visual->pool_name_list); } +void +hg_memory_visualizer_remove_pool(HgMemoryVisualizer *visual, + const gchar *name) +{ + GSList *l; + + g_return_if_fail (HG_IS_MEMORY_VISUALIZER (visual)); + g_return_if_fail (name != NULL); + + if ((l = g_slist_find_custom(visual->pool_name_list, + name, + _hg_memory_visualizer_compare_pool_name_list)) == NULL) { + g_warning("pool %s isn't registered.", name); + return; + } + + G_LOCK (visualizer); + + g_hash_table_remove(visual->pool2total_size, name); + g_hash_table_remove(visual->pool2used_size, name); + g_hash_table_remove(visual->pool2array, name); + g_free(l->data); + visual->pool_name_list = g_slist_delete_link(visual->pool_name_list, l); + + if (strcmp(name, visual->current_pool_name) == 0) { + const gchar *pool_name; + + if (visual->pool_name_list) + pool_name = visual->pool_name_list->data; + else + pool_name = ""; + hg_memory_visualizer_change_pool(visual, pool_name); + } + + G_UNLOCK (visualizer); +} + void hg_memory_visualizer_set_chunk_state(HgMemoryVisualizer *visual, const gchar *name, @@ -754,13 +802,20 @@ hg_memory_visualizer_change_pool(HgMemoryVisualizer *visual, g_return_if_fail (name != NULL); if (g_slist_find(visual->pool_name_list, name) != NULL) { - visual->current_pool_name = name; + if (visual->current_pool_name) + g_free(visual->current_pool_name); + visual->current_pool_name = g_strdup(name); visual->current_h2o = g_hash_table_lookup(visual->pool2array, name); - _hg_memory_visualizer_redraw_in_pixmap(visual); } else { /* send a signal to update the out of date list */ + if (visual->current_pool_name) + g_free(visual->current_pool_name); + visual->current_pool_name = NULL; + visual->current_h2o = NULL; g_signal_emit(visual, signals[POOL_UPDATED], 0, visual->pool_name_list); } + visual->need_update = TRUE; + _hg_memory_visualizer_add_idle(visual); } gsize diff --git a/src/visualizer.h b/src/visualizer.h index 10acb70..92223fc 100644 --- a/src/visualizer.h +++ b/src/visualizer.h @@ -56,6 +56,8 @@ gsize hg_memory_visualizer_get_max_size (HgMemoryVisualizer *visu void hg_memory_visualizer_set_heap_state (HgMemoryVisualizer *visual, const gchar *name, HgHeap *heap); +void hg_memory_visualizer_remove_pool (HgMemoryVisualizer *visual, + const gchar *name); void hg_memory_visualizer_set_chunk_state (HgMemoryVisualizer *visual, const gchar *name, gint heap_id, -- cgit v1.2.3