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 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@ethereal.com>
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.
36 #include "compat_macros.h"
37 #include "epan/packet_info.h"
38 #include "service_response_time_table.h"
39 #include "image/clist_ascend.xpm"
40 #include "image/clist_descend.xpm"
41 #include "simple_dialog.h"
43 #include "gtk/find_dlg.h"
45 #include "gtk/color_dlg.h"
47 #include "gui_utils.h"
48 #include "gtkglobals.h"
51 #define GTK_MENU_FUNC(a) ((GtkItemFactoryCallback)(a))
54 typedef struct column_arrows {
57 GtkWidget *descend_pm;
62 srt_click_column_cb(GtkCList *clist, gint column, gpointer data)
64 column_arrows *col_arrows = (column_arrows *) data;
67 gtk_clist_freeze(clist);
69 for (i = 0; i < 6; i++) {
70 gtk_widget_hide(col_arrows[i].ascend_pm);
71 gtk_widget_hide(col_arrows[i].descend_pm);
74 if (column == clist->sort_column) {
75 if (clist->sort_type == GTK_SORT_ASCENDING) {
76 clist->sort_type = GTK_SORT_DESCENDING;
77 gtk_widget_show(col_arrows[column].descend_pm);
79 clist->sort_type = GTK_SORT_ASCENDING;
80 gtk_widget_show(col_arrows[column].ascend_pm);
83 /* Columns 2-5 Count, Min, Max, Avg are sorted in descending
85 Columns 0 and 1 sort by ascending order by default
88 clist->sort_type = GTK_SORT_DESCENDING;
89 gtk_widget_show(col_arrows[column].descend_pm);
91 clist->sort_type = GTK_SORT_ASCENDING;
92 gtk_widget_show(col_arrows[column].ascend_pm);
94 gtk_clist_set_sort_column(clist, column);
96 gtk_clist_thaw(clist);
98 gtk_clist_sort(clist);
102 srt_sort_column(GtkCList *clist, gconstpointer ptr1, gconstpointer ptr2)
109 const GtkCListRow *row1 = ptr1;
110 const GtkCListRow *row2 = ptr2;
112 text1 = GTK_CELL_TEXT (row1->cell[clist->sort_column])->text;
113 text2 = GTK_CELL_TEXT (row2->cell[clist->sort_column])->text;
115 switch(clist->sort_column){
117 return strcmp (text1, text2);
126 sscanf(text1,"%f",&f1);
127 sscanf(text2,"%f",&f2);
128 if(fabs(f1-f2)<0.000005)
134 g_assert_not_reached();
140 /* action is encoded as
141 filter_action*256+filter_type
149 5: Colorize Procedure
159 srt_select_filter_cb(GtkWidget *widget _U_, gpointer callback_data, guint callback_action)
161 int action, type, selection;
162 srt_stat_table *rst = (srt_stat_table *)callback_data;
164 const char *current_filter;
167 if(rst->filter_string==NULL){
171 action=(callback_action>>8)&0xff;
172 type=callback_action&0xff;
174 selection=GPOINTER_TO_INT(g_list_nth_data(GTK_CLIST(rst->table)->selection, 0));
175 if(selection>=(int)rst->num_procs){
176 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "No procedure selected");
179 /* translate it back from row index to index in procedures array */
180 selection=GPOINTER_TO_INT(gtk_clist_get_row_data(rst->table, selection));
182 current_filter=gtk_entry_get_text(GTK_ENTRY(main_display_filter_widget));
187 g_snprintf(str, 255, "%s==%d", rst->filter_string, selection);
191 g_snprintf(str, 255, "!(%s==%d)", rst->filter_string, selection);
195 g_snprintf(str, 255, "(%s) && (%s==%d)", current_filter, rst->filter_string, selection);
199 g_snprintf(str, 255, "(%s) || (%s==%d)", current_filter, rst->filter_string, selection);
202 /* and not selected */
203 g_snprintf(str, 255, "(%s) && !(%s==%d)", current_filter, rst->filter_string, selection);
206 /* or not selected */
207 g_snprintf(str, 255, "(%s) || !(%s==%d)", current_filter, rst->filter_string, selection);
211 gtk_entry_set_text(GTK_ENTRY(main_display_filter_widget), str);
216 main_filter_packets(&cfile, str, FALSE);
223 find_frame_with_filter(str);
227 find_previous_next_frame_with_filter(str, FALSE);
231 find_previous_next_frame_with_filter(str, TRUE);
234 /* colorize procedure */
235 color_display_with_filter(str);
242 srt_show_popup_menu_cb(void *widg _U_, GdkEvent *event, srt_stat_table *rst)
244 GdkEventButton *bevent = (GdkEventButton *)event;
246 if(event->type==GDK_BUTTON_PRESS && bevent->button==3){
247 gtk_menu_popup(GTK_MENU(rst->menu), NULL, NULL, NULL, NULL,
248 bevent->button, bevent->time);
254 static GtkItemFactoryEntry srt_list_menu_items[] =
257 ITEM_FACTORY_ENTRY("/Apply as Filter", NULL, NULL, 0, "<Branch>", NULL),
258 ITEM_FACTORY_ENTRY("/Apply as Filter/Selected", NULL,
259 srt_select_filter_cb, 0*256+0, NULL, NULL),
260 ITEM_FACTORY_ENTRY("/Apply as Filter/... not Selected", NULL,
261 srt_select_filter_cb, 0*256+1, NULL, NULL),
262 ITEM_FACTORY_ENTRY("/Apply as Filter/.. and Selected", NULL,
263 srt_select_filter_cb, 0*256+2, NULL, NULL),
264 ITEM_FACTORY_ENTRY("/Apply as Filter/... or Selected", NULL,
265 srt_select_filter_cb, 0*256+3, NULL, NULL),
266 ITEM_FACTORY_ENTRY("/Apply as Filter/... and not Selected", NULL,
267 srt_select_filter_cb, 0*256+4, NULL, NULL),
268 ITEM_FACTORY_ENTRY("/Apply as Filter/... or not Selected", NULL,
269 srt_select_filter_cb, 0*256+5, NULL, NULL),
272 ITEM_FACTORY_ENTRY("/Prepare a Filter", NULL, NULL, 0, "<Branch>", NULL),
273 ITEM_FACTORY_ENTRY("/Prepare a Filter/Selected", NULL,
274 srt_select_filter_cb, 1*256+0, NULL, NULL),
275 ITEM_FACTORY_ENTRY("/Prepare a Filter/Not Selected", NULL,
276 srt_select_filter_cb, 1*256+1, NULL, NULL),
277 ITEM_FACTORY_ENTRY("/Prepare a Filter/... and Selected", NULL,
278 srt_select_filter_cb, 1*256+2, NULL, NULL),
279 ITEM_FACTORY_ENTRY("/Prepare a Filter/... or Selected", NULL,
280 srt_select_filter_cb, 1*256+3, NULL, NULL),
281 ITEM_FACTORY_ENTRY("/Prepare a Filter/... and not Selected", NULL,
282 srt_select_filter_cb, 1*256+4, NULL, NULL),
283 ITEM_FACTORY_ENTRY("/Prepare a Filter/... or not Selected", NULL,
284 srt_select_filter_cb, 1*256+5, NULL, NULL),
287 ITEM_FACTORY_ENTRY("/Find Frame", NULL, NULL, 0, "<Branch>", NULL),
288 ITEM_FACTORY_ENTRY("/Find Frame/Find Frame", NULL, NULL, 0, "<Branch>", NULL),
289 ITEM_FACTORY_ENTRY("/Find Frame/Find Frame/Selected", NULL,
290 srt_select_filter_cb, 2*256+0, NULL, NULL),
291 ITEM_FACTORY_ENTRY("/Find Frame/Find Frame/Not Selected", NULL,
292 srt_select_filter_cb, 2*256+1, NULL, NULL),
294 ITEM_FACTORY_ENTRY("/Find Frame/Find Next", NULL, NULL, 0, "<Branch>", NULL),
295 ITEM_FACTORY_ENTRY("/Find Frame/Find Next/Selected", NULL,
296 srt_select_filter_cb, 3*256+0, NULL, NULL),
297 ITEM_FACTORY_ENTRY("/Find Frame/Find Next/Not Selected", NULL,
298 srt_select_filter_cb, 3*256+1, NULL, NULL),
301 ITEM_FACTORY_ENTRY("/Find Frame/Find Previous", NULL, NULL, 0, "<Branch>", NULL),
302 ITEM_FACTORY_ENTRY("/Find Frame/Find Previous/Selected", NULL,
303 srt_select_filter_cb, 4*256+0, NULL, NULL),
304 ITEM_FACTORY_ENTRY("/Find Frame/Find Previous/Not Selected", NULL,
305 srt_select_filter_cb, 4*256+1, NULL, NULL),
307 /* Colorize Procedure */
308 ITEM_FACTORY_ENTRY("/Colorize Procedure", NULL, NULL, 0, "<Branch>", NULL),
309 ITEM_FACTORY_ENTRY("/Colorize Procedure/Selected", NULL,
310 srt_select_filter_cb, 5*256+0, NULL, NULL),
311 ITEM_FACTORY_ENTRY("/Colorize Procedure/Not Selected", NULL,
312 srt_select_filter_cb, 5*256+1, NULL, NULL),
317 srt_create_popup_menu(srt_stat_table *rst)
319 GtkItemFactory *item_factory;
321 item_factory = gtk_item_factory_new(GTK_TYPE_MENU, "<main>", NULL);
323 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);
325 rst->menu = gtk_item_factory_get_widget(item_factory, "<main>");
326 SIGNAL_CONNECT(rst->table, "button_press_event", srt_show_popup_menu_cb, rst);
331 init_srt_table(srt_stat_table *rst, int num_procs, GtkWidget *vbox, const char *filter_string)
334 column_arrows *col_arrows;
335 GdkBitmap *ascend_bm, *descend_bm;
336 GdkPixmap *ascend_pm, *descend_pm;
338 GtkWidget *column_lb;
339 const char *default_titles[] = { "Index", "Procedure", "Calls", "Min SRT", "Max SRT", "Avg SRT" };
343 rst->filter_string=g_strdup(filter_string);
345 rst->filter_string=NULL;
347 rst->scrolled_window=scrolled_window_new(NULL, NULL);
348 gtk_box_pack_start(GTK_BOX(vbox), rst->scrolled_window, TRUE, TRUE, 0);
350 rst->table=(GtkCList *)gtk_clist_new(6);
352 gtk_widget_show(GTK_WIDGET(rst->table));
353 gtk_widget_show(rst->scrolled_window);
355 col_arrows = (column_arrows *) g_malloc(sizeof(column_arrows) * 6);
356 win_style = gtk_widget_get_style(rst->scrolled_window);
357 ascend_pm = gdk_pixmap_create_from_xpm_d(rst->scrolled_window->window,
359 &win_style->bg[GTK_STATE_NORMAL],
360 (gchar **)clist_ascend_xpm);
361 descend_pm = gdk_pixmap_create_from_xpm_d(rst->scrolled_window->window,
363 &win_style->bg[GTK_STATE_NORMAL],
364 (gchar **)clist_descend_xpm);
365 for (i = 0; i < 6; i++) {
366 col_arrows[i].table = gtk_table_new(2, 2, FALSE);
367 gtk_table_set_col_spacings(GTK_TABLE(col_arrows[i].table), 5);
368 column_lb = gtk_label_new(default_titles[i]);
369 gtk_table_attach(GTK_TABLE(col_arrows[i].table), column_lb, 0, 1, 0, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
370 gtk_widget_show(column_lb);
372 col_arrows[i].ascend_pm = gtk_pixmap_new(ascend_pm, ascend_bm);
373 gtk_table_attach(GTK_TABLE(col_arrows[i].table), col_arrows[i].ascend_pm, 1, 2, 1, 2, GTK_SHRINK, GTK_SHRINK, 0, 0);
374 col_arrows[i].descend_pm = gtk_pixmap_new(descend_pm, descend_bm);
375 gtk_table_attach(GTK_TABLE(col_arrows[i].table), col_arrows[i].descend_pm, 1, 2, 0, 1, GTK_SHRINK, GTK_SHRINK, 0, 0);
377 gtk_widget_show(col_arrows[i].descend_pm);
379 gtk_clist_set_column_widget(GTK_CLIST(rst->table), i, col_arrows[i].table);
380 gtk_widget_show(col_arrows[i].table);
382 gtk_clist_column_titles_show(GTK_CLIST(rst->table));
384 gtk_clist_set_compare_func(rst->table, srt_sort_column);
385 gtk_clist_set_sort_column(rst->table, 2);
386 gtk_clist_set_sort_type(rst->table, GTK_SORT_DESCENDING);
389 /*XXX instead of this we should probably have some code to
390 dynamically adjust the width of the columns */
391 gtk_clist_set_column_width(rst->table, 0, 32);
392 gtk_clist_set_column_width(rst->table, 1, 160);
393 gtk_clist_set_column_width(rst->table, 2, 50);
394 gtk_clist_set_column_width(rst->table, 3, 60);
395 gtk_clist_set_column_width(rst->table, 4, 60);
396 gtk_clist_set_column_width(rst->table, 5, 60);
398 gtk_clist_set_shadow_type(rst->table, GTK_SHADOW_IN);
399 gtk_clist_column_titles_show(rst->table);
400 gtk_container_add(GTK_CONTAINER(rst->scrolled_window), (GtkWidget *)rst->table);
402 SIGNAL_CONNECT(rst->table, "click-column", srt_click_column_cb, col_arrows);
404 gtk_widget_show(GTK_WIDGET(rst->table));
405 gtk_widget_show(rst->scrolled_window);
408 rst->num_procs=num_procs;
409 rst->procedures=g_malloc(sizeof(srt_procedure_t)*num_procs);
410 for(i=0;i<num_procs;i++){
411 rst->procedures[i].stats.num=0;
412 rst->procedures[i].stats.min.secs=0;
413 rst->procedures[i].stats.min.nsecs=0;
414 rst->procedures[i].stats.max.secs=0;
415 rst->procedures[i].stats.max.nsecs=0;
416 rst->procedures[i].stats.tot.secs=0;
417 rst->procedures[i].stats.tot.nsecs=0;
419 rst->procedures[i].entries[j]=NULL;
423 /* create popup menu for this table */
424 if(rst->filter_string){
425 srt_create_popup_menu(rst);
430 init_srt_table_row(srt_stat_table *rst, int index, const char *procedure)
432 /* we have discovered a new procedure. Extend the table accordingly */
433 if(index>=rst->num_procs){
434 int old_num_procs=rst->num_procs;
436 rst->num_procs=index+1;
437 rst->procedures=g_realloc(rst->procedures, sizeof(srt_procedure_t)*(rst->num_procs));
438 for(i=old_num_procs;i<rst->num_procs;i++){
439 rst->procedures[i].stats.num=0;
440 rst->procedures[i].stats.min.secs=0;
441 rst->procedures[i].stats.min.nsecs=0;
442 rst->procedures[i].stats.max.secs=0;
443 rst->procedures[i].stats.max.nsecs=0;
444 rst->procedures[i].stats.tot.secs=0;
445 rst->procedures[i].stats.tot.nsecs=0;
447 rst->procedures[i].entries[j]=NULL;
451 rst->procedures[index].entries[0]=g_strdup_printf("%d", index);
453 rst->procedures[index].entries[1]=g_strdup(procedure);
455 rst->procedures[index].entries[2]=g_strdup("0");
456 rst->procedures[index].entries[3]=g_strdup("0");
457 rst->procedures[index].entries[4]=g_strdup("0");
458 rst->procedures[index].entries[5]=g_strdup("0");
462 add_srt_table_data(srt_stat_table *rst, int index, const nstime_t *req_time, packet_info *pinfo)
468 rp=&rst->procedures[index];
471 * If the count of calls for this procedure is currently zero, it's
472 * going to become non-zero, so add a row for it (we don't want
473 * rows for procedures that have no calls - especially if the
474 * procedure has no calls because the index doesn't correspond
475 * to a procedure, but is an unused/reserved value).
477 * (Yes, this means that the rows aren't in order by anything
478 * interesting. That's why we have the table sorted by a column.)
480 if (rp->stats.num==0){
481 row=gtk_clist_append(rst->table, rst->procedures[index].entries);
482 gtk_clist_set_row_data(rst->table, row, (gpointer) index);
485 /* calculate time delta between request and reply */
487 nstime_delta(&delta, &t, req_time);
489 time_stat_update(&rp->stats, &delta, pinfo);
493 draw_srt_table_data(srt_stat_table *rst)
499 for(i=0;i<rst->num_procs;i++){
500 /* ignore procedures with no calls (they don't have CList rows) */
501 if(rst->procedures[i].stats.num==0){
505 /* scale it to units of 10us.*/
506 /* for long captures with a large tot time, this can overflow on 32bit */
507 td=(int)rst->procedures[i].stats.tot.secs;
508 td=td*100000+(int)rst->procedures[i].stats.tot.nsecs/10000;
509 td/=rst->procedures[i].stats.num;
511 j=gtk_clist_find_row_from_data(rst->table, (gpointer)i);
512 strp=g_strdup_printf("%d", rst->procedures[i].stats.num);
513 gtk_clist_set_text(rst->table, j, 2, strp);
514 g_free(rst->procedures[i].entries[2]);
515 rst->procedures[i].entries[2]=strp;
518 strp=g_strdup_printf("%3d.%05d",
519 (int)rst->procedures[i].stats.min.secs,
520 rst->procedures[i].stats.min.nsecs/10000);
521 gtk_clist_set_text(rst->table, j, 3, strp);
522 g_free(rst->procedures[i].entries[3]);
523 rst->procedures[i].entries[3]=strp;
526 strp=g_strdup_printf("%3d.%05d",
527 (int)rst->procedures[i].stats.max.secs,
528 rst->procedures[i].stats.max.nsecs/10000);
529 gtk_clist_set_text(rst->table, j, 4, strp);
530 g_free(rst->procedures[i].entries[4]);
531 rst->procedures[i].entries[4]=strp;
533 strp=g_strdup_printf("%3" PRId64 ".%05" PRId64,
534 td/100000, td%100000);
535 gtk_clist_set_text(rst->table, j, 5, strp);
536 g_free(rst->procedures[i].entries[5]);
537 rst->procedures[i].entries[5]=strp;
540 gtk_clist_sort(rst->table);
545 reset_srt_table_data(srt_stat_table *rst)
549 for(i=0;i<rst->num_procs;i++){
550 time_stat_init(&rst->procedures[i].stats);
552 gtk_clist_clear(rst->table);
556 free_srt_table_data(srt_stat_table *rst)
560 for(i=0;i<rst->num_procs;i++){
562 if(rst->procedures[i].entries[j]){
563 g_free(rst->procedures[i].entries[j]);
564 rst->procedures[i].entries[j]=NULL;
568 g_free(rst->filter_string);
569 rst->filter_string=NULL;
570 g_free(rst->procedures);
571 rst->procedures=NULL;