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>
35 #include <afs/afs_Admin.h>
36 #include <afs/afs_AdminErrors.h>
37 #include <afs/afs_clientAdmin.h>
38 #include <afs/afs_utilAdmin.h>
41 pthread_mutex_t des_init_mutex = PTHREAD_MUTEX_INITIALIZER;
42 pthread_mutex_t des_random_mutex = PTHREAD_MUTEX_INITIALIZER;
43 pthread_mutex_t rxkad_random_mutex = PTHREAD_MUTEX_INITIALIZER;
44 #endif /* AFS_DARWIN_ENV */
46 #include <rx/rxstat.h>
47 #include <afs/afsint.h>
48 #define FSINT_COMMON_XG
49 #include <afs/afscbint.h>
50 #include <afs/kauth.h>
51 #include <afs/kautils.h>
52 #include <afs/ptint.h>
53 #include <afs/ptserver.h>
54 #include <afs/vldbint.h>
55 #include <afs/bosint.h>
56 #include <afs/volint.h>
57 #include <afs/volser.h>
58 #include <afs/bosint.h>
62 extern int RXSTATS_RetrieveProcessRPCStats();
67 fprintf(stderr, "Usage: rxstat_get_process <cell> <host> <port>\n");
72 ParseArgs(int argc, char *argv[], char **srvrName, long *srvrPort)
78 *srvrName = *(argp++);
81 *srvrPort = strtol(*(argp++), NULL, 0);
82 if (*srvrPort <= 0 || *srvrPort >= 65536)
89 GetPrintStrings(afs_RPCStats_p statp, char *ifName, char *ifRole,
90 const char ***funcList, int *funcListLen)
92 if (statp->s.stats_v1.remote_is_server) {
93 strcpy(ifRole, "client");
95 strcpy(ifRole, "server");
98 switch (statp->s.stats_v1.interfaceId) {
99 case RXSTATS_STATINDEX:
100 strcpy(ifName, "rxstats interface");
101 *funcList = RXSTATS_function_names;
102 *funcListLen = RXSTATS_NO_OF_STAT_FUNCS;
104 case RXAFS_STATINDEX:
105 strcpy(ifName, "fileserver interface");
106 *funcList = RXAFS_function_names;
107 *funcListLen = RXAFS_NO_OF_STAT_FUNCS;
109 case RXAFSCB_STATINDEX:
110 strcpy(ifName, "callback interface");
111 *funcList = RXAFSCB_function_names;
112 *funcListLen = RXAFSCB_NO_OF_STAT_FUNCS;
115 strcpy(ifName, "ptserver interface");
116 *funcList = PR_function_names;
117 *funcListLen = PR_NO_OF_STAT_FUNCS;
120 strcpy(ifName, "ubik disk interface");
121 *funcList = DISK_function_names;
122 *funcListLen = DISK_NO_OF_STAT_FUNCS;
125 strcpy(ifName, "ubik vote interface");
126 *funcList = VOTE_function_names;
127 *funcListLen = VOTE_NO_OF_STAT_FUNCS;
130 strcpy(ifName, "volserver interface");
131 *funcList = VL_function_names;
132 *funcListLen = VL_NO_OF_STAT_FUNCS;
134 case AFSVolSTATINDEX:
135 strcpy(ifName, "volserver interface");
136 *funcList = AFSVolfunction_names;
137 *funcListLen = AFSVolNO_OF_STAT_FUNCS;
140 strcpy(ifName, "bosserver interface");
141 *funcList = BOZO_function_names;
142 *funcListLen = BOZO_NO_OF_STAT_FUNCS;
145 strcpy(ifName, "KAA interface");
146 *funcList = KAA_function_names;
147 *funcListLen = KAA_NO_OF_STAT_FUNCS;
150 strcpy(ifName, "KAM interface");
151 *funcList = KAM_function_names;
152 *funcListLen = KAM_NO_OF_STAT_FUNCS;
155 strcpy(ifName, "KAT interface");
156 *funcList = KAT_function_names;
157 *funcListLen = KAT_NO_OF_STAT_FUNCS;
160 sprintf(ifName, "interface 0x%x", statp->s.stats_v1.interfaceId);
168 main(int argc, char *argv[])
172 struct rx_connection *conn;
177 afs_RPCStats_t stats;
180 const char **funcList;
184 ParseArgs(argc, argv, &srvrName, &srvrPort);
186 rc = afsclient_Init(&st);
188 fprintf(stderr, "afsclient_Init, status %d\n", st);
192 rc = afsclient_NullCellOpen(&cellHandle, &st);
194 fprintf(stderr, "afsclient_NullCellOpen, status %d\n", st);
198 rc = afsclient_RPCStatOpenPort(cellHandle, srvrName, srvrPort, &conn,
201 fprintf(stderr, "afsclient_RPCStatOpenPort, status %d\n", st);
205 rc = util_RPCStatsGetBegin(conn, RXSTATS_RetrieveProcessRPCStats,
208 fprintf(stderr, "util_RPCStatsGetBegin, status %d\n", st);
212 while (util_RPCStatsGetNext(iterator, &stats, &st)) {
213 index = stats.s.stats_v1.func_index;
216 GetPrintStrings(&stats, ifName, role, &funcList, &funcListLen);
217 printf("\nProcess RPC stats for %s accessed as a %s\n\n", ifName,
221 if (index >= funcListLen) {
222 printf(" Function index %d\n", index);
224 printf(" %s\n", funcList[index]);
227 if (!hiszero(stats.s.stats_v1.invocations)) {
228 printf("\tinvoc (%u.%u) bytes_sent (%u.%u) bytes_rcvd (%u.%u)\n",
229 hgethi(stats.s.stats_v1.invocations),
230 hgetlo(stats.s.stats_v1.invocations),
231 hgethi(stats.s.stats_v1.bytes_sent),
232 hgetlo(stats.s.stats_v1.bytes_sent),
233 hgethi(stats.s.stats_v1.bytes_rcvd),
234 hgetlo(stats.s.stats_v1.bytes_rcvd));
235 printf("\tqsum %d.%06d qsqr %d.%06d"
236 " qmin %d.%06d qmax %d.%06d\n",
237 stats.s.stats_v1.queue_time_sum.sec,
238 stats.s.stats_v1.queue_time_sum.usec,
239 stats.s.stats_v1.queue_time_sum_sqr.sec,
240 stats.s.stats_v1.queue_time_sum_sqr.usec,
241 stats.s.stats_v1.queue_time_min.sec,
242 stats.s.stats_v1.queue_time_min.usec,
243 stats.s.stats_v1.queue_time_max.sec,
244 stats.s.stats_v1.queue_time_max.usec);
245 printf("\txsum %d.%06d xsqr %d.%06d"
246 " xmin %d.%06d xmax %d.%06d\n",
247 stats.s.stats_v1.execution_time_sum.sec,
248 stats.s.stats_v1.execution_time_sum.usec,
249 stats.s.stats_v1.execution_time_sum_sqr.sec,
250 stats.s.stats_v1.execution_time_sum_sqr.usec,
251 stats.s.stats_v1.execution_time_min.sec,
252 stats.s.stats_v1.execution_time_min.usec,
253 stats.s.stats_v1.execution_time_max.sec,
254 stats.s.stats_v1.execution_time_max.usec);
256 printf("\tNever invoked\n");
259 if (st != ADMITERATORDONE) {
260 fprintf(stderr, "util_RPCStatsGetNext, status %d\n", st);
265 rc = util_RPCStatsGetDone(iterator, &st);
267 fprintf(stderr, "util_RPCStatsGetDone, status %d\n", st);
271 rc = afsclient_RPCStatClose(conn, &st);
273 fprintf(stderr, "afsclient_RPCStatClose, status %d\n", st);
277 rc = afsclient_CellClose(cellHandle, &st);
279 fprintf(stderr, "afsclient_CellClose, status %d\n", st);