Patch from James Liggett <jrliggett@cox.net>:
[anjuta-git-plugin.git] / plugins / profiler / plugin.c
blobe18f2806f217778ea07e07dd31d82d8a4e472939
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * plugin.c
4 * Copyright (C) James Liggett 2006 <jrliggett@cox.net>
5 *
6 * plugin.c is free software.
7 *
8 * You may redistribute it and/or modify it under the terms of the
9 * GNU General Public License, as published by the Free Software
10 * Foundation; either version 2, or (at your option) any later version.
12 * plugin.c is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15 * See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with plugin.c. See the file "COPYING". If not,
19 * write to: The Free Software Foundation, Inc.,
20 * 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
25 #include "plugin.h"
28 #define UI_FILE PACKAGE_DATA_DIR"/ui/profiler.ui"
29 #define GLADE_FILE PACKAGE_DATA_DIR"/glade/profiler.glade"
30 #define ICON_FILE PACKAGE_PIXMAPS_DIR"/profiler.png"
32 static gpointer parent_class;
34 static void
35 add_options_strings (GPtrArray *options, const gchar *prefix, const gchar *args)
37 gchar **split_args; /* List of arguements split by lines */
38 gchar **current_string;
39 gchar *full_arg; /* Argument with prefix */
41 if (strlen (args) > 0)
43 split_args = g_strsplit (args, "\n", -1);
45 for (current_string = split_args;
46 *current_string;
47 current_string++)
50 if (strlen (*current_string) > 0)
52 full_arg = g_strconcat (prefix, *current_string, NULL);
53 g_ptr_array_add (options, full_arg);
57 g_strfreev (split_args);
61 static GPtrArray *
62 setup_options (Profiler *profiler)
64 GPtrArray *options;
65 gchar *symbols;
67 options = g_ptr_array_new ();
69 /* First handle the easy ones: -a, -c, and -z */
70 if (anjuta_preferences_get_int (profiler->prefs,
71 "profiler.no_show_static"))
73 g_ptr_array_add (options, g_strdup ("-a"));
76 if (anjuta_preferences_get_int (profiler->prefs,
77 "profiler.show_possible_called"))
79 g_ptr_array_add (options, g_strdup ("-c"));
82 if (anjuta_preferences_get_int (profiler->prefs,
83 "profiler.show_uncalled"))
85 g_ptr_array_add (options, g_strdup ("-z"));
88 /* If the user wants to modify the call graph, put in -p so we have a flat
89 * profile. */
90 if (!anjuta_preferences_get_int (profiler->prefs,
91 "profiler.show_all_symbols"))
93 g_ptr_array_add (options, g_strdup ("-p"));
95 symbols = anjuta_preferences_get (profiler->prefs,
96 "profiler.symbols");
98 if (anjuta_preferences_get_int (profiler->prefs,
99 "profiler.include_symbols"))
101 add_options_strings (options, "-q", symbols);
104 if (anjuta_preferences_get_int (profiler->prefs,
105 "profiler.exclude_symbols"))
107 add_options_strings (options, "-Q", symbols);
110 g_free (symbols);
113 /* Time propagation options */
114 if (!anjuta_preferences_get_int (profiler->prefs,
115 "profiler_propagate_all_symbols"))
118 symbols = anjuta_preferences_get (profiler->prefs,
119 "profiler.propagation_symbols");
121 if (anjuta_preferences_get_int (profiler->prefs,
122 "profiler.propagate_include_symbols"))
124 add_options_strings (options, "-n", symbols);
127 if (anjuta_preferences_get_int (profiler->prefs,
128 "profiler.propagate_exclude_symbols"))
130 add_options_strings (options, "-N", symbols);
133 g_free (symbols);
136 /* NULL terminate the array for compatibility with g_strfreev */
138 g_ptr_array_add (options, NULL);
140 /* Other options not directly passed to gprof */
142 /* If there is an existing profile data monitor and automatic refresh
143 * is disabled, cancel the monitor */
145 if (profiler->profile_data_monitor)
147 if (!anjuta_preferences_get_int (profiler->prefs,
148 "profiler.automatic_refresh"))
150 gnome_vfs_monitor_cancel (profiler->profile_data_monitor);
151 profiler->profile_data_monitor = NULL;
155 return options;
158 static gboolean
159 profiler_get_data (Profiler *profiler)
161 GPtrArray *options;
162 gchar **option_strings;
163 gboolean ret = FALSE;
165 if (profiler->profile_target_path)
168 options = setup_options (profiler);
169 if (!gprof_profile_data_init_profile (profiler->profile_data,
170 profiler->profile_target_path,
171 options))
173 anjuta_util_dialog_error (ANJUTA_PLUGIN (profiler)->shell,
174 _("Could not get profiling data."
175 "\n\n"
176 "Please check the path to "
177 "this target's profiling data file"));
180 option_strings = (gchar **) g_ptr_array_free (options, FALSE);
181 g_strfreev (option_strings);
183 ret = TRUE;
186 return ret;
189 static void
190 on_profile_data_changed (GnomeVFSMonitorHandle *handle,
191 const gchar *monitor_uri, const gchar *info_uri,
192 GnomeVFSMonitorEventType event,
193 gpointer user_data)
195 Profiler *profiler;
197 profiler = PROFILER (user_data);
199 switch (event)
201 case GNOME_VFS_MONITOR_EVENT_CHANGED:
202 if (profiler_get_data (profiler))
203 gprof_view_manager_refresh_views (profiler->view_manager);
204 break;
205 case GNOME_VFS_MONITOR_EVENT_DELETED:
206 gnome_vfs_monitor_cancel (handle);
207 profiler->profile_data_monitor = NULL;
208 break;
209 default:
210 break;
214 static void
215 profiler_set_target (Profiler *profiler, const gchar *profile_target_uri)
217 gchar *profile_target_path;
218 gchar *profile_target_dir;
219 gchar *gmon_out_path;
220 gchar *gmon_out_uri;
222 if (profiler->profile_target_path)
224 g_free (profiler->profile_target_path);
225 profiler->profile_target_path = NULL;
228 if (profile_target_uri)
230 profile_target_path = gnome_vfs_get_local_path_from_uri (profile_target_uri);
231 profile_target_dir = g_path_get_dirname (profile_target_path);
232 gmon_out_path = g_build_filename (profile_target_dir, "gmon.out",
233 NULL);
234 gmon_out_uri = gnome_vfs_get_uri_from_local_path (gmon_out_path);
236 if (g_file_test (gmon_out_path, G_FILE_TEST_EXISTS))
238 profiler->profile_target_path = profile_target_path;
241 /* Set up a file change monitor for automatic refresh if enabled */
242 if (anjuta_preferences_get_int (profiler->prefs,
243 "profiler.automatic_refresh"))
245 /* Cancel any existing monitor */
246 if (profiler->profile_data_monitor)
247 gnome_vfs_monitor_cancel (profiler->profile_data_monitor);
249 gnome_vfs_monitor_add (&profiler->profile_data_monitor,
250 gmon_out_uri, GNOME_VFS_MONITOR_FILE,
251 on_profile_data_changed,
252 (gpointer) profiler);
255 /* Show user the profiler views if they aren't visible so they
256 * know what happened */
257 anjuta_shell_present_widget (ANJUTA_PLUGIN (profiler)->shell,
258 gprof_view_manager_get_notebook (profiler->view_manager),
259 NULL);
261 else
263 anjuta_util_dialog_error (GTK_WINDOW (ANJUTA_PLUGIN (profiler)->shell),
264 _("This target does not have any "
265 "profiling data.\n\n"
266 "Please ensure that the target is "
267 "complied with profiling support "
268 "and that it is run at least "
269 "once."));
272 g_free (profile_target_dir);
273 g_free (gmon_out_path);
274 g_free (gmon_out_uri);
278 static AnjutaPreferences *
279 register_preferences (GladeXML *gxml)
281 AnjutaPreferences *preferences;
282 GtkWidget *prefs_widget; /* Widget regestered with prefs */
284 preferences = ANJUTA_PREFERENCES (anjuta_preferences_new ());
286 prefs_widget = glade_xml_get_widget (gxml, "automatic_refresh_check");
287 anjuta_preferences_register_property_raw (preferences, prefs_widget,
288 "profiler.automatic_refresh",
289 "0", 0,
290 ANJUTA_PROPERTY_OBJECT_TYPE_TOGGLE,
291 ANJUTA_PROPERTY_DATA_TYPE_BOOL);
293 prefs_widget = glade_xml_get_widget (gxml, "no_show_static_check");
294 anjuta_preferences_register_property_raw (preferences, prefs_widget,
295 "profiler.no_show_static",
296 "0", 0,
297 ANJUTA_PROPERTY_OBJECT_TYPE_TOGGLE,
298 ANJUTA_PROPERTY_DATA_TYPE_BOOL);
300 prefs_widget = glade_xml_get_widget (gxml, "show_possible_called_check");
301 anjuta_preferences_register_property_raw (preferences, prefs_widget,
302 "profiler.show_possible_called",
303 "0", 0,
304 ANJUTA_PROPERTY_OBJECT_TYPE_TOGGLE,
305 ANJUTA_PROPERTY_DATA_TYPE_BOOL);
307 prefs_widget = glade_xml_get_widget (gxml, "show_uncalled_check");
308 anjuta_preferences_register_property_raw (preferences, prefs_widget,
309 "profiler.show_uncalled",
310 "0", 0,
311 ANJUTA_PROPERTY_OBJECT_TYPE_TOGGLE,
312 ANJUTA_PROPERTY_DATA_TYPE_BOOL);
314 prefs_widget = glade_xml_get_widget (gxml, "show_all_symbols_radio");
315 anjuta_preferences_register_property_raw (preferences, prefs_widget,
316 "profiler.show_all_symbols",
317 "1", 0,
318 ANJUTA_PROPERTY_OBJECT_TYPE_TOGGLE,
319 ANJUTA_PROPERTY_DATA_TYPE_BOOL);
321 prefs_widget = glade_xml_get_widget (gxml, "include_symbols_radio");
322 anjuta_preferences_register_property_raw (preferences, prefs_widget,
323 "profiler.include_symbols",
324 "0", 0,
325 ANJUTA_PROPERTY_OBJECT_TYPE_TOGGLE,
326 ANJUTA_PROPERTY_DATA_TYPE_BOOL);
328 prefs_widget = glade_xml_get_widget (gxml, "exclude_symbols_radio");
329 anjuta_preferences_register_property_raw (preferences, prefs_widget,
330 "profiler.exclude_symbols",
331 "0", 0,
332 ANJUTA_PROPERTY_OBJECT_TYPE_TOGGLE,
333 ANJUTA_PROPERTY_DATA_TYPE_BOOL);
335 prefs_widget = glade_xml_get_widget (gxml, "symbols_text_view");
336 anjuta_preferences_register_property_raw (preferences, prefs_widget,
337 "profiler.symbols",
338 "", 0,
339 ANJUTA_PROPERTY_OBJECT_TYPE_TEXT,
340 ANJUTA_PROPERTY_DATA_TYPE_TEXT);
343 prefs_widget = glade_xml_get_widget (gxml, "propagate_all_symbols_radio");
344 anjuta_preferences_register_property_raw (preferences, prefs_widget,
345 "profiler.propagate_all_symbols",
346 "0", 0,
347 ANJUTA_PROPERTY_OBJECT_TYPE_TOGGLE,
348 ANJUTA_PROPERTY_DATA_TYPE_BOOL);
350 prefs_widget = glade_xml_get_widget (gxml, "propagate_include_symbols_radio");
351 anjuta_preferences_register_property_raw (preferences, prefs_widget,
352 "profiler.propagate_include_symbols",
353 "0", 0,
354 ANJUTA_PROPERTY_OBJECT_TYPE_TOGGLE,
355 ANJUTA_PROPERTY_DATA_TYPE_BOOL);
357 prefs_widget = glade_xml_get_widget (gxml, "propagate_exclude_symbols_radio");
358 anjuta_preferences_register_property_raw (preferences, prefs_widget,
359 "profiler.propagate_exclude_symbols",
360 "0", 0,
361 ANJUTA_PROPERTY_OBJECT_TYPE_TOGGLE,
362 ANJUTA_PROPERTY_DATA_TYPE_BOOL);
364 prefs_widget = glade_xml_get_widget (gxml, "propagation_text_view");
365 anjuta_preferences_register_property_raw (preferences, prefs_widget,
366 "profiler.propagation_symbols",
367 "", 0,
368 ANJUTA_PROPERTY_OBJECT_TYPE_TEXT,
369 ANJUTA_PROPERTY_DATA_TYPE_TEXT);
371 return preferences;
374 static void
375 on_profiling_options_button_clicked (GtkButton *button, gpointer *user_data)
377 Profiler *profiler;
378 GtkWidget *profiling_options_dialog;
380 profiler = PROFILER (user_data);
381 profiling_options_dialog = glade_xml_get_widget (profiler->prefs_gxml,
382 "profiling_options_dialog");
384 gtk_widget_show (GTK_WIDGET (profiler->prefs));
385 gtk_widget_hide (GTK_WIDGET (profiler->prefs));
386 gtk_dialog_run (GTK_DIALOG (profiling_options_dialog));
388 gtk_widget_hide (profiling_options_dialog);
391 static void
392 on_profiler_select_target (GtkAction *action, Profiler *profiler)
394 GladeXML *gxml;
395 GtkWidget *select_target_dialog;
396 GtkWidget *profiling_options_button;
397 GtkWidget *targets_list_view;
398 GtkTreeViewColumn *column;
399 GtkCellRenderer *renderer;
400 GtkListStore *targets_list_store;
401 gint response;
402 GList *current_target;
403 GtkTreeIter iter;
404 GList *exec_targets;
405 IAnjutaProjectManager *project_manager;
406 GtkTreeSelection *selection;
407 GtkTreeModel *model;
408 gchar *target = NULL;
409 gchar *relative_path;
410 guint project_root_uri_length;
412 if (profiler->project_root_uri)
414 project_manager = anjuta_shell_get_interface (ANJUTA_PLUGIN (profiler)->shell,
415 IAnjutaProjectManager, NULL);
417 exec_targets = ianjuta_project_manager_get_targets (project_manager,
418 IANJUTA_PROJECT_MANAGER_TARGET_EXECUTABLE,
419 NULL);
421 project_root_uri_length = strlen (profiler->project_root_uri) + 1;
423 gxml = glade_xml_new (GLADE_FILE, "select_target_dialog", NULL);
424 select_target_dialog = glade_xml_get_widget (gxml,
425 "select_target_dialog");
426 targets_list_view = glade_xml_get_widget (gxml,
427 "targets_list_view");
428 profiling_options_button = glade_xml_get_widget (gxml,
429 "profiling_options_button");
431 g_signal_connect (profiling_options_button, "clicked",
432 G_CALLBACK (on_profiling_options_button_clicked),
433 profiler);
435 gtk_window_set_transient_for (GTK_WINDOW (select_target_dialog),
436 GTK_WINDOW (ANJUTA_PLUGIN(profiler)->shell));
438 if (exec_targets)
440 /* Populate listview */
441 gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW
442 (targets_list_view)),
443 GTK_SELECTION_BROWSE);
444 targets_list_store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
445 current_target = exec_targets;
447 while (current_target)
449 relative_path = (gchar *) current_target->data + project_root_uri_length;
451 gtk_list_store_append (targets_list_store, &iter);
452 gtk_list_store_set (targets_list_store, &iter, 0, relative_path, 1,
453 current_target->data, -1);
455 g_free (current_target->data);
456 current_target = g_list_next (current_target);
458 g_list_free (exec_targets);
460 gtk_tree_view_set_model (GTK_TREE_VIEW (targets_list_view),
461 GTK_TREE_MODEL (targets_list_store));
462 g_object_unref (targets_list_store);
464 column = gtk_tree_view_column_new ();
465 gtk_tree_view_column_set_sizing (column,
466 GTK_TREE_VIEW_COLUMN_AUTOSIZE);
468 renderer = gtk_cell_renderer_text_new ();
469 gtk_tree_view_column_pack_start (column, renderer, FALSE);
470 gtk_tree_view_column_add_attribute (column, renderer, "text",
472 gtk_tree_view_append_column (GTK_TREE_VIEW (targets_list_view), column);
473 gtk_tree_view_set_expander_column (GTK_TREE_VIEW (targets_list_view), column);
476 /* Run dialog */
477 response = gtk_dialog_run (GTK_DIALOG (select_target_dialog));
479 if (response == GTK_RESPONSE_OK)
481 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (targets_list_view));
483 if (gtk_tree_selection_get_selected (selection, &model, &iter))
485 gtk_tree_model_get (model, &iter, 1, &target, -1);
486 profiler_set_target (profiler, target);
488 if (profiler_get_data (profiler))
489 gprof_view_manager_refresh_views (profiler->view_manager);
491 else
492 profiler_set_target (profiler, NULL);
495 gtk_widget_destroy (select_target_dialog);
496 g_object_unref (gxml);
500 static void
501 on_profiler_refresh (GtkAction *action, Profiler *profiler)
503 if (profiler_get_data (profiler))
504 gprof_view_manager_refresh_views (profiler->view_manager);
507 static void
508 on_profiler_delete_data (GtkAction *action, Profiler *profiler)
510 gchar *profile_target_dir;
511 gchar *gmon_out_path;
513 if (profiler->profile_target_path)
515 profile_target_dir = g_path_get_dirname (profiler->profile_target_path);
516 gmon_out_path = g_build_filename (profile_target_dir, "gmon.out", NULL);
518 g_unlink (gmon_out_path);
520 g_free (profile_target_dir);
521 g_free (gmon_out_path);
525 static void
526 project_root_added (AnjutaPlugin *plugin, const gchar *name,
527 const GValue *value, gpointer user_data)
529 Profiler *profiler;
530 AnjutaUI *ui;
531 const gchar *root_uri;
532 GtkAction *action;
534 profiler = PROFILER (plugin);
535 root_uri = g_value_get_string (value);
537 if (root_uri)
539 g_free (profiler->project_root_uri);
540 profiler->project_root_uri = g_strdup (root_uri);
542 ui = anjuta_shell_get_ui (plugin->shell, NULL);
543 action = anjuta_ui_get_action (ui, "ActionGroupProfiler", "ActionMenuProfiler");
544 g_object_set (G_OBJECT (action), "sensitive", TRUE, NULL);
550 static void
551 project_root_removed (AnjutaPlugin *plugin, const gchar *name,
552 gpointer user_data)
554 Profiler *profiler;
555 AnjutaUI *ui;
556 GtkAction *action;
558 profiler = PROFILER (plugin);
560 g_free (profiler->project_root_uri);
561 profiler->project_root_uri = NULL;
563 ui = anjuta_shell_get_ui (plugin->shell, NULL);
564 action = anjuta_ui_get_action (ui, "ActionGroupProfiler", "ActionMenuProfiler");
565 g_object_set (G_OBJECT (action), "sensitive", FALSE, NULL);
570 static GtkActionEntry actions_file[] = {
572 "ActionMenuDebug", /* Action name */
573 NULL, /* Stock icon, if any */
574 N_("Debug"), /* Display label */
575 NULL, /* short-cut */
576 NULL, /* Tooltip */
577 NULL /* Action callback */
580 "ActionMenuProfiler", /* Action name */
581 "profiler-icon", /* Stock icon, if any */
582 N_("Profiler"), /* Display label */
583 NULL, /* short-cut */
584 NULL, /* Tooltip */
585 NULL /* Action callback */
588 "ActionProfilerSelectTarget", /* Action name */
589 GTK_STOCK_EXECUTE, /* Stock icon, if any */
590 N_("Select Target..."), /* Display label */
591 NULL, /* short-cut */
592 NULL, /* Tooltip */
593 G_CALLBACK (on_profiler_select_target) /* Action callback */
596 "ActionProfilerRefresh", /* Action name */
597 GTK_STOCK_REFRESH, /* Stock icon, if any */
598 N_("Refresh"), /* Display label */
599 NULL, /* short-cut */
600 NULL, /* Tooltip */
601 G_CALLBACK (on_profiler_refresh) /* Action callback */
604 "ActionProfilerDeleteData", /* Action name */
605 GTK_STOCK_DELETE, /* Stock icon, if any */
606 N_("Delete Data"), /* Display label */
607 NULL, /* short-cut */
608 NULL, /* Tooltip */
609 G_CALLBACK (on_profiler_delete_data) /* Action callback */
613 #define REGISTER_ICON(icon, stock_id) \
614 pixbuf = gdk_pixbuf_new_from_file (PACKAGE_PIXMAPS_DIR"/"icon, NULL); \
615 icon_set = gtk_icon_set_new_from_pixbuf (pixbuf); \
616 gtk_icon_factory_add (icon_factory, stock_id, icon_set); \
617 g_object_unref (pixbuf);
619 static void
620 register_stock_icons (AnjutaPlugin *plugin)
622 AnjutaUI *ui;
623 GtkIconFactory *icon_factory;
624 GtkIconSet *icon_set;
625 GdkPixbuf *pixbuf;
626 static gboolean registered = FALSE;
628 if (registered)
629 return;
630 registered = TRUE;
632 /* Register stock icons */
633 ui = anjuta_shell_get_ui (plugin->shell, NULL);
634 icon_factory = anjuta_ui_get_icon_factory (ui);
635 REGISTER_ICON ("profiler.png", "profiler-icon");
639 static gboolean
640 profiler_activate (AnjutaPlugin *plugin)
643 AnjutaUI *ui;
644 Profiler *profiler;
646 DEBUG_PRINT ("Profiler: Activating Profiler plugin ...");
647 profiler = PROFILER (plugin);
649 /* Add all UI actions and merge UI */
650 ui = anjuta_shell_get_ui (plugin->shell, NULL);
651 register_stock_icons (plugin);
653 profiler->action_group =
654 anjuta_ui_add_action_group_entries (ui, "ActionGroupProfiler",
655 _("Application Performance Profiler"),
656 actions_file,
657 G_N_ELEMENTS (actions_file),
658 GETTEXT_PACKAGE, TRUE,
659 plugin);
660 profiler->uiid = anjuta_ui_merge (ui, UI_FILE);
662 profiler->view_manager = gprof_view_manager_new ();
663 profiler->profile_data = gprof_profile_data_new ();
665 gprof_view_manager_add_view (profiler->view_manager,
666 GPROF_VIEW (gprof_flat_profile_view_new (profiler->profile_data)),
667 _("Flat Profile"));
668 gprof_view_manager_add_view (profiler->view_manager,
669 GPROF_VIEW (gprof_call_graph_view_new (profiler->profile_data)),
670 _("Call Graph"));
671 gprof_view_manager_add_view (profiler->view_manager,
672 GPROF_VIEW (gprof_function_call_tree_view_new (profiler->profile_data)),
673 _("Function Call Tree"));
675 #ifdef HAVE_GRAPHVIZ
676 gprof_view_manager_add_view (profiler->view_manager,
677 GPROF_VIEW (gprof_function_call_chart_view_new (profiler->profile_data)),
678 _("Function Call Chart"));
679 #endif
681 anjuta_shell_add_widget (plugin->shell,
682 gprof_view_manager_get_notebook (profiler->view_manager),
683 "Profiler",
684 _("Profiler"),
685 "profiler-icon",
686 ANJUTA_SHELL_PLACEMENT_CENTER,
687 NULL);
689 profiler->project_watch_id = anjuta_plugin_add_watch (plugin, "project_root_uri",
690 project_root_added,
691 project_root_removed, NULL);
693 profiler->prefs_gxml = glade_xml_new (GLADE_FILE, "profiling_options_dialog",
694 NULL);
695 profiler->prefs = register_preferences (profiler->prefs_gxml);
697 return TRUE;
700 static gboolean
701 profiler_deactivate (AnjutaPlugin *plugin)
704 AnjutaUI *ui;
705 Profiler *profiler;
707 DEBUG_PRINT ("Profiler: Dectivating Profiler plugin ...");
709 ui = anjuta_shell_get_ui (plugin->shell, NULL);
710 profiler = PROFILER (plugin);
712 anjuta_plugin_remove_watch (plugin, profiler->project_watch_id, TRUE);
714 anjuta_ui_unmerge (ui, PROFILER (plugin)->uiid);
715 anjuta_ui_remove_action_group (ui, PROFILER (plugin)->action_group);
717 anjuta_shell_remove_widget (plugin->shell,
718 gprof_view_manager_get_notebook (profiler->view_manager),
719 NULL);
721 profiler_set_target (profiler, NULL);
722 gprof_view_manager_free (profiler->view_manager);
723 gprof_profile_data_free (profiler->profile_data);
725 g_object_unref (profiler->prefs_gxml);
727 g_free (profiler->project_root_uri);
729 if (profiler->profile_data_monitor)
730 gnome_vfs_monitor_cancel (profiler->profile_data_monitor);
732 return TRUE;
735 static void
736 profiler_finalize (GObject *obj)
738 /* Finalization codes here */
739 GNOME_CALL_PARENT (G_OBJECT_CLASS, finalize, (obj));
742 static void
743 profiler_dispose (GObject *obj)
745 /* Disposition codes */
746 GNOME_CALL_PARENT (G_OBJECT_CLASS, dispose, (obj));
749 static void
750 profiler_instance_init (GObject *obj)
752 Profiler *profiler = PROFILER (obj);
754 profiler->uiid = 0;
755 profiler->project_root_uri = NULL;
756 profiler->profile_target_path = NULL;
761 static void
762 profiler_class_init (GObjectClass *klass)
764 AnjutaPluginClass *plugin_class = ANJUTA_PLUGIN_CLASS (klass);
766 parent_class = g_type_class_peek_parent (klass);
768 plugin_class->activate = profiler_activate;
769 plugin_class->deactivate = profiler_deactivate;
770 klass->finalize = profiler_finalize;
771 klass->dispose = profiler_dispose;
774 /* File open interface */
775 static void
776 ifile_open (IAnjutaFile *manager, const gchar *uri,
777 GError **err)
779 Profiler *profiler;
781 profiler = PROFILER (manager);
783 profiler_set_target (profiler, uri);
785 if (profiler_get_data (profiler))
786 gprof_view_manager_refresh_views (profiler->view_manager);
790 static gchar*
791 ifile_get_uri (IAnjutaFile *manager, GError **err)
793 DEBUG_PRINT ("Unsupported operation");
794 return NULL;
797 static void
798 ifile_iface_init (IAnjutaFileIface *iface)
800 iface->open = ifile_open;
801 iface->get_uri = ifile_get_uri;
804 ANJUTA_PLUGIN_BEGIN (Profiler, profiler);
805 ANJUTA_PLUGIN_ADD_INTERFACE (ifile, IANJUTA_TYPE_FILE);
806 ANJUTA_PLUGIN_END;
808 ANJUTA_SIMPLE_PLUGIN (Profiler, profiler);