2 * rpcstat 2002 Ronnie Sahlberg
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
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 statistics to tshark.
26 * It is only used by tshark and not wireshark
35 #ifdef HAVE_SYS_TYPES_H
36 # include <sys/types.h>
40 #include "epan/packet_info.h"
42 #include <epan/stat_cmd_args.h>
43 #include <epan/dissectors/packet-rpc.h>
46 /* used to keep track of statistics for a specific program/version */
47 typedef struct _rpc_program_t {
48 struct _rpc_program_t *next;
57 static rpc_program_t *prog_list=NULL;
58 static int already_enabled=0;
61 rpcprogs_packet(void *dummy1 _U_, packet_info *pinfo, epan_dissect_t *edt _U_, const void *pri)
63 const rpc_call_info_value *ri=pri;
65 rpc_program_t *rp=NULL;
68 /* the list was empty */
69 rp=g_malloc(sizeof(rpc_program_t));
81 } else if((ri->prog==prog_list->program)
82 &&(ri->vers==prog_list->version)){
84 } else if( (ri->prog<prog_list->program)
85 ||((ri->prog==prog_list->program)&&(ri->vers<prog_list->version))){
86 /* we should be first entry in list */
87 rp=g_malloc(sizeof(rpc_program_t));
100 /* we go somewhere else in the list */
101 for(rp=prog_list;rp;rp=rp->next){
103 && (rp->next->program==ri->prog)
104 && (rp->next->version==ri->vers)){
109 || (rp->next->program>ri->prog)
110 || ( (rp->next->program==ri->prog)
111 &&(rp->next->version>ri->vers))){
113 trp=g_malloc(sizeof(rpc_program_t));
115 trp->program=ri->prog;
116 trp->version=ri->vers;
132 /* we are only interested in reply packets */
137 /* calculate time delta between request and reply */
138 nstime_delta(&delta, &pinfo->fd->abs_ts, &ri->req_time);
141 && (rp->max.nsecs==0) ){
142 rp->max.secs=delta.secs;
143 rp->max.nsecs=delta.nsecs;
147 && (rp->min.nsecs==0) ){
148 rp->min.secs=delta.secs;
149 rp->min.nsecs=delta.nsecs;
152 if( (delta.secs<rp->min.secs)
153 ||( (delta.secs==rp->min.secs)
154 &&(delta.nsecs<rp->min.nsecs) ) ){
155 rp->min.secs=delta.secs;
156 rp->min.nsecs=delta.nsecs;
159 if( (delta.secs>rp->max.secs)
160 ||( (delta.secs==rp->max.secs)
161 &&(delta.nsecs>rp->max.nsecs) ) ){
162 rp->max.secs=delta.secs;
163 rp->max.nsecs=delta.nsecs;
166 rp->tot.secs += delta.secs;
167 rp->tot.nsecs += delta.nsecs;
168 if(rp->tot.nsecs>1000000000){
169 rp->tot.nsecs-=1000000000;
179 rpcprogs_draw(void *dummy _U_)
186 printf("===================================================================\n");
187 printf("ONC-RPC Program Statistics:\n");
188 printf("Program Version Calls Min SRT Max SRT Avg SRT\n");
189 for(rp=prog_list;rp;rp=rp->next){
190 /* scale it to units of 10us.*/
192 td=td*100000+(int)rp->tot.nsecs/10000;
199 g_snprintf(str, sizeof(str), "%s(%d)",rpc_prog_name(rp->program),rp->program);
200 printf("%-15s %2d %6d %3d.%05d %3d.%05d %3" G_GINT64_MODIFIER "u.%05" G_GINT64_MODIFIER "u\n",
204 (int)rp->min.secs,rp->min.nsecs/10000,
205 (int)rp->max.secs,rp->max.nsecs/10000,
209 printf("===================================================================\n");
214 rpcprogs_init(const char *optarg _U_, void* userdata _U_)
216 GString *error_string;
223 error_string=register_tap_listener("rpc", NULL, NULL, NULL, rpcprogs_packet, rpcprogs_draw);
225 fprintf(stderr,"tshark: Couldn't register rpc,programs tap: %s\n",
227 g_string_free(error_string, TRUE);
234 register_tap_listener_rpcprogs(void)
236 register_stat_cmd_arg("rpc,programs", rpcprogs_init, NULL);