2 * rpc_stat 2002 Ronnie Sahlberg
4 * $Id: rpc_stat.c,v 1.15 2003/09/02 08:27:41 sahlberg Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 /* This module provides rpc call/reply SRT (Server Response Time) statistics
28 * It serves as an example on how to use the tap api.
37 #include "epan/packet_info.h"
38 #include "epan/filesystem.h"
39 #include "simple_dialog.h"
41 #include "../register.h"
42 #include "packet-rpc.h"
43 #include "../globals.h"
44 #include "compat_macros.h"
45 #include "service_response_time_table.h"
47 extern GtkWidget *main_display_filter_widget;
49 /* used to keep track of the statistics for an entire program interface */
50 typedef struct _rpcstat_t {
52 srt_stat_table srt_table;
56 guint32 num_procedures;
63 rpcstat_reset(rpcstat_t *rs)
65 char title_string[256];
67 reset_srt_table_data(&rs->srt_table);
69 snprintf(title_string, 256, "ONC-RPC Service Response Time statistics for %s version %d : %s", rs->prog, rs->version, get_basename(cfile.filename));
70 gtk_window_set_title(GTK_WINDOW(rs->win), title_string);
75 rpcstat_packet(rpcstat_t *rs, packet_info *pinfo, epan_dissect_t *edt _U_, rpc_call_info_value *ri)
77 if(ri->proc>=rs->num_procedures){
78 /* dont handle this since its outside of known table */
81 /* we are only interested in reply packets */
85 /* we are only interested in certain program/versions */
86 if( (ri->prog!=rs->program) || (ri->vers!=rs->version) ){
90 add_srt_table_data(&rs->srt_table, ri->proc, &ri->req_time, pinfo);
96 rpcstat_draw(rpcstat_t *rs)
98 draw_srt_table_data(&rs->srt_table);
103 static guint32 rpc_program=0;
104 static guint32 rpc_version=0;
105 static gint32 rpc_min_vers=-1;
106 static gint32 rpc_max_vers=-1;
107 static gint32 rpc_min_proc=-1;
108 static gint32 rpc_max_proc=-1;
111 rpcstat_find_procs(gpointer *key, gpointer *value _U_, gpointer *user_data _U_)
113 rpc_proc_info_key *k=(rpc_proc_info_key *)key;
115 if(k->prog!=rpc_program){
118 if(k->vers!=rpc_version){
121 if(rpc_min_proc==-1){
122 rpc_min_proc=k->proc;
123 rpc_max_proc=k->proc;
125 if((gint32)k->proc<rpc_min_proc){
126 rpc_min_proc=k->proc;
128 if((gint32)k->proc>rpc_max_proc){
129 rpc_max_proc=k->proc;
136 rpcstat_find_vers(gpointer *key, gpointer *value _U_, gpointer *user_data _U_)
138 rpc_proc_info_key *k=(rpc_proc_info_key *)key;
140 if(k->prog!=rpc_program){
143 if(rpc_min_vers==-1){
144 rpc_min_vers=k->vers;
145 rpc_max_vers=k->vers;
147 if((gint32)k->vers<rpc_min_vers){
148 rpc_min_vers=k->vers;
150 if((gint32)k->vers>rpc_max_vers){
151 rpc_max_vers=k->vers;
157 /* since the gtk2 implementation of tap is multithreaded we must protect
158 * remove_tap_listener() from modifying the list while draw_tap_listener()
159 * is running. the other protected block is in main.c
161 * there should not be any other critical regions in gtk2
163 void protect_thread_critical_region(void);
164 void unprotect_thread_critical_region(void);
166 win_destroy_cb(GtkWindow *win _U_, gpointer data)
168 rpcstat_t *rs=(rpcstat_t *)data;
170 protect_thread_critical_region();
171 remove_tap_listener(rs);
172 unprotect_thread_critical_region();
174 free_srt_table_data(&rs->srt_table);
178 /* When called, this function will create a new instance of gtk2-rpcstat.
181 gtk_rpcstat_init(char *optarg)
185 char title_string[256];
186 char filter_string[256];
188 GtkWidget *stat_label;
189 GtkWidget *filter_label;
190 int program, version, pos;
192 GString *error_string;
195 if(sscanf(optarg,"rpc,srt,%d,%d,%n",&program,&version,&pos)==2){
202 fprintf(stderr, "ethereal: invalid \"-z rpc,srt,<program>,<version>[,<filter>]\" argument\n");
208 rs=g_malloc(sizeof(rpcstat_t));
209 rs->prog=rpc_prog_name(rpc_program);
210 rs->program=rpc_program;
211 rs->version=rpc_version;
213 rs->win=gtk_window_new(GTK_WINDOW_TOPLEVEL);
214 gtk_window_set_default_size(GTK_WINDOW(rs->win), 550, 400);
215 snprintf(title_string, 256, "ONC-RPC Service Response Time statistics for %s version %d : %s", rs->prog, rs->version, get_basename(cfile.filename));
216 gtk_window_set_title(GTK_WINDOW(rs->win), title_string);
217 SIGNAL_CONNECT(rs->win, "destroy", win_destroy_cb, rs);
219 vbox=gtk_vbox_new(FALSE, 0);
220 gtk_container_add(GTK_CONTAINER(rs->win), vbox);
221 gtk_container_set_border_width(GTK_CONTAINER(vbox), 10);
222 gtk_widget_show(vbox);
224 stat_label=gtk_label_new(title_string);
225 gtk_box_pack_start(GTK_BOX(vbox), stat_label, FALSE, FALSE, 0);
226 gtk_widget_show(stat_label);
228 snprintf(filter_string,255,"Filter:%s",filter?filter:"");
229 filter_label=gtk_label_new(filter_string);
230 gtk_box_pack_start(GTK_BOX(vbox), filter_label, FALSE, FALSE, 0);
231 gtk_widget_show(filter_label);
235 g_hash_table_foreach(rpc_procs, (GHFunc)rpcstat_find_procs, NULL);
236 rs->num_procedures=rpc_max_proc+1;
238 /* We must display TOP LEVEL Widget before calling init_srt_table() */
239 gtk_widget_show(rs->win);
241 init_srt_table(&rs->srt_table, rpc_max_proc+1, vbox);
243 for(i=0;i<rs->num_procedures;i++){
244 init_srt_table_row(&rs->srt_table, i, rpc_proc_name(rpc_program, rpc_version, i));
248 error_string=register_tap_listener("rpc", rs, filter, (void*)rpcstat_reset, (void*)rpcstat_packet, (void*)rpcstat_draw);
250 simple_dialog(ESD_TYPE_WARN, NULL, error_string->str);
251 g_string_free(error_string, TRUE);
252 free_srt_table_data(&rs->srt_table);
258 gtk_widget_show_all(rs->win);
259 redissect_packets(&cfile);
265 static GtkWidget *dlg=NULL, *dlg_box;
266 static GtkWidget *prog_box;
267 static GtkWidget *prog_label, *prog_opt, *prog_menu;
268 static GtkWidget *vers_label, *vers_opt, *vers_menu;
269 static GtkWidget *filter_box;
270 static GtkWidget *filter_label, *filter_entry;
271 static GtkWidget *start_button;
275 rpcstat_start_button_clicked(GtkWidget *item _U_, gpointer data _U_)
280 filter=(char *)gtk_entry_get_text(GTK_ENTRY(filter_entry));
282 sprintf(str, "rpc,srt,%d,%d", rpc_program, rpc_version);
285 sprintf(str, "rpc,srt,%d,%d,%s", rpc_program, rpc_version, filter);
287 gtk_rpcstat_init(str);
292 rpcstat_version_select(GtkWidget *item _U_, gpointer key)
302 rpcstat_program_select(GtkWidget *item _U_, gpointer key)
304 rpc_prog_info_key *k=(rpc_prog_info_key *)key;
309 /* change version menu */
311 gtk_object_destroy(GTK_OBJECT(vers_menu));
312 vers_menu=gtk_menu_new();
315 g_hash_table_foreach(rpc_procs, (GHFunc)rpcstat_find_vers, NULL);
316 rpc_version=rpc_min_vers;
317 for(i=rpc_min_vers;i<=rpc_max_vers;i++){
318 GtkWidget *menu_item;
321 menu_item=gtk_menu_item_new_with_label(vs);
322 SIGNAL_CONNECT(menu_item, "activate", rpcstat_version_select,
325 gtk_widget_show(menu_item);
326 gtk_menu_append(GTK_MENU(vers_menu), menu_item);
328 gtk_option_menu_set_menu(GTK_OPTION_MENU(vers_opt), vers_menu);
332 rpcstat_list_programs(gpointer *key, gpointer *value, gpointer *user_data _U_)
334 rpc_prog_info_key *k=(rpc_prog_info_key *)key;
335 rpc_prog_info_value *v=(rpc_prog_info_value *)value;
336 GtkWidget *menu_item;
338 menu_item=gtk_menu_item_new_with_label(v->progname);
339 SIGNAL_CONNECT(menu_item, "activate", rpcstat_program_select, k);
341 gtk_widget_show(menu_item);
342 gtk_menu_append(GTK_MENU(prog_menu), menu_item);
358 gtk_rpcstat_cb(GtkWidget *w _U_, gpointer d _U_)
363 /* if the window is already open, bring it to front */
365 gdk_window_raise(dlg->window);
369 dlg=gtk_window_new(GTK_WINDOW_TOPLEVEL);
370 gtk_window_set_title(GTK_WINDOW(dlg), "ONC-RPC Service Response Time statistics");
371 SIGNAL_CONNECT(dlg, "destroy", dlg_destroy_cb, NULL);
372 dlg_box=gtk_vbox_new(FALSE, 0);
373 gtk_container_add(GTK_CONTAINER(dlg), dlg_box);
374 gtk_widget_show(dlg_box);
377 prog_box=gtk_hbox_new(FALSE, 10);
379 gtk_container_set_border_width(GTK_CONTAINER(prog_box), 10);
380 prog_label=gtk_label_new("Program:");
381 gtk_box_pack_start(GTK_BOX(prog_box), prog_label, FALSE, FALSE, 0);
382 gtk_widget_show(prog_label);
385 prog_opt=gtk_option_menu_new();
386 prog_menu=gtk_menu_new();
387 g_hash_table_foreach(rpc_progs, (GHFunc)rpcstat_list_programs, NULL);
388 gtk_option_menu_set_menu(GTK_OPTION_MENU(prog_opt), prog_menu);
389 gtk_box_pack_start(GTK_BOX(prog_box), prog_opt, TRUE, TRUE, 0);
390 gtk_widget_show(prog_opt);
393 gtk_container_set_border_width(GTK_CONTAINER(prog_box), 10);
394 vers_label=gtk_label_new("Version:");
395 gtk_box_pack_start(GTK_BOX(prog_box), vers_label, FALSE, FALSE, 0);
396 gtk_widget_show(vers_label);
399 vers_opt=gtk_option_menu_new();
400 vers_menu=gtk_menu_new();
403 g_hash_table_foreach(rpc_procs, (GHFunc)rpcstat_find_vers, NULL);
404 rpc_version=rpc_min_vers;
405 for(i=rpc_min_vers;i<=rpc_max_vers;i++){
406 GtkWidget *menu_item;
409 menu_item=gtk_menu_item_new_with_label(vs);
410 SIGNAL_CONNECT(menu_item, "activate", rpcstat_version_select,
413 gtk_widget_show(menu_item);
414 gtk_menu_append(GTK_MENU(vers_menu), menu_item);
417 gtk_option_menu_set_menu(GTK_OPTION_MENU(vers_opt), vers_menu);
418 gtk_box_pack_start(GTK_BOX(prog_box), vers_opt, TRUE, TRUE, 0);
419 gtk_widget_show(vers_opt);
421 gtk_box_pack_start(GTK_BOX(dlg_box), prog_box, TRUE, TRUE, 0);
422 gtk_widget_show(prog_box);
426 filter_box=gtk_hbox_new(FALSE, 10);
428 gtk_container_set_border_width(GTK_CONTAINER(filter_box), 10);
429 filter_label=gtk_label_new("Filter:");
430 gtk_box_pack_start(GTK_BOX(filter_box), filter_label, FALSE, FALSE, 0);
431 gtk_widget_show(filter_label);
433 filter_entry=gtk_entry_new_with_max_length(250);
434 gtk_box_pack_start(GTK_BOX(filter_box), filter_entry, FALSE, FALSE, 0);
435 filter=gtk_entry_get_text(GTK_ENTRY(main_display_filter_widget));
437 gtk_entry_set_text(GTK_ENTRY(filter_entry), filter);
439 gtk_widget_show(filter_entry);
441 gtk_box_pack_start(GTK_BOX(dlg_box), filter_box, TRUE, TRUE, 0);
442 gtk_widget_show(filter_box);
445 /* the start button */
446 start_button=gtk_button_new_with_label("Create Stat");
447 SIGNAL_CONNECT_OBJECT(start_button, "clicked",
448 rpcstat_start_button_clicked, NULL);
449 gtk_box_pack_start(GTK_BOX(dlg_box), start_button, TRUE, TRUE, 0);
450 gtk_widget_show(start_button);
452 gtk_widget_show_all(dlg);
457 register_tap_listener_gtkrpcstat(void)
459 register_ethereal_tap("rpc,srt,", gtk_rpcstat_init);
463 register_tap_menu_gtkrpcstat(void)
465 register_tap_menu_item("Service Response Time/ONC-RPC", gtk_rpcstat_cb);