1 /* service_response_time_table.c
2 * service_response_time_table 2003 Ronnie Sahlberg
3 * Helper routines common to all service response time statistics
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33 #include "epan/packet_info.h"
35 #include "../simple_dialog.h"
36 #include "../globals.h"
38 #include "gtk/service_response_time_table.h"
39 #include "gtk/filter_utils.h"
40 #include "gtk/gui_utils.h"
55 srt_select_filter_cb(GtkWidget *widget _U_, gpointer callback_data, guint callback_action)
57 srt_stat_table *rst = (srt_stat_table *)callback_data;
61 GtkTreeSelection *sel;
64 if(rst->filter_string==NULL){
68 sel = gtk_tree_view_get_selection (GTK_TREE_VIEW(rst->table));
70 if (!gtk_tree_selection_get_selected(sel, &model, &iter))
73 gtk_tree_model_get (model, &iter, INDEX_COLUMN, &selection, -1);
74 if(selection>=(int)rst->num_procs){
75 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "No procedure selected");
79 str = g_strdup_printf("%s==%d", rst->filter_string, selection);
81 apply_selected_filter (callback_action, str);
87 srt_show_popup_menu_cb(void *widg _U_, GdkEvent *event, srt_stat_table *rst)
89 GdkEventButton *bevent = (GdkEventButton *)event;
91 if(event->type==GDK_BUTTON_PRESS && bevent->button==3){
92 gtk_menu_popup(GTK_MENU(rst->menu), NULL, NULL, NULL, NULL,
93 bevent->button, bevent->time);
99 static GtkItemFactoryEntry srt_list_menu_items[] =
102 {"/Apply as Filter", NULL, NULL, 0, "<Branch>", NULL,},
103 {"/Apply as Filter/Selected", NULL,
104 GTK_MENU_FUNC(srt_select_filter_cb), CALLBACK_MATCH(ACTYPE_SELECTED, 0), NULL, NULL,},
105 {"/Apply as Filter/... not Selected", NULL,
106 GTK_MENU_FUNC(srt_select_filter_cb), CALLBACK_MATCH(ACTYPE_NOT_SELECTED, 0), NULL, NULL,},
107 {"/Apply as Filter/.. and Selected", NULL,
108 GTK_MENU_FUNC(srt_select_filter_cb), CALLBACK_MATCH(ACTYPE_AND_SELECTED, 0), NULL, NULL,},
109 {"/Apply as Filter/... or Selected", NULL,
110 GTK_MENU_FUNC(srt_select_filter_cb), CALLBACK_MATCH(ACTYPE_OR_SELECTED, 0), NULL, NULL,},
111 {"/Apply as Filter/... and not Selected", NULL,
112 GTK_MENU_FUNC(srt_select_filter_cb), CALLBACK_MATCH(ACTYPE_AND_NOT_SELECTED, 0), NULL, NULL,},
113 {"/Apply as Filter/... or not Selected", NULL,
114 GTK_MENU_FUNC(srt_select_filter_cb), CALLBACK_MATCH(ACTYPE_OR_NOT_SELECTED, 0), NULL, NULL,},
117 {"/Prepare a Filter", NULL, NULL, 0, "<Branch>", NULL,},
118 {"/Prepare a Filter/Selected", NULL,
119 GTK_MENU_FUNC(srt_select_filter_cb), CALLBACK_PREPARE(ACTYPE_SELECTED, 0), NULL, NULL,},
120 {"/Prepare a Filter/Not Selected", NULL,
121 GTK_MENU_FUNC(srt_select_filter_cb), CALLBACK_PREPARE(ACTYPE_NOT_SELECTED, 0), NULL, NULL,},
122 {"/Prepare a Filter/... and Selected", NULL,
123 GTK_MENU_FUNC(srt_select_filter_cb), CALLBACK_PREPARE(ACTYPE_AND_SELECTED, 0), NULL, NULL,},
124 {"/Prepare a Filter/... or Selected", NULL,
125 GTK_MENU_FUNC(srt_select_filter_cb), CALLBACK_PREPARE(ACTYPE_OR_SELECTED, 0), NULL, NULL,},
126 {"/Prepare a Filter/... and not Selected", NULL,
127 GTK_MENU_FUNC(srt_select_filter_cb), CALLBACK_PREPARE(ACTYPE_AND_NOT_SELECTED, 0), NULL, NULL,},
128 {"/Prepare a Filter/... or not Selected", NULL,
129 GTK_MENU_FUNC(srt_select_filter_cb), CALLBACK_PREPARE(ACTYPE_OR_NOT_SELECTED, 0), NULL, NULL,},
132 {"/Find Frame", NULL, NULL, 0, "<Branch>", NULL,},
133 {"/Find Frame/Find Frame", NULL, NULL, 0, "<Branch>", NULL,},
134 {"/Find Frame/Find Frame/Selected", NULL,
135 GTK_MENU_FUNC(srt_select_filter_cb), CALLBACK_FIND_FRAME(ACTYPE_SELECTED, 0), NULL, NULL,},
136 {"/Find Frame/Find Frame/Not Selected", NULL,
137 GTK_MENU_FUNC(srt_select_filter_cb), CALLBACK_FIND_FRAME(ACTYPE_NOT_SELECTED, 0), NULL, NULL,},
139 {"/Find Frame/Find Next", NULL, NULL, 0, "<Branch>", NULL,},
140 {"/Find Frame/Find Next/Selected", NULL,
141 GTK_MENU_FUNC(srt_select_filter_cb), CALLBACK_FIND_NEXT(ACTYPE_SELECTED, 0), NULL, NULL,},
142 {"/Find Frame/Find Next/Not Selected", NULL,
143 GTK_MENU_FUNC(srt_select_filter_cb), CALLBACK_FIND_NEXT(ACTYPE_NOT_SELECTED, 0), NULL, NULL,},
146 {"/Find Frame/Find Previous", NULL, NULL, 0, "<Branch>", NULL,},
147 {"/Find Frame/Find Previous/Selected", NULL,
148 GTK_MENU_FUNC(srt_select_filter_cb), CALLBACK_FIND_PREVIOUS(ACTYPE_SELECTED, 0), NULL, NULL,},
149 {"/Find Frame/Find Previous/Not Selected", NULL,
150 GTK_MENU_FUNC(srt_select_filter_cb), CALLBACK_FIND_PREVIOUS(ACTYPE_NOT_SELECTED, 0), NULL, NULL,},
152 /* Colorize Procedure */
153 {"/Colorize Procedure", NULL, NULL, 0, "<Branch>", NULL,},
154 {"/Colorize Procedure/Selected", NULL,
155 GTK_MENU_FUNC(srt_select_filter_cb), CALLBACK_COLORIZE(ACTYPE_SELECTED, 0), NULL, NULL,},
156 {"/Colorize Procedure/Not Selected", NULL,
157 GTK_MENU_FUNC(srt_select_filter_cb), CALLBACK_COLORIZE(ACTYPE_NOT_SELECTED, 0), NULL, NULL,}
162 srt_create_popup_menu(srt_stat_table *rst)
164 GtkItemFactory *item_factory;
166 item_factory = gtk_item_factory_new(GTK_TYPE_MENU, "<main>", NULL);
168 gtk_item_factory_create_items_ac(item_factory, sizeof(srt_list_menu_items)/sizeof(srt_list_menu_items[0]), srt_list_menu_items, rst, 2);
170 rst->menu = gtk_item_factory_get_widget(item_factory, "<main>");
171 g_signal_connect(rst->table, "button_press_event", G_CALLBACK(srt_show_popup_menu_cb), rst);
175 XXX Resizable columns are ugly when there's more than on table cf. SMB
178 init_srt_table(srt_stat_table *rst, int num_procs, GtkWidget *vbox, const char *filter_string)
183 GtkTreeViewColumn *column;
184 GtkCellRenderer *renderer;
185 GtkTreeSortable *sortable;
186 GtkTreeSelection *sel;
188 const char *default_titles[] = { "Index", "Procedure", "Calls", "Min SRT", "Max SRT", "Avg SRT" };
190 /* Create the store */
191 store = gtk_list_store_new (N_COLUMNS, /* Total number of columns */
192 G_TYPE_INT, /* Index */
193 G_TYPE_STRING, /* Procedure */
194 G_TYPE_INT, /* Calls */
195 G_TYPE_STRING, /* Min SRT */
196 G_TYPE_STRING, /* Max SRT */
197 G_TYPE_STRING); /* Avg SRT */
200 tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
201 rst->table = GTK_TREE_VIEW(tree);
202 sortable = GTK_TREE_SORTABLE(store);
204 /* The view now holds a reference. We can get rid of our own reference */
205 g_object_unref (G_OBJECT (store));
208 rst->filter_string=g_strdup(filter_string);
210 rst->filter_string=NULL;
212 for (i = 0; i < N_COLUMNS; i++) {
213 renderer = gtk_cell_renderer_text_new ();
214 if (i != PROCEDURE_COLUMN) {
215 /* right align numbers */
216 g_object_set(G_OBJECT(renderer), "xalign", 1.0, NULL);
218 g_object_set(renderer, "ypad", 0, NULL);
219 column = gtk_tree_view_column_new_with_attributes (default_titles[i], renderer, "text",
222 gtk_tree_view_column_set_sort_column_id(column, i);
223 gtk_tree_view_column_set_resizable(column, TRUE);
224 gtk_tree_view_append_column (rst->table, column);
225 if (i == CALLS_COLUMN) {
226 /* XXX revert order sort */
227 gtk_tree_view_column_clicked(column);
228 gtk_tree_view_column_clicked(column);
232 rst->scrolled_window=scrolled_window_new(NULL, NULL);
233 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(rst->scrolled_window),
235 gtk_container_add(GTK_CONTAINER(rst->scrolled_window), GTK_WIDGET (rst->table));
236 gtk_box_pack_start(GTK_BOX(vbox), rst->scrolled_window, TRUE, TRUE, 0);
238 gtk_tree_view_set_reorderable (rst->table, FALSE);
239 /* Now enable the sorting of each column */
240 gtk_tree_view_set_rules_hint(rst->table, TRUE);
241 gtk_tree_view_set_headers_clickable(rst->table, TRUE);
243 gtk_widget_show(rst->scrolled_window);
245 rst->num_procs=num_procs;
246 rst->procedures=g_malloc(sizeof(srt_procedure_t)*num_procs);
247 for(i=0;i<num_procs;i++){
248 time_stat_init(&rst->procedures[i].stats);
249 rst->procedures[i].index = 0;
250 rst->procedures[i].procedure = NULL;
253 sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(rst->table));
254 gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE);
255 /* create popup menu for this table */
256 if(rst->filter_string){
257 srt_create_popup_menu(rst);
262 init_srt_table_row(srt_stat_table *rst, int index, const char *procedure)
264 /* we have discovered a new procedure. Extend the table accordingly */
265 if(index>=rst->num_procs){
266 int old_num_procs=rst->num_procs;
269 rst->num_procs=index+1;
270 rst->procedures=g_realloc(rst->procedures, sizeof(srt_procedure_t)*(rst->num_procs));
271 for(i=old_num_procs;i<rst->num_procs;i++){
272 time_stat_init(&rst->procedures[i].stats);
273 rst->procedures[i].index = i;
274 rst->procedures[i].procedure=NULL;
277 rst->procedures[index].index = index;
278 rst->procedures[index].procedure=g_strdup(procedure);
282 add_srt_table_data(srt_stat_table *rst, int index, const nstime_t *req_time, packet_info *pinfo)
287 g_assert(index >= 0 && index < rst->num_procs);
288 rp=&rst->procedures[index];
291 * If the count of calls for this procedure is currently zero, it's
292 * going to become non-zero, so add a row for it (we don't want
293 * rows for procedures that have no calls - especially if the
294 * procedure has no calls because the index doesn't correspond
295 * to a procedure, but is an unused/reserved value).
297 * (Yes, this means that the rows aren't in order by anything
298 * interesting. That's why we have the table sorted by a column.)
301 if (rp->stats.num==0){
302 GtkListStore *store = GTK_LIST_STORE(gtk_tree_view_get_model(rst->table));
303 gtk_list_store_append(store, &rp->iter);
304 gtk_list_store_set(store, &rp->iter,
305 INDEX_COLUMN, rp->index,
306 PROCEDURE_COLUMN, rp->procedure,
307 CALLS_COLUMN, rp->stats.num,
314 /* calculate time delta between request and reply */
316 nstime_delta(&delta, &t, req_time);
318 time_stat_update(&rp->stats, &delta, pinfo);
322 draw_srt_table_data(srt_stat_table *rst)
326 char *min, *max, *avg;
327 GtkListStore *store = GTK_LIST_STORE(gtk_tree_view_get_model(rst->table));
329 for(i=0;i<rst->num_procs;i++){
330 /* ignore procedures with no calls (they don't have rows) */
331 if(rst->procedures[i].stats.num==0){
335 /* scale it to units of 10us.*/
336 /* for long captures with a large tot time, this can overflow on 32bit */
337 td=(int)rst->procedures[i].stats.tot.secs;
338 td=td*100000+(int)rst->procedures[i].stats.tot.nsecs/10000;
339 td/=rst->procedures[i].stats.num;
341 min=g_strdup_printf("%3d.%05d",
342 (int)rst->procedures[i].stats.min.secs,
343 rst->procedures[i].stats.min.nsecs/10000);
345 max=g_strdup_printf("%3d.%05d",
346 (int)rst->procedures[i].stats.max.secs,
347 rst->procedures[i].stats.max.nsecs/10000);
348 avg=g_strdup_printf("%3" G_GINT64_MODIFIER "d.%05" G_GINT64_MODIFIER "d",
349 td/100000, td%100000);
351 gtk_list_store_set(store, &rst->procedures[i].iter,
352 CALLS_COLUMN, rst->procedures[i].stats.num,
365 reset_srt_table_data(srt_stat_table *rst)
370 for(i=0;i<rst->num_procs;i++){
371 time_stat_init(&rst->procedures[i].stats);
373 store = GTK_LIST_STORE(gtk_tree_view_get_model(rst->table));
374 gtk_list_store_clear(store);
378 free_srt_table_data(srt_stat_table *rst)
382 for(i=0;i<rst->num_procs;i++){
383 g_free(rst->procedures[i].procedure);
384 rst->procedures[i].procedure=NULL;
386 g_free(rst->filter_string);
387 rst->filter_string=NULL;
388 g_free(rst->procedures);
389 rst->procedures=NULL;