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"
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 GtkCListRow *row1 = (GtkCListRow *) ptr1;
110 GtkCListRow *row2 = (GtkCListRow *) 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, 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 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].num=0;
412 rst->procedures[i].min.secs=0;
413 rst->procedures[i].min.nsecs=0;
414 rst->procedures[i].max.secs=0;
415 rst->procedures[i].max.nsecs=0;
416 rst->procedures[i].tot.secs=0;
417 rst->procedures[i].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, char *procedure)
434 /* we have discovered a new procedure. Extend the table accordingly */
435 if(index>=rst->num_procs){
436 int old_num_procs=rst->num_procs;
438 rst->num_procs=index+1;
439 rst->procedures=g_realloc(rst->procedures, sizeof(srt_procedure_t)*(rst->num_procs));
440 for(i=old_num_procs;i<rst->num_procs;i++){
441 rst->procedures[i].num=0;
442 rst->procedures[i].min.secs=0;
443 rst->procedures[i].min.nsecs=0;
444 rst->procedures[i].max.secs=0;
445 rst->procedures[i].max.nsecs=0;
446 rst->procedures[i].tot.secs=0;
447 rst->procedures[i].tot.nsecs=0;
449 rst->procedures[i].entries[j]=NULL;
453 g_snprintf(str, 10, "%d",index);
454 rst->procedures[index].entries[0]=g_strdup(str);
456 rst->procedures[index].entries[1]=g_strdup(procedure);
458 rst->procedures[index].entries[2]=g_strdup("0");
459 rst->procedures[index].entries[3]=g_strdup("0");
460 rst->procedures[index].entries[4]=g_strdup("0");
461 rst->procedures[index].entries[5]=g_strdup("0");
463 gtk_clist_insert(rst->table, index, rst->procedures[index].entries);
464 gtk_clist_set_row_data(rst->table, index, (gpointer) index);
468 add_srt_table_data(srt_stat_table *rst, int index, nstime_t *req_time, packet_info *pinfo)
473 rp=&rst->procedures[index];
475 /* calculate time delta between request and reply */
476 delta.secs=pinfo->fd->abs_secs-req_time->secs;
477 delta.nsecs=pinfo->fd->abs_usecs*1000-req_time->nsecs;
479 delta.nsecs+=1000000000;
484 rp->max.secs=delta.secs;
485 rp->max.nsecs=delta.nsecs;
489 rp->min.secs=delta.secs;
490 rp->min.nsecs=delta.nsecs;
493 if( (delta.secs<rp->min.secs)
494 ||( (delta.secs==rp->min.secs)
495 &&(delta.nsecs<rp->min.nsecs) ) ){
496 rp->min.secs=delta.secs;
497 rp->min.nsecs=delta.nsecs;
500 if( (delta.secs>rp->max.secs)
501 ||( (delta.secs==rp->max.secs)
502 &&(delta.nsecs>rp->max.nsecs) ) ){
503 rp->max.secs=delta.secs;
504 rp->max.nsecs=delta.nsecs;
507 rp->tot.secs += delta.secs;
508 rp->tot.nsecs += delta.nsecs;
509 if(rp->tot.nsecs>1000000000){
510 rp->tot.nsecs-=1000000000;
518 draw_srt_table_data(srt_stat_table *rst)
526 char str[256], *strp;
528 for(i=0;i<rst->num_procs;i++){
529 /* scale it to units of 10us.*/
530 /* for long captures with a large tot time, this can overflow on 32bit */
531 td=(int)rst->procedures[i].tot.secs;
532 td=td*100000+(int)rst->procedures[i].tot.nsecs/10000;
533 if(rst->procedures[i].num){
534 td/=rst->procedures[i].num;
539 j=gtk_clist_find_row_from_data(rst->table, (gpointer)i);
540 g_snprintf(str, 256, "%d", rst->procedures[i].num);
542 gtk_clist_set_text(rst->table, j, 2, strp);
543 g_free(rst->procedures[i].entries[2]);
544 rst->procedures[i].entries[2]=strp;
547 g_snprintf(str, 256, "%3d.%05d", (int)rst->procedures[i].min.secs,rst->procedures[i].min.nsecs/10000);
549 gtk_clist_set_text(rst->table, j, 3, strp);
550 g_free(rst->procedures[i].entries[3]);
551 rst->procedures[i].entries[3]=strp;
554 g_snprintf(str, 256, "%3d.%05d", (int)rst->procedures[i].max.secs,rst->procedures[i].max.nsecs/10000);
556 gtk_clist_set_text(rst->table, j, 4, strp);
557 g_free(rst->procedures[i].entries[4]);
558 rst->procedures[i].entries[4]=strp;
560 g_snprintf(str, 256, "%3d.%05d", td/100000, td%100000);
562 gtk_clist_set_text(rst->table, j, 5, strp);
563 g_free(rst->procedures[i].entries[5]);
564 rst->procedures[i].entries[5]=strp;
567 gtk_clist_sort(rst->table);
572 reset_srt_table_data(srt_stat_table *rst)
576 for(i=0;i<rst->num_procs;i++){
577 rst->procedures[i].num=0;
578 rst->procedures[i].min.secs=0;
579 rst->procedures[i].min.nsecs=0;
580 rst->procedures[i].max.secs=0;
581 rst->procedures[i].max.nsecs=0;
582 rst->procedures[i].tot.secs=0;
583 rst->procedures[i].tot.nsecs=0;
588 free_srt_table_data(srt_stat_table *rst)
592 for(i=0;i<rst->num_procs;i++){
594 if(rst->procedures[i].entries[j]){
595 g_free(rst->procedures[i].entries[j]);
596 rst->procedures[i].entries[j]=NULL;
600 g_free(rst->filter_string);
601 rst->filter_string=NULL;
602 g_free(rst->procedures);
603 rst->procedures=NULL;