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
9 * Portions Copyright (c) 2003 Apple Computer, Inc.
13 * This file contains sample code for the rxstats interface
16 #include <afsconfig.h>
17 #include <afs/param.h>
28 #include <afs/afs_Admin.h>
29 #include <afs/afs_AdminErrors.h>
30 #include <afs/afs_clientAdmin.h>
31 #include <afs/afs_utilAdmin.h>
34 pthread_mutex_t des_init_mutex = PTHREAD_MUTEX_INITIALIZER;
35 pthread_mutex_t des_random_mutex = PTHREAD_MUTEX_INITIALIZER;
36 pthread_mutex_t rxkad_random_mutex = PTHREAD_MUTEX_INITIALIZER;
37 #endif /* AFS_DARWIN_ENV */
39 #include <rx/rxstat.h>
40 #include <afs/afsint.h>
41 #define FSINT_COMMON_XG
42 #include <afs/afscbint.h>
43 #include <afs/kauth.h>
44 #include <afs/kautils.h>
45 #include <afs/ptint.h>
46 #include <afs/ptserver.h>
47 #include <afs/vldbint.h>
48 #include <afs/bosint.h>
49 #include <afs/volint.h>
50 #include <afs/volser.h>
51 #include <afs/bosint.h>
55 extern int RXSTATS_RetrieveProcessRPCStats();
60 fprintf(stderr, "Usage: rxstat_get_process <cell> <host> <port>\n");
65 ParseArgs(int argc, char *argv[], char **srvrName, long *srvrPort)
71 *srvrName = *(argp++);
74 *srvrPort = strtol(*(argp++), NULL, 0);
75 if (*srvrPort <= 0 || *srvrPort >= 65536)
82 GetPrintStrings(afs_RPCStats_p statp, char *ifName, char *ifRole,
83 const char ***funcList, int *funcListLen)
85 if (statp->s.stats_v1.remote_is_server) {
86 strcpy(ifRole, "client");
88 strcpy(ifRole, "server");
91 switch (statp->s.stats_v1.interfaceId) {
92 case RXSTATS_STATINDEX:
93 strcpy(ifName, "rxstats interface");
94 *funcList = RXSTATS_function_names;
95 *funcListLen = RXSTATS_NO_OF_STAT_FUNCS;
98 strcpy(ifName, "fileserver interface");
99 *funcList = RXAFS_function_names;
100 *funcListLen = RXAFS_NO_OF_STAT_FUNCS;
102 case RXAFSCB_STATINDEX:
103 strcpy(ifName, "callback interface");
104 *funcList = RXAFSCB_function_names;
105 *funcListLen = RXAFSCB_NO_OF_STAT_FUNCS;
108 strcpy(ifName, "ptserver interface");
109 *funcList = PR_function_names;
110 *funcListLen = PR_NO_OF_STAT_FUNCS;
113 strcpy(ifName, "ubik disk interface");
114 *funcList = DISK_function_names;
115 *funcListLen = DISK_NO_OF_STAT_FUNCS;
118 strcpy(ifName, "ubik vote interface");
119 *funcList = VOTE_function_names;
120 *funcListLen = VOTE_NO_OF_STAT_FUNCS;
123 strcpy(ifName, "volserver interface");
124 *funcList = VL_function_names;
125 *funcListLen = VL_NO_OF_STAT_FUNCS;
127 case AFSVolSTATINDEX:
128 strcpy(ifName, "volserver interface");
129 *funcList = AFSVolfunction_names;
130 *funcListLen = AFSVolNO_OF_STAT_FUNCS;
133 strcpy(ifName, "bosserver interface");
134 *funcList = BOZO_function_names;
135 *funcListLen = BOZO_NO_OF_STAT_FUNCS;
138 strcpy(ifName, "KAA interface");
139 *funcList = KAA_function_names;
140 *funcListLen = KAA_NO_OF_STAT_FUNCS;
143 strcpy(ifName, "KAM interface");
144 *funcList = KAM_function_names;
145 *funcListLen = KAM_NO_OF_STAT_FUNCS;
148 strcpy(ifName, "KAT interface");
149 *funcList = KAT_function_names;
150 *funcListLen = KAT_NO_OF_STAT_FUNCS;
153 sprintf(ifName, "interface 0x%x", statp->s.stats_v1.interfaceId);
161 main(int argc, char *argv[])
165 struct rx_connection *conn;
170 afs_RPCStats_t stats;
173 const char **funcList;
177 ParseArgs(argc, argv, &srvrName, &srvrPort);
179 rc = afsclient_Init(&st);
181 fprintf(stderr, "afsclient_Init, status %d\n", st);
185 rc = afsclient_NullCellOpen(&cellHandle, &st);
187 fprintf(stderr, "afsclient_NullCellOpen, status %d\n", st);
191 rc = afsclient_RPCStatOpenPort(cellHandle, srvrName, srvrPort, &conn,
194 fprintf(stderr, "afsclient_RPCStatOpenPort, status %d\n", st);
198 rc = util_RPCStatsGetBegin(conn, RXSTATS_RetrieveProcessRPCStats,
201 fprintf(stderr, "util_RPCStatsGetBegin, status %d\n", st);
205 while (util_RPCStatsGetNext(iterator, &stats, &st)) {
206 index = stats.s.stats_v1.func_index;
209 GetPrintStrings(&stats, ifName, role, &funcList, &funcListLen);
210 printf("\nProcess RPC stats for %s accessed as a %s\n\n", ifName,
214 if (index >= funcListLen) {
215 printf(" Function index %d\n", index);
217 printf(" %s\n", funcList[index]);
220 if (!hiszero(stats.s.stats_v1.invocations)) {
221 printf("\tinvoc (%u.%u) bytes_sent (%u.%u) bytes_rcvd (%u.%u)\n",
222 hgethi(stats.s.stats_v1.invocations),
223 hgetlo(stats.s.stats_v1.invocations),
224 hgethi(stats.s.stats_v1.bytes_sent),
225 hgetlo(stats.s.stats_v1.bytes_sent),
226 hgethi(stats.s.stats_v1.bytes_rcvd),
227 hgetlo(stats.s.stats_v1.bytes_rcvd));
228 printf("\tqsum %d.%06d qsqr %d.%06d"
229 " qmin %d.%06d qmax %d.%06d\n",
230 stats.s.stats_v1.queue_time_sum.sec,
231 stats.s.stats_v1.queue_time_sum.usec,
232 stats.s.stats_v1.queue_time_sum_sqr.sec,
233 stats.s.stats_v1.queue_time_sum_sqr.usec,
234 stats.s.stats_v1.queue_time_min.sec,
235 stats.s.stats_v1.queue_time_min.usec,
236 stats.s.stats_v1.queue_time_max.sec,
237 stats.s.stats_v1.queue_time_max.usec);
238 printf("\txsum %d.%06d xsqr %d.%06d"
239 " xmin %d.%06d xmax %d.%06d\n",
240 stats.s.stats_v1.execution_time_sum.sec,
241 stats.s.stats_v1.execution_time_sum.usec,
242 stats.s.stats_v1.execution_time_sum_sqr.sec,
243 stats.s.stats_v1.execution_time_sum_sqr.usec,
244 stats.s.stats_v1.execution_time_min.sec,
245 stats.s.stats_v1.execution_time_min.usec,
246 stats.s.stats_v1.execution_time_max.sec,
247 stats.s.stats_v1.execution_time_max.usec);
249 printf("\tNever invoked\n");
252 if (st != ADMITERATORDONE) {
253 fprintf(stderr, "util_RPCStatsGetNext, status %d\n", st);
258 rc = util_RPCStatsGetDone(iterator, &st);
260 fprintf(stderr, "util_RPCStatsGetDone, status %d\n", st);
264 rc = afsclient_RPCStatClose(conn, &st);
266 fprintf(stderr, "afsclient_RPCStatClose, status %d\n", st);
270 rc = afsclient_CellClose(cellHandle, &st);
272 fprintf(stderr, "afsclient_CellClose, status %d\n", st);