2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 * This file contains sample code for the rxstats interface
14 #include <afsconfig.h>
15 #include <afs/param.h>
33 #include <afs/afs_Admin.h>
34 #include <afs/afs_AdminErrors.h>
35 #include <afs/afs_clientAdmin.h>
36 #include <afs/afs_utilAdmin.h>
37 #include <rx/rxstat.h>
38 #include <afs/afsint.h>
39 #define FSINT_COMMON_XG
40 #include <afs/afscbint.h>
41 #include <afs/kauth.h>
42 #include <afs/kautils.h>
43 #include <afs/ptint.h>
44 #include <afs/ptserver.h>
45 #include <afs/vldbint.h>
46 #include <afs/bosint.h>
47 #include <afs/volint.h>
48 #include <afs/volser.h>
49 #include <afs/bosint.h>
53 extern int RXSTATS_RetrieveProcessRPCStats();
58 fprintf(stderr, "Usage: rxstat_get_process <cell> <host> <port>\n");
63 ParseArgs(int argc, char *argv[], char **srvrName, long *srvrPort)
69 *srvrName = *(argp++);
72 *srvrPort = strtol(*(argp++), NULL, 0);
73 if (*srvrPort <= 0 || *srvrPort >= 65536)
80 GetPrintStrings(afs_RPCStats_p statp, char *ifName, char *ifRole,
81 const char ***funcList, int *funcListLen)
83 if (statp->s.stats_v1.remote_is_server) {
84 strcpy(ifRole, "client");
86 strcpy(ifRole, "server");
89 switch (statp->s.stats_v1.interfaceId) {
90 case RXSTATS_STATINDEX:
91 strcpy(ifName, "rxstats interface");
92 *funcList = RXSTATS_function_names;
93 *funcListLen = RXSTATS_NO_OF_STAT_FUNCS;
96 strcpy(ifName, "fileserver interface");
97 *funcList = RXAFS_function_names;
98 *funcListLen = RXAFS_NO_OF_STAT_FUNCS;
100 case RXAFSCB_STATINDEX:
101 strcpy(ifName, "callback interface");
102 *funcList = RXAFSCB_function_names;
103 *funcListLen = RXAFSCB_NO_OF_STAT_FUNCS;
106 strcpy(ifName, "ptserver interface");
107 *funcList = PR_function_names;
108 *funcListLen = PR_NO_OF_STAT_FUNCS;
111 strcpy(ifName, "ubik disk interface");
112 *funcList = DISK_function_names;
113 *funcListLen = DISK_NO_OF_STAT_FUNCS;
116 strcpy(ifName, "ubik vote interface");
117 *funcList = VOTE_function_names;
118 *funcListLen = VOTE_NO_OF_STAT_FUNCS;
121 strcpy(ifName, "volserver interface");
122 *funcList = VL_function_names;
123 *funcListLen = VL_NO_OF_STAT_FUNCS;
125 case AFSVolSTATINDEX:
126 strcpy(ifName, "volserver interface");
127 *funcList = AFSVolfunction_names;
128 *funcListLen = AFSVolNO_OF_STAT_FUNCS;
131 strcpy(ifName, "bosserver interface");
132 *funcList = BOZO_function_names;
133 *funcListLen = BOZO_NO_OF_STAT_FUNCS;
136 strcpy(ifName, "KAA interface");
137 *funcList = KAA_function_names;
138 *funcListLen = KAA_NO_OF_STAT_FUNCS;
141 strcpy(ifName, "KAM interface");
142 *funcList = KAM_function_names;
143 *funcListLen = KAM_NO_OF_STAT_FUNCS;
146 strcpy(ifName, "KAT interface");
147 *funcList = KAT_function_names;
148 *funcListLen = KAT_NO_OF_STAT_FUNCS;
151 sprintf(ifName, "interface 0x%x", statp->s.stats_v1.interfaceId);
159 main(int argc, char *argv[])
163 struct rx_connection *conn;
168 afs_RPCStats_t stats;
171 const char **funcList;
175 ParseArgs(argc, argv, &srvrName, &srvrPort);
177 rc = afsclient_Init(&st);
179 fprintf(stderr, "afsclient_Init, status %d\n", st);
183 rc = afsclient_NullCellOpen(&cellHandle, &st);
185 fprintf(stderr, "afsclient_NullCellOpen, status %d\n", st);
189 rc = afsclient_RPCStatOpenPort(cellHandle, srvrName, srvrPort, &conn,
192 fprintf(stderr, "afsclient_RPCStatOpenPort, status %d\n", st);
196 rc = util_RPCStatsGetBegin(conn, RXSTATS_RetrieveProcessRPCStats,
199 fprintf(stderr, "util_RPCStatsGetBegin, status %d\n", st);
203 while (util_RPCStatsGetNext(iterator, &stats, &st)) {
204 index = stats.s.stats_v1.func_index;
207 GetPrintStrings(&stats, ifName, role, &funcList, &funcListLen);
208 printf("\nProcess RPC stats for %s accessed as a %s\n\n", ifName,
212 if (index >= funcListLen) {
213 printf(" Function index %d\n", index);
215 printf(" %s\n", funcList[index]);
218 if (!hiszero(stats.s.stats_v1.invocations)) {
219 printf("\tinvoc (%u.%u) bytes_sent (%u.%u) bytes_rcvd (%u.%u)\n",
220 hgethi(stats.s.stats_v1.invocations),
221 hgetlo(stats.s.stats_v1.invocations),
222 hgethi(stats.s.stats_v1.bytes_sent),
223 hgetlo(stats.s.stats_v1.bytes_sent),
224 hgethi(stats.s.stats_v1.bytes_rcvd),
225 hgetlo(stats.s.stats_v1.bytes_rcvd));
226 printf("\tqsum %d.%06d qsqr %d.%06d"
227 " qmin %d.%06d qmax %d.%06d\n",
228 stats.s.stats_v1.queue_time_sum.sec,
229 stats.s.stats_v1.queue_time_sum.usec,
230 stats.s.stats_v1.queue_time_sum_sqr.sec,
231 stats.s.stats_v1.queue_time_sum_sqr.usec,
232 stats.s.stats_v1.queue_time_min.sec,
233 stats.s.stats_v1.queue_time_min.usec,
234 stats.s.stats_v1.queue_time_max.sec,
235 stats.s.stats_v1.queue_time_max.usec);
236 printf("\txsum %d.%06d xsqr %d.%06d"
237 " xmin %d.%06d xmax %d.%06d\n",
238 stats.s.stats_v1.execution_time_sum.sec,
239 stats.s.stats_v1.execution_time_sum.usec,
240 stats.s.stats_v1.execution_time_sum_sqr.sec,
241 stats.s.stats_v1.execution_time_sum_sqr.usec,
242 stats.s.stats_v1.execution_time_min.sec,
243 stats.s.stats_v1.execution_time_min.usec,
244 stats.s.stats_v1.execution_time_max.sec,
245 stats.s.stats_v1.execution_time_max.usec);
247 printf("\tNever invoked\n");
250 if (st != ADMITERATORDONE) {
251 fprintf(stderr, "util_RPCStatsGetNext, status %d\n", st);
256 rc = util_RPCStatsGetDone(iterator, &st);
258 fprintf(stderr, "util_RPCStatsGetDone, status %d\n", st);
262 rc = afsclient_RPCStatClose(conn, &st);
264 fprintf(stderr, "afsclient_RPCStatClose, status %d\n", st);
268 rc = afsclient_CellClose(cellHandle, &st);
270 fprintf(stderr, "afsclient_CellClose, status %d\n", st);