diff options
author | Akira TAGOH <akira@tagoh.org> | 2006-06-17 18:56:33 +0000 |
---|---|---|
committer | Akira TAGOH <akira@tagoh.org> | 2006-06-17 18:56:33 +0000 |
commit | 072b74112d9f7f0c0b2eb47d6e921db0d8e00a18 (patch) | |
tree | bed6aa315943960663844a768e0a69882eb418e6 /src | |
parent | 1fbf66f5d1cee5d4aab1ce1249a7cc2197c3f5eb (diff) |
* src/visualizer.c (hg_memory_visualizer_class_init): added gc-started
and gc-finished signals.
(hg_memory_visualizer_notify_gc_state): new function.
* src/hgspy.c (_hgspy_gc_started_cb): new function.
(_hgspy_gc_finished_cb): new function.
(main): added a statusbar.
* src/hgspy_helper.c (helper_init): watch hg_mem_garbage_collection too.
(hg_mem_garbage_collection): new function.
Diffstat (limited to 'src')
-rw-r--r-- | src/hgspy.c | 43 | ||||
-rw-r--r-- | src/hgspy_helper.c | 17 | ||||
-rw-r--r-- | src/visualizer.c | 37 | ||||
-rw-r--r-- | src/visualizer.h | 2 |
4 files changed, 98 insertions, 1 deletions
diff --git a/src/hgspy.c b/src/hgspy.c index afcffae..3204f89 100644 --- a/src/hgspy.c +++ b/src/hgspy.c @@ -40,6 +40,7 @@ typedef struct _HieroGlyphSpy HgSpy; struct _HieroGlyphSpy { GtkWidget *window; + GtkWidget *status; GtkWidget *visualizer; GtkWidget *total_vm_size; GtkWidget *used_vm_size; @@ -53,6 +54,8 @@ struct _HieroGlyphSpy { gint error; gchar *statementedit_buffer; gboolean destroyed; + guint gc_status_ctxt_id; + guint gc_status_msg_id; }; static void _hgspy_update_vm_status(HgMemoryVisualizer *visual, @@ -510,6 +513,34 @@ _hgspy_draw_updated_cb(HgMemoryVisualizer *visual, } static void +_hgspy_gc_started_cb(HgMemoryVisualizer *visual, + gpointer data) +{ + HgSpy *spy = data; + + g_return_if_fail (HG_IS_MEMORY_VISUALIZER (visual)); + g_return_if_fail (data != NULL); + + spy->gc_status_msg_id = gtk_statusbar_push(GTK_STATUSBAR (spy->status), + spy->gc_status_ctxt_id, + _("Collecting the garbages...")); +} + +static void +_hgspy_gc_finished_cb(HgMemoryVisualizer *visual, + gpointer data) +{ + HgSpy *spy = data; + + g_return_if_fail (HG_IS_MEMORY_VISUALIZER (visual)); + g_return_if_fail (data != NULL); + + gtk_statusbar_remove(GTK_STATUSBAR (spy->status), + spy->gc_status_ctxt_id, + spy->gc_status_msg_id); +} + +static void _hgspy_entry_activate_cb(GtkWidget *widget, gpointer data) { @@ -703,6 +734,8 @@ main(int argc, spy->error = 0; spy->statementedit_buffer = NULL; spy->destroyed = FALSE; + spy->gc_status_ctxt_id = 0; + spy->gc_status_msg_id = 0; actions = gtk_action_group_new("MenuBar"); spy->ui = gtk_ui_manager_new(); @@ -717,6 +750,7 @@ main(int argc, spy->visualizer = ((GtkWidget * (*) (void))__hg_spy_helper_get_widget) (); spy->textview = gtk_text_view_new(); spy->entry = gtk_entry_new(); + spy->status = gtk_statusbar_new(); if (spy->visualizer == NULL) { g_warning("Failed to initialize a helper module."); @@ -747,6 +781,8 @@ main(int argc, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_text_view_set_editable(GTK_TEXT_VIEW (spy->textview), FALSE); gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW (spy->textview), GTK_WRAP_WORD_CHAR); + spy->gc_status_ctxt_id = gtk_statusbar_get_context_id(GTK_STATUSBAR (spy->status), + "Status for GC"); /* setup accelerators */ gtk_window_add_accel_group(GTK_WINDOW (spy->window), gtk_ui_manager_get_accel_group(spy->ui)); @@ -794,7 +830,8 @@ main(int argc, gtk_box_pack_start(GTK_BOX (vbox2), spy->entry, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX (hbox), vbox2, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX (hbox), table, FALSE, FALSE, 0); - gtk_box_pack_end(GTK_BOX (vbox), hbox, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX (vbox), hbox, FALSE, FALSE, 0); + gtk_box_pack_end(GTK_BOX (vbox), spy->status, FALSE, FALSE, 0); gtk_container_add(GTK_CONTAINER (spy->window), vbox); /* setup signals */ @@ -802,6 +839,10 @@ main(int argc, G_CALLBACK (_hgspy_pool_updated_cb), spy); g_signal_connect(spy->visualizer, "draw-updated", G_CALLBACK (_hgspy_draw_updated_cb), spy); + g_signal_connect(spy->visualizer, "gc-started", + G_CALLBACK (_hgspy_gc_started_cb), spy); + g_signal_connect(spy->visualizer, "gc-finished", + G_CALLBACK (_hgspy_gc_finished_cb), spy); g_signal_connect(spy->window, "delete-event", G_CALLBACK (_hgspy_quit_cb), spy); g_signal_connect(spy->entry, "activate", diff --git a/src/hgspy_helper.c b/src/hgspy_helper.c index 8eff821..6a90b14 100644 --- a/src/hgspy_helper.c +++ b/src/hgspy_helper.c @@ -37,6 +37,7 @@ static gpointer __hg_mem_pool_add_heap = NULL; static gpointer __hg_mem_alloc_with_flags = NULL; static gpointer __hg_mem_free = NULL; static gpointer __hg_mem_resize = NULL; +static gpointer __hg_mem_garbage_collection = NULL; static GModule *__handle = NULL; static GtkWidget *visual = NULL; @@ -72,6 +73,10 @@ helper_init(void) g_warning("Failed g_module_symbol: %s", g_module_error()); exit(1); } + if (!g_module_symbol(__handle, "hg_mem_garbage_collection", &__hg_mem_garbage_collection)) { + g_warning("Failed g_module_symbol: %s", g_module_error()); + exit(1); + } g_type_init(); visual = hg_memory_visualizer_new(); } @@ -196,6 +201,18 @@ hg_mem_resize(gpointer data, return retval; } +gboolean +hg_mem_garbage_collection(HgMemPool *pool) +{ + gboolean retval; + + hg_memory_visualizer_notify_gc_state(HG_MEMORY_VISUALIZER (visual), FALSE); + retval = ((gboolean (*) (HgMemPool *))__hg_mem_garbage_collection) (pool); + hg_memory_visualizer_notify_gc_state(HG_MEMORY_VISUALIZER (visual), TRUE); + + return retval; +} + /* * Public Functions */ diff --git a/src/visualizer.c b/src/visualizer.c index 6dc41d9..57804c7 100644 --- a/src/visualizer.c +++ b/src/visualizer.c @@ -39,6 +39,8 @@ enum { enum { POOL_UPDATED, DRAW_UPDATED, + GC_STARTED, + GC_FINISHED, LAST_SIGNAL }; @@ -48,6 +50,8 @@ struct _HgMemoryVisualizerClass { void (* pool_updated) (HgMemoryVisualizer *visual, gpointer list); void (* draw_updated) (HgMemoryVisualizer *visual); + void (* gc_started) (HgMemoryVisualizer *visual); + void (* gc_finished) (HgMemoryVisualizer *visual); }; struct Heap2Offset { @@ -341,6 +345,20 @@ hg_memory_visualizer_class_init(HgMemoryVisualizerClass *klass) NULL, NULL, gtk_marshal_VOID__VOID, G_TYPE_NONE, 0); + signals[GC_STARTED] = g_signal_new("gc-started", + G_OBJECT_CLASS_TYPE (klass), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (HgMemoryVisualizerClass, gc_started), + NULL, NULL, + gtk_marshal_VOID__VOID, + G_TYPE_NONE, 0); + signals[GC_FINISHED] = g_signal_new("gc-finished", + G_OBJECT_CLASS_TYPE (klass), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (HgMemoryVisualizerClass, gc_finished), + NULL, NULL, + gtk_marshal_VOID__VOID, + G_TYPE_NONE, 0); } static void @@ -806,3 +824,22 @@ hg_memory_visualizer_get_current_pool_name(HgMemoryVisualizer *visual) { return visual->current_pool_name; } + +void +hg_memory_visualizer_notify_gc_state(HgMemoryVisualizer *visual, + gboolean is_finished) +{ + gdk_threads_enter(); + if (is_finished) + g_signal_emit(visual, signals[GC_FINISHED], 0); + else + g_signal_emit(visual, signals[GC_STARTED], 0); + gdk_threads_leave(); + + G_LOCK (visualizer); + + visual->need_update = TRUE; + _hg_memory_visualizer_add_idle(visual); + + G_UNLOCK (visualizer); +} diff --git a/src/visualizer.h b/src/visualizer.h index 92223fc..f8e0c3a 100644 --- a/src/visualizer.h +++ b/src/visualizer.h @@ -69,6 +69,8 @@ void hg_memory_visualizer_change_pool (HgMemoryVisualizer *visu gsize hg_memory_visualizer_get_used_size (HgMemoryVisualizer *visual, const gchar *name); const gchar *hg_memory_visualizer_get_current_pool_name(HgMemoryVisualizer *visual); +void hg_memory_visualizer_notify_gc_state (HgMemoryVisualizer *visual, + gboolean is_finished); G_END_DECLS |