1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
3 * gprof-flat-profile-view.c
4 * Copyright (C) James Liggett 2006 <jrliggett@cox.net>
6 * gprof-flat-profile-view.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.
24 #include "gprof-flat-profile-view.h"
25 #include <glib/gi18n-lib.h>
27 struct _GProfFlatProfileViewPriv
30 GtkListStore
*list_store
;
46 gprof_flat_profile_view_create_columns (GProfFlatProfileView
*self
)
48 GtkTreeViewColumn
*col
;
49 GtkCellRenderer
*renderer
;
52 list_view
= glade_xml_get_widget (self
->priv
->gxml
, "flat_profile_view");
55 col
= gtk_tree_view_column_new ();
56 gtk_tree_view_column_set_title (col
, _("Function Name"));
57 gtk_tree_view_append_column (GTK_TREE_VIEW (list_view
), col
);
60 renderer
= gtk_cell_renderer_text_new ();
61 gtk_tree_view_column_pack_start (col
, renderer
, TRUE
);
62 gtk_tree_view_column_add_attribute (col
, renderer
, "text", COL_NAME
);
63 gtk_tree_view_column_set_resizable (col
, TRUE
);
64 gtk_tree_view_column_set_reorderable (col
, TRUE
);
66 /* Function time percentage */
67 col
= gtk_tree_view_column_new ();
68 gtk_tree_view_column_set_title (col
, _("% Time"));
69 gtk_tree_view_append_column (GTK_TREE_VIEW (list_view
), col
);
71 renderer
= gtk_cell_renderer_text_new ();
72 gtk_tree_view_column_pack_start (col
, renderer
, TRUE
);
73 gtk_tree_view_column_add_attribute (col
, renderer
, "text", COL_TIME_PERC
);
74 gtk_tree_view_column_set_resizable (col
, TRUE
);
75 gtk_tree_view_column_set_reorderable (col
, TRUE
);
77 /* Cumulative seconds */
78 col
= gtk_tree_view_column_new ();
79 gtk_tree_view_column_set_title (col
, _("Cumulative Seconds"));
80 gtk_tree_view_append_column (GTK_TREE_VIEW (list_view
), col
);
82 renderer
= gtk_cell_renderer_text_new ();
83 gtk_tree_view_column_pack_start (col
, renderer
, TRUE
);
84 gtk_tree_view_column_add_attribute (col
, renderer
, "text", COL_CUM_SEC
);
85 gtk_tree_view_column_set_resizable (col
, TRUE
);
86 gtk_tree_view_column_set_reorderable (col
, TRUE
);
89 col
= gtk_tree_view_column_new ();
91 /* The number of seconds that this function, excluding other functions it
92 * calls, takes to execute. */
93 gtk_tree_view_column_set_title (col
, _("Self Seconds"));
94 gtk_tree_view_append_column (GTK_TREE_VIEW (list_view
), col
);
96 renderer
= gtk_cell_renderer_text_new ();
97 gtk_tree_view_column_pack_start (col
, renderer
, TRUE
);
98 gtk_tree_view_column_add_attribute (col
, renderer
, "text", COL_SELF_SEC
);
99 gtk_tree_view_column_set_resizable (col
, TRUE
);
100 gtk_tree_view_column_set_reorderable (col
, TRUE
);
103 col
= gtk_tree_view_column_new ();
104 gtk_tree_view_column_set_title (col
, _("Calls"));
105 gtk_tree_view_append_column (GTK_TREE_VIEW (list_view
), col
);
107 renderer
= gtk_cell_renderer_text_new ();
108 gtk_tree_view_column_pack_start (col
, renderer
, TRUE
);
109 gtk_tree_view_column_add_attribute (col
, renderer
, "text", COL_CALLS
);
110 gtk_tree_view_column_set_resizable (col
, TRUE
);
111 gtk_tree_view_column_set_reorderable (col
, TRUE
);
114 col
= gtk_tree_view_column_new ();
116 /* The average number of milliseconds spent in a function, excluding
117 * the functions that it calls. */
118 gtk_tree_view_column_set_title (col
, _("Self ms/call"));
119 gtk_tree_view_append_column (GTK_TREE_VIEW (list_view
), col
);
121 renderer
= gtk_cell_renderer_text_new ();
122 gtk_tree_view_column_pack_start (col
, renderer
, TRUE
);
123 gtk_tree_view_column_add_attribute (col
, renderer
, "text", COL_AVG_MS
);
124 gtk_tree_view_column_set_resizable (col
, TRUE
);
125 gtk_tree_view_column_set_reorderable (col
, TRUE
);
128 col
= gtk_tree_view_column_new ();
130 /* Same as self ms/call, but includes called functions. */
131 gtk_tree_view_column_set_title (col
, _("Total ms/call"));
132 gtk_tree_view_append_column (GTK_TREE_VIEW (list_view
), col
);
134 renderer
= gtk_cell_renderer_text_new ();
135 gtk_tree_view_column_pack_start (col
, renderer
, TRUE
);
136 gtk_tree_view_column_add_attribute (col
, renderer
, "text", COL_TOTAL_MS
);
137 gtk_tree_view_column_set_resizable (col
, TRUE
);
138 gtk_tree_view_column_set_reorderable (col
, TRUE
);
141 gtk_tree_view_set_model (GTK_TREE_VIEW (list_view
),
142 GTK_TREE_MODEL (self
->priv
->list_store
));
143 g_object_unref (self
->priv
->list_store
);
148 on_list_view_row_activated (GtkTreeView
*list_view
,
150 GtkTreeViewColumn
*col
,
154 GtkTreeIter list_iter
;
156 gchar
*selected_function_name
;
158 self
= GPROF_VIEW (user_data
);
159 model
= gtk_tree_view_get_model (list_view
);
161 if (gtk_tree_model_get_iter (model
, &list_iter
, path
))
163 gtk_tree_model_get (model
,
164 &list_iter
, COL_NAME
,
165 &selected_function_name
, -1);
167 gprof_view_show_symbol_in_editor (self
, selected_function_name
);
169 g_free (selected_function_name
);
174 gprof_flat_profile_view_init (GProfFlatProfileView
*self
)
176 GtkWidget
*list_view
;
178 self
->priv
= g_new0 (GProfFlatProfileViewPriv
, 1);
180 self
->priv
->gxml
= glade_xml_new (PACKAGE_DATA_DIR
181 "/glade/profiler-flat-profile.glade",
183 self
->priv
->list_store
= gtk_list_store_new (NUM_COLS
, G_TYPE_STRING
,
184 G_TYPE_FLOAT
, G_TYPE_FLOAT
,
185 G_TYPE_FLOAT
, G_TYPE_UINT
,
186 G_TYPE_FLOAT
, G_TYPE_FLOAT
);
188 gprof_flat_profile_view_create_columns (self
);
190 list_view
= glade_xml_get_widget (self
->priv
->gxml
, "flat_profile_view");
192 g_signal_connect (list_view
, "row-activated",
193 G_CALLBACK (on_list_view_row_activated
),
199 gprof_flat_profile_view_finalize (GObject
*obj
)
201 GProfFlatProfileView
*self
;
203 self
= (GProfFlatProfileView
*) obj
;
205 g_object_unref (self
->priv
->gxml
);
210 gprof_flat_profile_view_class_init (GProfFlatProfileViewClass
*klass
)
212 GObjectClass
*object_class
;
213 GProfViewClass
*view_class
;
215 object_class
= (GObjectClass
*) klass
;
216 view_class
= GPROF_VIEW_CLASS (klass
);
218 object_class
->finalize
= gprof_flat_profile_view_finalize
;
219 view_class
->refresh
= gprof_flat_profile_view_refresh
;
220 view_class
->get_widget
= gprof_flat_profile_view_get_widget
;
224 gprof_flat_profile_view_get_type (void)
226 static GType obj_type
= 0;
230 static const GTypeInfo obj_info
=
232 sizeof (GProfFlatProfileViewClass
),
233 (GBaseInitFunc
) NULL
,
234 (GBaseFinalizeFunc
) NULL
,
235 (GClassInitFunc
) gprof_flat_profile_view_class_init
,
236 (GClassFinalizeFunc
) NULL
,
237 NULL
, /* class_data */
238 sizeof (GProfFlatProfileView
),
240 (GInstanceInitFunc
) gprof_flat_profile_view_init
,
241 NULL
/* value_table */
243 obj_type
= g_type_register_static (GPROF_VIEW_TYPE
,
244 "GProfFlatProfileView", &obj_info
, 0);
249 GProfFlatProfileView
*
250 gprof_flat_profile_view_new (GProfProfileData
*profile_data
,
251 IAnjutaSymbolManager
*symbol_manager
,
252 IAnjutaDocumentManager
*document_manager
)
254 GProfFlatProfileView
*view
;
256 view
= g_object_new (GPROF_FLAT_PROFILE_VIEW_TYPE
, NULL
);
257 gprof_view_set_data (GPROF_VIEW (view
), profile_data
);
258 gprof_view_set_symbol_manager (GPROF_VIEW (view
), symbol_manager
);
259 gprof_view_set_document_manager (GPROF_VIEW (view
), document_manager
);
265 gprof_flat_profile_view_refresh (GProfView
*view
)
267 GProfFlatProfileView
*self
;
268 GProfProfileData
*data
;
269 GProfFlatProfile
*flat_profile
;
270 GProfFlatProfileEntry
*current_entry
;
272 GtkWidget
*list_view
;
273 GtkTreeIter view_iter
;
275 self
= GPROF_FLAT_PROFILE_VIEW (view
);
276 list_view
= glade_xml_get_widget (self
->priv
->gxml
, "flat_profile_view");
278 g_object_ref (self
->priv
->list_store
);
279 gtk_tree_view_set_model (GTK_TREE_VIEW (list_view
), NULL
);
280 gtk_list_store_clear (self
->priv
->list_store
);
282 data
= gprof_view_get_data (view
);
283 flat_profile
= gprof_profile_data_get_flat_profile (data
);
284 current_entry
= gprof_flat_profile_get_first_entry (flat_profile
,
287 while (current_entry
)
289 gtk_list_store_append (self
->priv
->list_store
, &view_iter
);
290 gtk_list_store_set (self
->priv
->list_store
, &view_iter
,
292 gprof_flat_profile_entry_get_name (current_entry
),
294 gprof_flat_profile_entry_get_time_perc (current_entry
),
296 gprof_flat_profile_entry_get_cum_sec (current_entry
),
298 gprof_flat_profile_entry_get_self_sec (current_entry
),
300 gprof_flat_profile_entry_get_calls (current_entry
),
302 gprof_flat_profile_entry_get_avg_ms (current_entry
),
304 gprof_flat_profile_entry_get_total_ms (current_entry
),
307 current_entry
= gprof_flat_profile_entry_get_next (entry_iter
,
311 gtk_tree_view_set_model (GTK_TREE_VIEW (list_view
),
312 GTK_TREE_MODEL (self
->priv
->list_store
));
313 g_object_unref (self
->priv
->list_store
);
318 gprof_flat_profile_view_get_widget (GProfView
*view
)
320 GProfFlatProfileView
*self
;
322 self
= GPROF_FLAT_PROFILE_VIEW (view
);
324 return glade_xml_get_widget (self
->priv
->gxml
, "flat_profile_scrolled");