1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 * Copyright (C) James Liggett 2006 <jrliggett@cox.net>
6 * plugin.c is free software.
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 * 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
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"/anjuta-profiler-plugin-48.png"
32 static gpointer parent_class
;
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
;
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
);
62 setup_options (Profiler
*profiler
)
67 options
= g_ptr_array_new ();
69 /* First handle the easy ones: -a, -c, and -z */
70 if (gprof_options_get_int (profiler
->options
, "no_show_static"))
72 g_ptr_array_add (options
, g_strdup ("-a"));
75 if (gprof_options_get_int (profiler
->options
, "show_possible_called"))
77 g_ptr_array_add (options
, g_strdup ("-c"));
80 if (gprof_options_get_int (profiler
->options
, "show_uncalled"))
82 g_ptr_array_add (options
, g_strdup ("-z"));
85 /* If the user wants to modify the call graph, put in -p so we have a flat
87 if (!gprof_options_get_int (profiler
->options
, "show_all_symbols"))
89 g_ptr_array_add (options
, g_strdup ("-p"));
91 symbols
= gprof_options_get_string (profiler
->options
, "symbols");
93 if (gprof_options_get_int (profiler
->options
, "include_symbols"))
95 add_options_strings (options
, "-q", symbols
);
98 if (gprof_options_get_int (profiler
->options
, "exclude_symbols"))
100 add_options_strings (options
, "-Q", symbols
);
106 /* Time propagation options */
107 if (!gprof_options_get_int (profiler
->options
, "propagate_all_symbols"))
110 symbols
= gprof_options_get_string (profiler
->options
,
111 "propagation_symbols");
113 if (gprof_options_get_int (profiler
->options
,
114 "propagate_include_symbols"))
116 add_options_strings (options
, "-n", symbols
);
119 if (gprof_options_get_int (profiler
->options
,
120 "propagate_exclude_symbols"))
122 add_options_strings (options
, "-N", symbols
);
128 /* NULL terminate the array for compatibility with g_strfreev */
130 g_ptr_array_add (options
, NULL
);
132 /* Other options not directly passed to gprof */
134 /* If there is an existing profile data monitor and automatic refresh
135 * is disabled, cancel the monitor */
137 if (profiler
->profile_data_monitor
)
139 if (!gprof_options_get_int (profiler
->options
, "automatic_refresh"))
141 gnome_vfs_monitor_cancel (profiler
->profile_data_monitor
);
142 profiler
->profile_data_monitor
= NULL
;
150 profiler_get_data (Profiler
*profiler
)
153 gchar
**option_strings
;
154 gchar
*profiling_data_path
;
155 gchar
*profiling_data_path_from_options
;
156 gboolean ret
= FALSE
;
158 if (profiler
->profile_target_path
)
161 options
= setup_options (profiler
);
163 profiling_data_path_from_options
= gprof_options_get_string (profiler
->options
,
164 "profile_data_file");
166 if (strlen (profiling_data_path_from_options
) > 0)
167 profiling_data_path
= profiling_data_path_from_options
;
169 profiling_data_path
= NULL
;
171 if (!gprof_profile_data_init_profile (profiler
->profile_data
,
172 profiler
->profile_target_path
,
176 anjuta_util_dialog_error (GTK_WINDOW (ANJUTA_PLUGIN (profiler
)->shell
),
177 _("Could not get profiling data."
179 "Please check the path to "
180 "this target's profiling data file."));
183 option_strings
= (gchar
**) g_ptr_array_free (options
, FALSE
);
184 g_free (profiling_data_path_from_options
);
185 g_strfreev (option_strings
);
194 on_profile_data_changed (GnomeVFSMonitorHandle
*handle
,
195 const gchar
*monitor_uri
, const gchar
*info_uri
,
196 GnomeVFSMonitorEventType event
,
201 profiler
= PROFILER (user_data
);
205 case GNOME_VFS_MONITOR_EVENT_CHANGED
:
206 if (profiler_get_data (profiler
))
207 gprof_view_manager_refresh_views (profiler
->view_manager
);
209 case GNOME_VFS_MONITOR_EVENT_DELETED
:
210 gnome_vfs_monitor_cancel (handle
);
211 profiler
->profile_data_monitor
= NULL
;
219 profiler_set_target (Profiler
*profiler
, const gchar
*profile_target_uri
)
221 gchar
*profile_target_path
;
222 gchar
*profile_target_dir
;
223 gchar
*profile_data_path
;
224 gchar
*profile_data_path_from_options
;
225 gchar
*profile_data_uri
;
227 if (profiler
->profile_target_path
)
229 g_free (profiler
->profile_target_path
);
230 profiler
->profile_target_path
= NULL
;
233 if (profile_target_uri
)
235 profile_target_path
= gnome_vfs_get_local_path_from_uri (profile_target_uri
);
237 profile_data_path_from_options
= gprof_options_get_string (profiler
->options
,
238 "profile_data_file");
240 if (strlen (profile_data_path_from_options
) > 0)
242 profile_data_path
= g_strdup (profile_data_path_from_options
);
243 profile_target_dir
= NULL
;
247 profile_target_dir
= g_path_get_dirname (profile_target_path
);
248 profile_data_path
= g_build_filename (profile_target_dir
, "gmon.out",
252 g_free (profile_data_path_from_options
);
254 profile_data_uri
= gnome_vfs_get_uri_from_local_path (profile_data_path
);
256 if (g_file_test (profile_data_path
, G_FILE_TEST_EXISTS
))
258 profiler
->profile_target_path
= profile_target_path
;
261 /* Set up a file change monitor for automatic refresh if enabled */
262 if (gprof_options_get_int (profiler
->options
,
263 "automatic_refresh"))
265 /* Cancel any existing monitor */
266 if (profiler
->profile_data_monitor
)
267 gnome_vfs_monitor_cancel (profiler
->profile_data_monitor
);
269 gnome_vfs_monitor_add (&profiler
->profile_data_monitor
,
270 profile_data_uri
, GNOME_VFS_MONITOR_FILE
,
271 on_profile_data_changed
,
272 (gpointer
) profiler
);
275 /* Show user the profiler views if they aren't visible so they
276 * know what happened */
277 anjuta_shell_present_widget (ANJUTA_PLUGIN (profiler
)->shell
,
278 gprof_view_manager_get_notebook (profiler
->view_manager
),
283 anjuta_util_dialog_error (GTK_WINDOW (ANJUTA_PLUGIN (profiler
)->shell
),
284 _("This target does not have any "
285 "profiling data.\n\n"
286 "Please ensure that the target is "
287 "complied with profiling support "
288 "and that it is run at least "
292 g_free (profile_target_dir
);
293 g_free (profile_data_path
);
294 g_free (profile_data_uri
);
298 static GProfOptions
*
301 GProfOptions
*options
;
303 options
= gprof_options_new ();
305 gprof_options_register_key (options
, "automatic_refresh", "0",
306 "automatic_refresh_check",
309 gprof_options_register_key (options
, "no_show_static", "0",
310 "no_show_static_check",
313 gprof_options_register_key (options
, "show_possible_called", "0",
314 "show_possible_called_check",
317 gprof_options_register_key (options
, "show_uncalled", "0",
318 "show_uncalled_check",
321 gprof_options_register_key (options
, "show_all_symbols", "1",
322 "show_all_symbols_radio",
325 gprof_options_register_key (options
, "include_symbols", "0",
326 "include_symbols_radio",
329 gprof_options_register_key (options
, "exclude_symbols", "0",
330 "exclude_symbols_radio",
333 gprof_options_register_key (options
, "symbols", "", "symbols_text_view",
334 OPTION_TYPE_TEXT_ENTRY
);
336 gprof_options_register_key (options
, "propagate_all_symbols", "1",
337 "propagate_all_symbols_radio",
340 gprof_options_register_key (options
, "propagate_include_symbols", "0",
341 "propagate_include_symbols_radio",
344 gprof_options_register_key (options
, "propagate_exclude_symbols", "0",
345 "propagate_exclude_symbols_radio",
348 gprof_options_register_key (options
, "propagation_symbols", "",
349 "propagation_text_view",
350 OPTION_TYPE_TEXT_ENTRY
);
352 gprof_options_register_key (options
, "profile_data_file", "",
353 "profile_data_file_entry",
360 on_profile_data_browse_button_clicked (GtkButton
*button
, GladeXML
*gxml
)
362 GtkWidget
*select_file_dialog
;
363 GtkWidget
*profile_data_file_entry
;
364 GtkWidget
*profiling_options_dialog
;
365 gchar
*selected_file
;
367 profile_data_file_entry
= glade_xml_get_widget (gxml
, "profile_data_file_entry");
368 profiling_options_dialog
= glade_xml_get_widget (gxml
,
369 "profiling_options_dialog");
370 select_file_dialog
= gtk_file_chooser_dialog_new ("Select Data File",
371 GTK_WINDOW (profiling_options_dialog
),
372 GTK_FILE_CHOOSER_ACTION_OPEN
,
379 if (gtk_dialog_run (GTK_DIALOG (select_file_dialog
)) == GTK_RESPONSE_ACCEPT
)
381 selected_file
= gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (select_file_dialog
));
382 gtk_entry_set_text (GTK_ENTRY (profile_data_file_entry
), selected_file
);
383 g_free (selected_file
);
386 gtk_widget_destroy (select_file_dialog
);
390 on_profiling_options_button_clicked (GtkButton
*button
, gpointer
*user_data
)
394 GtkWidget
*profiling_options_dialog
;
395 GtkWidget
*profile_data_browse_button
;
397 profiler
= PROFILER (user_data
);
398 gxml
= glade_xml_new (GLADE_FILE
, "profiling_options_dialog",
400 profiling_options_dialog
= glade_xml_get_widget (gxml
, "profiling_options_dialog");
401 profile_data_browse_button
= glade_xml_get_widget (gxml
,
402 "profile_data_browse_button");
404 g_signal_connect (profile_data_browse_button
, "clicked",
405 G_CALLBACK (on_profile_data_browse_button_clicked
),
408 g_signal_connect (profiling_options_dialog
, "response", G_CALLBACK (gtk_widget_hide
),
409 profiling_options_dialog
);
411 gprof_options_create_window (profiler
->options
, gxml
);
413 gtk_window_set_transient_for (GTK_WINDOW (profiling_options_dialog
),
414 GTK_WINDOW (ANJUTA_PLUGIN(profiler
)->shell
));
416 gtk_dialog_run (GTK_DIALOG (profiling_options_dialog
));
418 g_object_unref (gxml
);
422 on_select_other_target_button_clicked (GtkButton
*button
,
423 GtkTreeView
*targets_list_view
)
426 GtkWidget
*target_chooser_dialog
;
428 gchar
*selected_target_path
;
429 gchar
*selected_target_uri
;
430 GtkTreeSelection
*selection
;
431 GtkTreePath
*new_target_path
;
433 model
= gtk_tree_view_get_model (targets_list_view
);
434 target_chooser_dialog
= gtk_file_chooser_dialog_new ("Select Target",
436 GTK_FILE_CHOOSER_ACTION_OPEN
,
443 if (gtk_dialog_run (GTK_DIALOG (target_chooser_dialog
)) == GTK_RESPONSE_ACCEPT
)
445 selected_target_path
= gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (target_chooser_dialog
));
446 selected_target_uri
= gnome_vfs_get_uri_from_local_path (selected_target_path
);
447 selection
= gtk_tree_view_get_selection (targets_list_view
);
449 gtk_list_store_append (GTK_LIST_STORE (model
), &iter
);
450 gtk_list_store_set (GTK_LIST_STORE (model
), &iter
, 0,
451 selected_target_path
, 1,
452 selected_target_uri
, -1);
454 gtk_tree_selection_select_iter (selection
, &iter
);
455 new_target_path
= gtk_tree_model_get_path (model
, &iter
);
456 gtk_tree_view_scroll_to_cell (targets_list_view
, new_target_path
, NULL
,
459 g_free (selected_target_path
);
460 g_free (selected_target_uri
);
461 gtk_tree_path_free (new_target_path
);
464 gtk_widget_destroy (target_chooser_dialog
);
468 on_target_selected (GtkTreeSelection
*selection
, GtkTreeModel
*model
,
469 GtkTreePath
*path
, gboolean path_currently_selected
,
472 GtkTreeIter list_iter
;
475 gtk_tree_model_get_iter (model
, &list_iter
, path
);
476 gtk_tree_model_get (model
, &list_iter
, 1, &target_uri
, -1);
480 gprof_options_set_target (profiler
->options
, target_uri
);
488 on_profiler_select_target (GtkAction
*action
, Profiler
*profiler
)
491 GtkWidget
*select_target_dialog
;
492 GtkWidget
*profiling_options_button
;
493 GtkWidget
*select_other_target_button
;
494 GtkWidget
*targets_list_view
;
495 GtkTreeViewColumn
*column
;
496 GtkCellRenderer
*renderer
;
497 GtkListStore
*targets_list_store
;
499 GList
*current_target
;
502 IAnjutaProjectManager
*project_manager
;
503 GtkTreeSelection
*selection
;
505 gchar
*target
= NULL
;
506 gchar
*relative_path
;
507 guint project_root_uri_length
;
509 gxml
= glade_xml_new (GLADE_FILE
, "select_target_dialog", NULL
);
510 select_target_dialog
= glade_xml_get_widget (gxml
,
511 "select_target_dialog");
512 targets_list_view
= glade_xml_get_widget (gxml
,
513 "targets_list_view");
514 profiling_options_button
= glade_xml_get_widget (gxml
,
515 "profiling_options_button");
516 select_other_target_button
= glade_xml_get_widget (gxml
,
517 "select_other_target_button");
519 g_signal_connect (profiling_options_button
, "clicked",
520 G_CALLBACK (on_profiling_options_button_clicked
),
523 g_signal_connect (select_other_target_button
, "clicked",
524 G_CALLBACK (on_select_other_target_button_clicked
),
527 gtk_window_set_transient_for (GTK_WINDOW (select_target_dialog
),
528 GTK_WINDOW (ANJUTA_PLUGIN(profiler
)->shell
));
530 selection
= gtk_tree_view_get_selection (GTK_TREE_VIEW (targets_list_view
));
531 gtk_tree_selection_set_mode (selection
, GTK_SELECTION_BROWSE
);
532 gtk_tree_selection_set_select_function (selection
,
533 (GtkTreeSelectionFunc
) on_target_selected
,
535 targets_list_store
= gtk_list_store_new (2, G_TYPE_STRING
, G_TYPE_STRING
);
537 column
= gtk_tree_view_column_new ();
538 gtk_tree_view_column_set_sizing (column
,
539 GTK_TREE_VIEW_COLUMN_AUTOSIZE
);
541 renderer
= gtk_cell_renderer_text_new ();
542 gtk_tree_view_column_pack_start (column
, renderer
, FALSE
);
543 gtk_tree_view_column_add_attribute (column
, renderer
, "text",
545 gtk_tree_view_append_column (GTK_TREE_VIEW (targets_list_view
), column
);
546 gtk_tree_view_set_expander_column (GTK_TREE_VIEW (targets_list_view
), column
);
548 if (profiler
->project_root_uri
)
550 project_manager
= anjuta_shell_get_interface (ANJUTA_PLUGIN (profiler
)->shell
,
551 IAnjutaProjectManager
, NULL
);
553 exec_targets
= ianjuta_project_manager_get_targets (project_manager
,
554 IANJUTA_PROJECT_MANAGER_TARGET_EXECUTABLE
,
557 project_root_uri_length
= strlen (profiler
->project_root_uri
) + 1;
561 /* Populate listview */
562 current_target
= exec_targets
;
564 while (current_target
)
566 relative_path
= (gchar
*) current_target
->data
+ project_root_uri_length
;
568 gtk_list_store_append (targets_list_store
, &iter
);
569 gtk_list_store_set (targets_list_store
, &iter
, 0, relative_path
, 1,
570 current_target
->data
, -1);
572 g_free (current_target
->data
);
573 current_target
= g_list_next (current_target
);
575 g_list_free (exec_targets
);
577 gtk_tree_view_set_model (GTK_TREE_VIEW (targets_list_view
),
578 GTK_TREE_MODEL (targets_list_store
));
579 g_object_unref (targets_list_store
);
584 gtk_tree_view_set_model (GTK_TREE_VIEW (targets_list_view
),
585 GTK_TREE_MODEL (targets_list_store
));
586 g_object_unref (targets_list_store
);
590 response
= gtk_dialog_run (GTK_DIALOG (select_target_dialog
));
592 if (response
== GTK_RESPONSE_OK
)
594 selection
= gtk_tree_view_get_selection (GTK_TREE_VIEW (targets_list_view
));
595 if (gtk_tree_selection_get_selected (selection
, &model
, &iter
))
597 gtk_tree_model_get (model
, &iter
, 1, &target
, -1);
598 profiler_set_target (profiler
, target
);
600 if (profiler_get_data (profiler
))
601 gprof_view_manager_refresh_views (profiler
->view_manager
);
604 profiler_set_target (profiler
, NULL
);
607 gtk_widget_hide (select_target_dialog
);
608 g_object_unref (gxml
);
612 on_profiler_refresh (GtkAction
*action
, Profiler
*profiler
)
614 if (profiler_get_data (profiler
))
615 gprof_view_manager_refresh_views (profiler
->view_manager
);
619 on_profiler_delete_data (GtkAction
*action
, Profiler
*profiler
)
621 gchar
*profile_target_dir
;
622 gchar
*profile_data_path_from_options
;
623 gchar
*profile_data_path
;
625 if (profiler
->profile_target_path
)
627 profile_data_path_from_options
= gprof_options_get_string (profiler
->options
,
628 "profile_data_file");
629 /* Delete given path if we have one, or just use the default */
630 if (strlen (profile_data_path_from_options
) > 0)
631 g_unlink (profile_data_path_from_options
);
635 profile_target_dir
= g_path_get_dirname (profiler
->profile_target_path
);
636 profile_data_path
= g_build_filename (profile_target_dir
,
639 g_unlink (profile_data_path
);
641 g_free (profile_target_dir
);
642 g_free (profile_data_path
);
645 g_free (profile_data_path_from_options
);
650 project_root_added (AnjutaPlugin
*plugin
, const gchar
*name
,
651 const GValue
*value
, gpointer user_data
)
654 const gchar
*root_uri
;
656 profiler
= PROFILER (plugin
);
657 root_uri
= g_value_get_string (value
);
661 g_free (profiler
->project_root_uri
);
662 profiler
->project_root_uri
= g_strdup (root_uri
);
669 project_root_removed (AnjutaPlugin
*plugin
, const gchar
*name
,
674 profiler
= PROFILER (plugin
);
676 g_free (profiler
->project_root_uri
);
677 profiler
->project_root_uri
= NULL
;
681 on_session_load (AnjutaShell
*shell
, AnjutaSessionPhase phase
,
682 AnjutaSession
*session
,
685 const gchar
*session_dir
;
686 gchar
*settings_file_path
;
688 if (phase
== ANJUTA_SESSION_PHASE_NORMAL
)
690 session_dir
= anjuta_session_get_session_directory (session
);
691 settings_file_path
= g_build_filename (session_dir
,
692 "profiler-settings.xml",
695 gprof_options_load (plugin
->options
, settings_file_path
);
697 g_free (settings_file_path
);
702 on_session_save (AnjutaShell
*shell
, AnjutaSessionPhase phase
,
703 AnjutaSession
*session
,
706 const gchar
*session_dir
;
707 gchar
*settings_file_path
;
709 if (phase
== ANJUTA_SESSION_PHASE_NORMAL
)
711 session_dir
= anjuta_session_get_session_directory (session
);
712 settings_file_path
= g_build_filename (session_dir
,
713 "profiler-settings.xml",
716 gprof_options_save (plugin
->options
, settings_file_path
);
718 g_free (settings_file_path
);
723 static GtkActionEntry actions_file
[] = {
725 "ActionMenuDebug", /* Action name */
726 NULL
, /* Stock icon, if any */
727 N_("Debug"), /* Display label */
728 NULL
, /* short-cut */
730 NULL
/* Action callback */
733 "ActionMenuProfiler", /* Action name */
734 "profiler-icon", /* Stock icon, if any */
735 N_("Profiler"), /* Display label */
736 NULL
, /* short-cut */
738 NULL
/* Action callback */
741 "ActionProfilerSelectTarget", /* Action name */
742 GTK_STOCK_EXECUTE
, /* Stock icon, if any */
743 N_("Select Target..."), /* Display label */
744 NULL
, /* short-cut */
746 G_CALLBACK (on_profiler_select_target
) /* Action callback */
749 "ActionProfilerRefresh", /* Action name */
750 GTK_STOCK_REFRESH
, /* Stock icon, if any */
751 N_("Refresh"), /* Display label */
752 NULL
, /* short-cut */
754 G_CALLBACK (on_profiler_refresh
) /* Action callback */
757 "ActionProfilerDeleteData", /* Action name */
758 GTK_STOCK_DELETE
, /* Stock icon, if any */
759 N_("Delete Data"), /* Display label */
760 NULL
, /* short-cut */
762 G_CALLBACK (on_profiler_delete_data
) /* Action callback */
767 register_stock_icons (AnjutaPlugin
*plugin
)
770 GtkIconFactory
*icon_factory
;
771 GtkIconSet
*icon_set
;
772 static gboolean registered
= FALSE
;
778 /* Register stock icons */
779 ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
780 icon_factory
= anjuta_ui_get_icon_factory (ui
);
781 REGISTER_ICON ("anjuta-profiler-plugin-48.png", "profiler-icon");
785 profiler_activate (AnjutaPlugin
*plugin
)
790 IAnjutaSymbolManager
*symbol_manager
;
791 IAnjutaDocumentManager
*document_manager
;
793 DEBUG_PRINT ("Profiler: Activating Profiler plugin ...");
794 profiler
= PROFILER (plugin
);
796 /* Add all UI actions and merge UI */
797 ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
798 register_stock_icons (plugin
);
800 profiler
->action_group
=
801 anjuta_ui_add_action_group_entries (ui
, "ActionGroupProfiler",
802 _("Application Performance Profiler"),
804 G_N_ELEMENTS (actions_file
),
805 GETTEXT_PACKAGE
, TRUE
,
807 profiler
->uiid
= anjuta_ui_merge (ui
, UI_FILE
);
809 profiler
->view_manager
= gprof_view_manager_new ();
810 profiler
->profile_data
= gprof_profile_data_new ();
812 symbol_manager
= anjuta_shell_get_interface (plugin
->shell
,
813 IAnjutaSymbolManager
,
816 document_manager
= anjuta_shell_get_interface (plugin
->shell
,
817 IAnjutaDocumentManager
,
820 gprof_view_manager_add_view (profiler
->view_manager
,
821 GPROF_VIEW (gprof_flat_profile_view_new (profiler
->profile_data
,
825 gprof_view_manager_add_view (profiler
->view_manager
,
826 GPROF_VIEW (gprof_call_graph_view_new (profiler
->profile_data
,
830 gprof_view_manager_add_view (profiler
->view_manager
,
831 GPROF_VIEW (gprof_function_call_tree_view_new (profiler
->profile_data
,
834 _("Function Call Tree"));
837 gprof_view_manager_add_view (profiler
->view_manager
,
838 GPROF_VIEW (gprof_function_call_chart_view_new (profiler
->profile_data
,
841 _("Function Call Chart"));
844 anjuta_shell_add_widget (plugin
->shell
,
845 gprof_view_manager_get_notebook (profiler
->view_manager
),
849 ANJUTA_SHELL_PLACEMENT_CENTER
,
852 profiler
->project_watch_id
= anjuta_plugin_add_watch (plugin
, IANJUTA_PROJECT_MANAGER_PROJECT_ROOT_URI
,
854 project_root_removed
, NULL
);
856 profiler
->options
= register_options ();
858 /* Set up session save/load */
859 g_signal_connect (G_OBJECT (plugin
->shell
), "save_session",
860 G_CALLBACK (on_session_save
), plugin
);
862 g_signal_connect (G_OBJECT (plugin
->shell
), "load_session",
863 G_CALLBACK (on_session_load
), plugin
);
869 profiler_deactivate (AnjutaPlugin
*plugin
)
875 DEBUG_PRINT ("Profiler: Dectivating Profiler plugin ...");
877 /* Disconnect session save/load */
878 g_signal_handlers_disconnect_by_func (G_OBJECT (plugin
->shell
),
879 G_CALLBACK (on_session_save
), plugin
);
881 g_signal_handlers_disconnect_by_func (G_OBJECT (plugin
->shell
),
882 G_CALLBACK (on_session_load
), plugin
);
884 ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
885 profiler
= PROFILER (plugin
);
887 anjuta_plugin_remove_watch (plugin
, profiler
->project_watch_id
, TRUE
);
889 anjuta_ui_unmerge (ui
, PROFILER (plugin
)->uiid
);
890 anjuta_ui_remove_action_group (ui
, PROFILER (plugin
)->action_group
);
892 anjuta_shell_remove_widget (plugin
->shell
,
893 gprof_view_manager_get_notebook (profiler
->view_manager
),
896 profiler_set_target (profiler
, NULL
);
897 gprof_view_manager_free (profiler
->view_manager
);
898 gprof_profile_data_free (profiler
->profile_data
);
900 gprof_options_destroy (profiler
->options
);
902 g_free (profiler
->project_root_uri
);
904 if (profiler
->profile_data_monitor
)
905 gnome_vfs_monitor_cancel (profiler
->profile_data_monitor
);
911 profiler_finalize (GObject
*obj
)
913 /* Finalization codes here */
914 G_OBJECT_CLASS (parent_class
)->finalize (obj
);
918 profiler_dispose (GObject
*obj
)
920 /* Disposition codes */
921 G_OBJECT_CLASS (parent_class
)->dispose (obj
);
925 profiler_instance_init (GObject
*obj
)
927 Profiler
*profiler
= PROFILER (obj
);
930 profiler
->project_root_uri
= NULL
;
931 profiler
->profile_target_path
= NULL
;
937 profiler_class_init (GObjectClass
*klass
)
939 AnjutaPluginClass
*plugin_class
= ANJUTA_PLUGIN_CLASS (klass
);
941 parent_class
= g_type_class_peek_parent (klass
);
943 plugin_class
->activate
= profiler_activate
;
944 plugin_class
->deactivate
= profiler_deactivate
;
945 klass
->finalize
= profiler_finalize
;
946 klass
->dispose
= profiler_dispose
;
949 /* File open interface */
951 ifile_open (IAnjutaFile
*manager
, GFile
* file
,
956 profiler
= PROFILER (manager
);
958 gchar
* uri
= g_file_get_uri (file
);
960 profiler_set_target (profiler
, uri
);
962 /* Respect user settings for this target if they exist. Otherwise, don't
963 * create an entry for this target to avoid having the settings file
964 * balloon with the settings for a bunch of targets, espcially if this
965 * is a one-time operation. If previous settings don't exist, just use
967 if (gprof_options_has_target (profiler
->options
, uri
))
968 gprof_options_set_target (profiler
->options
, uri
);
970 gprof_options_set_target (profiler
->options
, NULL
);
972 if (profiler_get_data (profiler
))
973 gprof_view_manager_refresh_views (profiler
->view_manager
);
978 ifile_get_file (IAnjutaFile
*manager
, GError
**err
)
980 DEBUG_PRINT ("Unsupported operation");
985 ifile_iface_init (IAnjutaFileIface
*iface
)
987 iface
->open
= ifile_open
;
988 iface
->get_file
= ifile_get_file
;
991 ANJUTA_PLUGIN_BEGIN (Profiler
, profiler
);
992 ANJUTA_PLUGIN_ADD_INTERFACE (ifile
, IANJUTA_TYPE_FILE
);
995 ANJUTA_SIMPLE_PLUGIN (Profiler
, profiler
);