2 * rpcstat 2002 Ronnie Sahlberg
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0+*/
10 /* This module provides rpc call/reply SRT statistics to tshark.
11 * It is only used by tshark and not wireshark
22 #include <epan/packet_info.h>
24 #include <epan/stat_tap_ui.h>
25 #include <epan/dissectors/packet-rpc.h>
27 #define MICROSECS_PER_SEC 1000000
28 #define NANOSECS_PER_SEC 1000000000
30 void register_tap_listener_rpcprogs(void);
32 /* used to keep track of statistics for a specific program/version */
33 typedef struct _rpc_program_t {
34 struct _rpc_program_t *next;
43 static rpc_program_t *prog_list = NULL;
44 static int already_enabled = 0;
47 rpcprogs_packet(void *dummy1 _U_, packet_info *pinfo, epan_dissect_t *edt _U_, const void *pri)
49 const rpc_call_info_value *ri = (const rpc_call_info_value *)pri;
51 rpc_program_t *rp = NULL;
54 /* the list was empty */
55 rp = g_new(rpc_program_t, 1);
57 rp->program = ri->prog;
58 rp->version = ri->vers;
67 } else if ((ri->prog == prog_list->program)
68 && (ri->vers == prog_list->version)) {
70 } else if ( (ri->prog < prog_list->program)
71 || ((ri->prog == prog_list->program) && (ri->vers < prog_list->version))) {
72 /* we should be first entry in list */
73 rp = g_new(rpc_program_t, 1);
75 rp->program = ri->prog;
76 rp->version = ri->vers;
86 /* we go somewhere else in the list */
87 for (rp=prog_list; rp; rp=rp->next) {
89 && (rp->next->program == ri->prog)
90 && (rp->next->version == ri->vers)) {
95 || (rp->next->program > ri->prog)
96 || ( (rp->next->program == ri->prog)
97 && (rp->next->version > ri->vers))) {
99 trp = g_new(rpc_program_t, 1);
100 trp->next = rp->next;
101 trp->program = ri->prog;
102 trp->version = ri->vers;
118 /* we are only interested in reply packets */
119 if (ri->request || !rp) {
123 /* calculate time delta between request and reply */
124 nstime_delta(&delta, &pinfo->abs_ts, &ri->req_time);
126 if ((rp->max.secs == 0)
127 && (rp->max.nsecs == 0) ) {
128 rp->max.secs = delta.secs;
129 rp->max.nsecs = delta.nsecs;
132 if ((rp->min.secs == 0)
133 && (rp->min.nsecs == 0) ) {
134 rp->min.secs = delta.secs;
135 rp->min.nsecs = delta.nsecs;
138 if ( (delta.secs < rp->min.secs)
139 || ( (delta.secs == rp->min.secs)
140 && (delta.nsecs < rp->min.nsecs) ) ) {
141 rp->min.secs = delta.secs;
142 rp->min.nsecs = delta.nsecs;
145 if ( (delta.secs > rp->max.secs)
146 || ( (delta.secs == rp->max.secs)
147 && (delta.nsecs > rp->max.nsecs) ) ) {
148 rp->max.secs = delta.secs;
149 rp->max.nsecs = delta.nsecs;
152 rp->tot.secs += delta.secs;
153 rp->tot.nsecs += delta.nsecs;
154 if (rp->tot.nsecs > NANOSECS_PER_SEC) {
155 rp->tot.nsecs -= NANOSECS_PER_SEC;
165 rpcprogs_draw(void *dummy _U_)
172 printf("==========================================================\n");
173 printf("ONC-RPC Program Statistics:\n");
174 printf("Program Version Calls Min SRT Max SRT Avg SRT\n");
175 for (rp = prog_list;rp;rp = rp->next) {
176 /* Only display procs with non-zero calls */
180 /* Scale the average SRT in units of 1us and round to the nearest us. */
181 td = ((guint64)(rp->tot.secs)) * NANOSECS_PER_SEC + rp->tot.nsecs;
182 td = ((td / rp->num) + 500) / 1000;
184 g_snprintf(str, sizeof(str), "%s(%d)", rpc_prog_name(rp->program), rp->program);
185 printf("%-15s %2u %6d %3d.%06d %3d.%06d %3" G_GINT64_MODIFIER "u.%06" G_GINT64_MODIFIER "u\n",
189 (int)(rp->min.secs), (rp->min.nsecs+500)/1000,
190 (int)(rp->max.secs), (rp->max.nsecs+500)/1000,
191 td/MICROSECS_PER_SEC, td%MICROSECS_PER_SEC
194 printf("===================================================================\n");
199 rpcprogs_init(const char *opt_arg _U_, void *userdata _U_)
201 GString *error_string;
203 if (already_enabled) {
208 error_string = register_tap_listener("rpc", NULL, NULL, 0, NULL, rpcprogs_packet, rpcprogs_draw);
210 fprintf(stderr, "tshark: Couldn't register rpc,programs tap: %s\n",
212 g_string_free(error_string, TRUE);
217 static stat_tap_ui rpcprogs_ui = {
218 REGISTER_STAT_GROUP_GENERIC,
227 register_tap_listener_rpcprogs(void)
229 register_stat_tap_ui(&rpcprogs_ui, NULL);
233 * Editor modelines - http://www.wireshark.org/tools/modelines.html
238 * indent-tabs-mode: t
241 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
242 * :indentSize=8:tabSize=8:noTabs=false: