2 * rpcstat 2002 Ronnie Sahlberg
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 statistics to tethereal.
26 * It is only used by tethereal and not ethereal
35 #ifdef HAVE_SYS_TYPES_H
36 # include <sys/types.h>
40 #include "epan/packet_info.h"
42 #include <epan/stat.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 delta.secs=pinfo->fd->abs_secs-ri->req_time.secs;
139 delta.nsecs=pinfo->fd->abs_usecs*1000-ri->req_time.nsecs;
141 delta.nsecs+=1000000000;
146 && (rp->max.nsecs==0) ){
147 rp->max.secs=delta.secs;
148 rp->max.nsecs=delta.nsecs;
152 && (rp->min.nsecs==0) ){
153 rp->min.secs=delta.secs;
154 rp->min.nsecs=delta.nsecs;
157 if( (delta.secs<rp->min.secs)
158 ||( (delta.secs==rp->min.secs)
159 &&(delta.nsecs<rp->min.nsecs) ) ){
160 rp->min.secs=delta.secs;
161 rp->min.nsecs=delta.nsecs;
164 if( (delta.secs>rp->max.secs)
165 ||( (delta.secs==rp->max.secs)
166 &&(delta.nsecs>rp->max.nsecs) ) ){
167 rp->max.secs=delta.secs;
168 rp->max.nsecs=delta.nsecs;
171 rp->tot.secs += delta.secs;
172 rp->tot.nsecs += delta.nsecs;
173 if(rp->tot.nsecs>1000000000){
174 rp->tot.nsecs-=1000000000;
184 rpcprogs_draw(void *dummy _U_)
195 printf("===================================================================\n");
196 printf("ONC-RPC Program Statistics:\n");
197 printf("Program Version Calls Min SRT Max SRT Avg SRT\n");
198 for(rp=prog_list;rp;rp=rp->next){
199 /* scale it to units of 10us.*/
200 /* for long captures with a large tot time, this can overflow on 32bit */
201 td=(int)rp->tot.secs;
202 td=td*100000+(int)rp->tot.nsecs/10000;
209 g_snprintf(str, sizeof(str), "%s(%d)",rpc_prog_name(rp->program),rp->program);
210 printf("%-15s %2d %6d %3d.%05d %3d.%05d %3d.%05d\n",
214 (int)rp->min.secs,rp->min.nsecs/10000,
215 (int)rp->max.secs,rp->max.nsecs/10000,
219 printf("===================================================================\n");
224 rpcprogs_init(const char *optarg _U_)
226 GString *error_string;
233 error_string=register_tap_listener("rpc", NULL, NULL, NULL, rpcprogs_packet, rpcprogs_draw);
235 fprintf(stderr,"tethereal: Couldn't register rpc,programs tap: %s\n",
237 g_string_free(error_string, TRUE);
244 register_tap_listener_rpcprogs(void)
246 register_stat_cmd_arg("rpc,programs", rpcprogs_init);