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_set_cell_data_func (col
, renderer
,
74 gprof_view_format_float
,
75 GINT_TO_POINTER (COL_TIME_PERC
),
77 gtk_tree_view_column_set_resizable (col
, TRUE
);
78 gtk_tree_view_column_set_reorderable (col
, TRUE
);
80 /* Cumulative seconds */
81 col
= gtk_tree_view_column_new ();
82 gtk_tree_view_column_set_title (col
, _("Cumulative Seconds"));
83 gtk_tree_view_append_column (GTK_TREE_VIEW (list_view
), col
);
85 renderer
= gtk_cell_renderer_text_new ();
86 gtk_tree_view_column_pack_start (col
, renderer
, TRUE
);
87 gtk_tree_view_column_set_cell_data_func (col
, renderer
,
88 gprof_view_format_float
,
89 GINT_TO_POINTER (COL_CUM_SEC
),
91 gtk_tree_view_column_set_resizable (col
, TRUE
);
92 gtk_tree_view_column_set_reorderable (col
, TRUE
);
95 col
= gtk_tree_view_column_new ();
97 /* The number of seconds that this function, excluding other functions it
98 * calls, takes to execute. */
99 gtk_tree_view_column_set_title (col
, _("Self Seconds"));
100 gtk_tree_view_append_column (GTK_TREE_VIEW (list_view
), col
);
102 renderer
= gtk_cell_renderer_text_new ();
103 gtk_tree_view_column_pack_start (col
, renderer
, TRUE
);
104 gtk_tree_view_column_set_cell_data_func (col
, renderer
,
105 gprof_view_format_float
,
106 GINT_TO_POINTER (COL_SELF_SEC
),
108 gtk_tree_view_column_set_resizable (col
, TRUE
);
109 gtk_tree_view_column_set_reorderable (col
, TRUE
);
112 col
= gtk_tree_view_column_new ();
113 gtk_tree_view_column_set_title (col
, _("Calls"));
114 gtk_tree_view_append_column (GTK_TREE_VIEW (list_view
), col
);
116 renderer
= gtk_cell_renderer_text_new ();
117 gtk_tree_view_column_pack_start (col
, renderer
, TRUE
);
118 gtk_tree_view_column_add_attribute (col
, renderer
, "text", COL_CALLS
);
119 gtk_tree_view_column_set_resizable (col
, TRUE
);
120 gtk_tree_view_column_set_reorderable (col
, TRUE
);
123 col
= gtk_tree_view_column_new ();
125 /* The average number of milliseconds spent in a function, excluding
126 * the functions that it calls. */
127 gtk_tree_view_column_set_title (col
, _("Self ms/call"));
128 gtk_tree_view_append_column (GTK_TREE_VIEW (list_view
), col
);
130 renderer
= gtk_cell_renderer_text_new ();
131 gtk_tree_view_column_pack_start (col
, renderer
, TRUE
);
132 gtk_tree_view_column_set_cell_data_func (col
, renderer
,
133 gprof_view_format_float
,
134 GINT_TO_POINTER (COL_AVG_MS
),
136 gtk_tree_view_column_set_resizable (col
, TRUE
);
137 gtk_tree_view_column_set_reorderable (col
, TRUE
);
140 col
= gtk_tree_view_column_new ();
142 /* Same as self ms/call, but includes called functions. */
143 gtk_tree_view_column_set_title (col
, _("Total ms/call"));
144 gtk_tree_view_append_column (GTK_TREE_VIEW (list_view
), col
);
146 renderer
= gtk_cell_renderer_text_new ();
147 gtk_tree_view_column_pack_start (col
, renderer
, TRUE
);
148 gtk_tree_view_column_set_cell_data_func (col
, renderer
,
149 gprof_view_format_float
,
150 GINT_TO_POINTER (COL_TOTAL_MS
),
152 gtk_tree_view_column_set_resizable (col
, TRUE
);
153 gtk_tree_view_column_set_reorderable (col
, TRUE
);
156 gtk_tree_view_set_model (GTK_TREE_VIEW (list_view
),
157 GTK_TREE_MODEL (self
->priv
->list_store
));
158 g_object_unref (self
->priv
->list_store
);
163 on_list_view_row_activated (GtkTreeView
*list_view
,
165 GtkTreeViewColumn
*col
,
169 GtkTreeIter list_iter
;
171 gchar
*selected_function_name
;
173 self
= GPROF_VIEW (user_data
);
174 model
= gtk_tree_view_get_model (list_view
);
176 if (gtk_tree_model_get_iter (model
, &list_iter
, path
))
178 gtk_tree_model_get (model
,
179 &list_iter
, COL_NAME
,
180 &selected_function_name
, -1);
182 gprof_view_show_symbol_in_editor (self
, selected_function_name
);
184 g_free (selected_function_name
);
189 gprof_flat_profile_view_init (GProfFlatProfileView
*self
)
191 GtkWidget
*list_view
;
193 self
->priv
= g_new0 (GProfFlatProfileViewPriv
, 1);
195 self
->priv
->gxml
= glade_xml_new (PACKAGE_DATA_DIR
196 "/glade/profiler-flat-profile.glade",
198 self
->priv
->list_store
= gtk_list_store_new (NUM_COLS
, G_TYPE_STRING
,
199 G_TYPE_FLOAT
, G_TYPE_FLOAT
,
200 G_TYPE_FLOAT
, G_TYPE_UINT
,
201 G_TYPE_FLOAT
, G_TYPE_FLOAT
);
203 gprof_flat_profile_view_create_columns (self
);
205 list_view
= glade_xml_get_widget (self
->priv
->gxml
, "flat_profile_view");
207 g_signal_connect (list_view
, "row-activated",
208 G_CALLBACK (on_list_view_row_activated
),
214 gprof_flat_profile_view_finalize (GObject
*obj
)
216 GProfFlatProfileView
*self
;
218 self
= (GProfFlatProfileView
*) obj
;
220 g_object_unref (self
->priv
->gxml
);
225 gprof_flat_profile_view_class_init (GProfFlatProfileViewClass
*klass
)
227 GObjectClass
*object_class
;
228 GProfViewClass
*view_class
;
230 object_class
= (GObjectClass
*) klass
;
231 view_class
= GPROF_VIEW_CLASS (klass
);
233 object_class
->finalize
= gprof_flat_profile_view_finalize
;
234 view_class
->refresh
= gprof_flat_profile_view_refresh
;
235 view_class
->get_widget
= gprof_flat_profile_view_get_widget
;
239 gprof_flat_profile_view_get_type (void)
241 static GType obj_type
= 0;
245 static const GTypeInfo obj_info
=
247 sizeof (GProfFlatProfileViewClass
),
248 (GBaseInitFunc
) NULL
,
249 (GBaseFinalizeFunc
) NULL
,
250 (GClassInitFunc
) gprof_flat_profile_view_class_init
,
251 (GClassFinalizeFunc
) NULL
,
252 NULL
, /* class_data */
253 sizeof (GProfFlatProfileView
),
255 (GInstanceInitFunc
) gprof_flat_profile_view_init
,
256 NULL
/* value_table */
258 obj_type
= g_type_register_static (GPROF_VIEW_TYPE
,
259 "GProfFlatProfileView", &obj_info
, 0);
264 GProfFlatProfileView
*
265 gprof_flat_profile_view_new (GProfProfileData
*profile_data
,
266 IAnjutaSymbolManager
*symbol_manager
,
267 IAnjutaDocumentManager
*document_manager
)
269 GProfFlatProfileView
*view
;
271 view
= g_object_new (GPROF_FLAT_PROFILE_VIEW_TYPE
, NULL
);
272 gprof_view_set_data (GPROF_VIEW (view
), profile_data
);
273 gprof_view_set_symbol_manager (GPROF_VIEW (view
), symbol_manager
);
274 gprof_view_set_document_manager (GPROF_VIEW (view
), document_manager
);
280 gprof_flat_profile_view_refresh (GProfView
*view
)
282 GProfFlatProfileView
*self
;
283 GProfProfileData
*data
;
284 GProfFlatProfile
*flat_profile
;
285 GProfFlatProfileEntry
*current_entry
;
287 GtkWidget
*list_view
;
288 GtkTreeIter view_iter
;
290 self
= GPROF_FLAT_PROFILE_VIEW (view
);
291 list_view
= glade_xml_get_widget (self
->priv
->gxml
, "flat_profile_view");
293 g_object_ref (self
->priv
->list_store
);
294 gtk_tree_view_set_model (GTK_TREE_VIEW (list_view
), NULL
);
295 gtk_list_store_clear (self
->priv
->list_store
);
297 data
= gprof_view_get_data (view
);
298 flat_profile
= gprof_profile_data_get_flat_profile (data
);
299 current_entry
= gprof_flat_profile_get_first_entry (flat_profile
,
302 while (current_entry
)
304 gtk_list_store_append (self
->priv
->list_store
, &view_iter
);
305 gtk_list_store_set (self
->priv
->list_store
, &view_iter
,
307 gprof_flat_profile_entry_get_name (current_entry
),
309 gprof_flat_profile_entry_get_time_perc (current_entry
),
311 gprof_flat_profile_entry_get_cum_sec (current_entry
),
313 gprof_flat_profile_entry_get_self_sec (current_entry
),
315 gprof_flat_profile_entry_get_calls (current_entry
),
317 gprof_flat_profile_entry_get_avg_ms (current_entry
),
319 gprof_flat_profile_entry_get_total_ms (current_entry
),
322 current_entry
= gprof_flat_profile_entry_get_next (entry_iter
,
326 gtk_tree_view_set_model (GTK_TREE_VIEW (list_view
),
327 GTK_TREE_MODEL (self
->priv
->list_store
));
328 g_object_unref (self
->priv
->list_store
);
333 gprof_flat_profile_view_get_widget (GProfView
*view
)
335 GProfFlatProfileView
*self
;
337 self
= GPROF_FLAT_PROFILE_VIEW (view
);
339 return glade_xml_get_widget (self
->priv
->gxml
, "flat_profile_scrolled");