Updated Spanish translation
[anjuta-git-plugin.git] / plugins / profiler / gprof-flat-profile-view.c
blobf4c80e1c3e7f8b6b12df8d9fe6fb6d9dea10bcbe
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_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);
88 /* Self seconds */
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);
102 /* Calls */
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);
113 /* Self ms/call */
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);
127 /* Total ms/call */
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);
140 /* Model setup */
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);
147 static void
148 on_list_view_row_activated (GtkTreeView *list_view,
149 GtkTreePath *path,
150 GtkTreeViewColumn *col,
151 gpointer user_data)
153 GProfView *self;
154 GtkTreeIter list_iter;
155 GtkTreeModel *model;
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);
173 static void
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",
182 NULL, NULL);
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),
194 (gpointer) self);
198 static void
199 gprof_flat_profile_view_finalize (GObject *obj)
201 GProfFlatProfileView *self;
203 self = (GProfFlatProfileView *) obj;
205 g_object_unref (self->priv->gxml);
206 g_free (self->priv);
209 static void
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;
223 GType
224 gprof_flat_profile_view_get_type (void)
226 static GType obj_type = 0;
228 if (!obj_type)
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),
239 0, /* n_preallocs */
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);
246 return obj_type;
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);
261 return view;
264 void
265 gprof_flat_profile_view_refresh (GProfView *view)
267 GProfFlatProfileView *self;
268 GProfProfileData *data;
269 GProfFlatProfile *flat_profile;
270 GProfFlatProfileEntry *current_entry;
271 GList *entry_iter;
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,
285 &entry_iter);
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,
291 COL_NAME,
292 gprof_flat_profile_entry_get_name (current_entry),
293 COL_TIME_PERC,
294 gprof_flat_profile_entry_get_time_perc (current_entry),
295 COL_CUM_SEC,
296 gprof_flat_profile_entry_get_cum_sec (current_entry),
297 COL_SELF_SEC,
298 gprof_flat_profile_entry_get_self_sec (current_entry),
299 COL_CALLS,
300 gprof_flat_profile_entry_get_calls (current_entry),
301 COL_AVG_MS,
302 gprof_flat_profile_entry_get_avg_ms (current_entry),
303 COL_TOTAL_MS,
304 gprof_flat_profile_entry_get_total_ms (current_entry),
305 -1);
307 current_entry = gprof_flat_profile_entry_get_next (entry_iter,
308 &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);
317 GtkWidget *
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");