Updated Spanish translation
[anjuta-git-plugin.git] / plugins / profiler / gprof-flat-profile-view.c
blob1890b36698761e869388a64847de459f63619224
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * gprof-flat-profile-view.c
4 * Copyright (C) James Liggett 2006 <jrliggett@cox.net>
5 *
6 * gprof-flat-profile-view.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 * 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
29 GladeXML *gxml;
30 GtkListStore *list_store;
33 enum
35 COL_NAME = 0,
36 COL_TIME_PERC,
37 COL_CUM_SEC,
38 COL_SELF_SEC,
39 COL_CALLS,
40 COL_AVG_MS,
41 COL_TOTAL_MS,
42 NUM_COLS
45 static void
46 gprof_flat_profile_view_create_columns (GProfFlatProfileView *self)
48 GtkTreeViewColumn *col;
49 GtkCellRenderer *renderer;
50 GtkWidget *list_view;
52 list_view = glade_xml_get_widget (self->priv->gxml, "flat_profile_view");
54 /* Function name */
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),
76 NULL);
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),
90 NULL);
91 gtk_tree_view_column_set_resizable (col, TRUE);
92 gtk_tree_view_column_set_reorderable (col, TRUE);
94 /* Self seconds */
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),
107 NULL);
108 gtk_tree_view_column_set_resizable (col, TRUE);
109 gtk_tree_view_column_set_reorderable (col, TRUE);
111 /* Calls */
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);
122 /* Self ms/call */
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),
135 NULL);
136 gtk_tree_view_column_set_resizable (col, TRUE);
137 gtk_tree_view_column_set_reorderable (col, TRUE);
139 /* Total ms/call */
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),
151 NULL);
152 gtk_tree_view_column_set_resizable (col, TRUE);
153 gtk_tree_view_column_set_reorderable (col, TRUE);
155 /* Model setup */
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);
162 static void
163 on_list_view_row_activated (GtkTreeView *list_view,
164 GtkTreePath *path,
165 GtkTreeViewColumn *col,
166 gpointer user_data)
168 GProfView *self;
169 GtkTreeIter list_iter;
170 GtkTreeModel *model;
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);
188 static void
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",
197 NULL, NULL);
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),
209 (gpointer) self);
213 static void
214 gprof_flat_profile_view_finalize (GObject *obj)
216 GProfFlatProfileView *self;
218 self = (GProfFlatProfileView *) obj;
220 g_object_unref (self->priv->gxml);
221 g_free (self->priv);
224 static void
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;
238 GType
239 gprof_flat_profile_view_get_type (void)
241 static GType obj_type = 0;
243 if (!obj_type)
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),
254 0, /* n_preallocs */
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);
261 return obj_type;
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);
276 return view;
279 void
280 gprof_flat_profile_view_refresh (GProfView *view)
282 GProfFlatProfileView *self;
283 GProfProfileData *data;
284 GProfFlatProfile *flat_profile;
285 GProfFlatProfileEntry *current_entry;
286 GList *entry_iter;
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,
300 &entry_iter);
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,
306 COL_NAME,
307 gprof_flat_profile_entry_get_name (current_entry),
308 COL_TIME_PERC,
309 gprof_flat_profile_entry_get_time_perc (current_entry),
310 COL_CUM_SEC,
311 gprof_flat_profile_entry_get_cum_sec (current_entry),
312 COL_SELF_SEC,
313 gprof_flat_profile_entry_get_self_sec (current_entry),
314 COL_CALLS,
315 gprof_flat_profile_entry_get_calls (current_entry),
316 COL_AVG_MS,
317 gprof_flat_profile_entry_get_avg_ms (current_entry),
318 COL_TOTAL_MS,
319 gprof_flat_profile_entry_get_total_ms (current_entry),
320 -1);
322 current_entry = gprof_flat_profile_entry_get_next (entry_iter,
323 &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);
332 GtkWidget *
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");