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>
26 #include <rx/rxstat.h>
27 #include <afs/afs_Admin.h>
28 #include <afs/afs_AdminErrors.h>
29 #include <afs/afs_clientAdmin.h>
30 #include <afs/afs_utilAdmin.h>
32 #include <afs/afsint.h>
33 #define FSINT_COMMON_XG
34 #include <afs/afscbint.h>
35 #include <afs/kauth.h>
36 #include <afs/kautils.h>
37 #include <afs/ptint.h>
38 #include <afs/ptserver.h>
39 #include <afs/vldbint.h>
40 #include <afs/bosint.h>
41 #include <afs/volint.h>
42 #include <afs/volser.h>
43 #include <afs/bosint.h>
50 fprintf(stderr
, "Usage: rxstat_get_process <cell> <host> <port>\n");
55 ParseArgs(int argc
, char *argv
[], char **srvrName
, long *srvrPort
)
61 *srvrName
= *(argp
++);
64 *srvrPort
= strtol(*(argp
++), NULL
, 0);
65 if (*srvrPort
<= 0 || *srvrPort
>= 65536)
72 GetPrintStrings(afs_RPCStats_p statp
, char *ifName
, char *ifRole
,
73 const char ***funcList
, int *funcListLen
)
75 if (statp
->s
.stats_v1
.remote_is_server
) {
76 strcpy(ifRole
, "client");
78 strcpy(ifRole
, "server");
81 switch (statp
->s
.stats_v1
.interfaceId
) {
82 case RXSTATS_STATINDEX
:
83 strcpy(ifName
, "rxstats interface");
84 *funcList
= RXSTATS_function_names
;
85 *funcListLen
= RXSTATS_NO_OF_STAT_FUNCS
;
88 strcpy(ifName
, "fileserver interface");
89 *funcList
= RXAFS_function_names
;
90 *funcListLen
= RXAFS_NO_OF_STAT_FUNCS
;
92 case RXAFSCB_STATINDEX
:
93 strcpy(ifName
, "callback interface");
94 *funcList
= RXAFSCB_function_names
;
95 *funcListLen
= RXAFSCB_NO_OF_STAT_FUNCS
;
98 strcpy(ifName
, "ptserver interface");
99 *funcList
= PR_function_names
;
100 *funcListLen
= PR_NO_OF_STAT_FUNCS
;
103 strcpy(ifName
, "ubik disk interface");
104 *funcList
= DISK_function_names
;
105 *funcListLen
= DISK_NO_OF_STAT_FUNCS
;
108 strcpy(ifName
, "ubik vote interface");
109 *funcList
= VOTE_function_names
;
110 *funcListLen
= VOTE_NO_OF_STAT_FUNCS
;
113 strcpy(ifName
, "volserver interface");
114 *funcList
= VL_function_names
;
115 *funcListLen
= VL_NO_OF_STAT_FUNCS
;
117 case AFSVolSTATINDEX
:
118 strcpy(ifName
, "volserver interface");
119 *funcList
= AFSVolfunction_names
;
120 *funcListLen
= AFSVolNO_OF_STAT_FUNCS
;
123 strcpy(ifName
, "bosserver interface");
124 *funcList
= BOZO_function_names
;
125 *funcListLen
= BOZO_NO_OF_STAT_FUNCS
;
128 strcpy(ifName
, "KAA interface");
129 *funcList
= KAA_function_names
;
130 *funcListLen
= KAA_NO_OF_STAT_FUNCS
;
133 strcpy(ifName
, "KAM interface");
134 *funcList
= KAM_function_names
;
135 *funcListLen
= KAM_NO_OF_STAT_FUNCS
;
138 strcpy(ifName
, "KAT interface");
139 *funcList
= KAT_function_names
;
140 *funcListLen
= KAT_NO_OF_STAT_FUNCS
;
143 sprintf(ifName
, "interface 0x%x", statp
->s
.stats_v1
.interfaceId
);
151 main(int argc
, char *argv
[])
155 struct rx_connection
*conn
;
160 afs_RPCStats_t stats
;
163 const char **funcList
;
167 ParseArgs(argc
, argv
, &srvrName
, &srvrPort
);
169 rc
= afsclient_Init(&st
);
171 fprintf(stderr
, "afsclient_Init, status %d\n", st
);
175 rc
= afsclient_NullCellOpen(&cellHandle
, &st
);
177 fprintf(stderr
, "afsclient_NullCellOpen, status %d\n", st
);
181 rc
= afsclient_RPCStatOpenPort(cellHandle
, srvrName
, srvrPort
, &conn
,
184 fprintf(stderr
, "afsclient_RPCStatOpenPort, status %d\n", st
);
188 rc
= util_RPCStatsGetBegin(conn
, RXSTATS_RetrieveProcessRPCStats
,
191 fprintf(stderr
, "util_RPCStatsGetBegin, status %d\n", st
);
195 while (util_RPCStatsGetNext(iterator
, &stats
, &st
)) {
196 index
= stats
.s
.stats_v1
.func_index
;
199 GetPrintStrings(&stats
, ifName
, role
, &funcList
, &funcListLen
);
200 printf("\nProcess RPC stats for %s accessed as a %s\n\n", ifName
,
204 if (index
>= funcListLen
) {
205 printf(" Function index %d\n", index
);
207 printf(" %s\n", funcList
[index
]);
210 if (stats
.s
.stats_v1
.invocations
!= 0) {
211 printf("\tinvoc %"AFS_UINT64_FMT
212 " bytes_sent %"AFS_UINT64_FMT
213 " bytes_rcvd %"AFS_UINT64_FMT
"\n",
214 stats
.s
.stats_v1
.invocations
,
215 stats
.s
.stats_v1
.bytes_sent
,
216 stats
.s
.stats_v1
.bytes_rcvd
);
217 printf("\tqsum %d.%06d qsqr %d.%06d"
218 " qmin %d.%06d qmax %d.%06d\n",
219 stats
.s
.stats_v1
.queue_time_sum
.sec
,
220 stats
.s
.stats_v1
.queue_time_sum
.usec
,
221 stats
.s
.stats_v1
.queue_time_sum_sqr
.sec
,
222 stats
.s
.stats_v1
.queue_time_sum_sqr
.usec
,
223 stats
.s
.stats_v1
.queue_time_min
.sec
,
224 stats
.s
.stats_v1
.queue_time_min
.usec
,
225 stats
.s
.stats_v1
.queue_time_max
.sec
,
226 stats
.s
.stats_v1
.queue_time_max
.usec
);
227 printf("\txsum %d.%06d xsqr %d.%06d"
228 " xmin %d.%06d xmax %d.%06d\n",
229 stats
.s
.stats_v1
.execution_time_sum
.sec
,
230 stats
.s
.stats_v1
.execution_time_sum
.usec
,
231 stats
.s
.stats_v1
.execution_time_sum_sqr
.sec
,
232 stats
.s
.stats_v1
.execution_time_sum_sqr
.usec
,
233 stats
.s
.stats_v1
.execution_time_min
.sec
,
234 stats
.s
.stats_v1
.execution_time_min
.usec
,
235 stats
.s
.stats_v1
.execution_time_max
.sec
,
236 stats
.s
.stats_v1
.execution_time_max
.usec
);
238 printf("\tNever invoked\n");
241 if (st
!= ADMITERATORDONE
) {
242 fprintf(stderr
, "util_RPCStatsGetNext, status %d\n", st
);
247 rc
= util_RPCStatsGetDone(iterator
, &st
);
249 fprintf(stderr
, "util_RPCStatsGetDone, status %d\n", st
);
253 rc
= afsclient_RPCStatClose(conn
, &st
);
255 fprintf(stderr
, "afsclient_RPCStatClose, status %d\n", st
);
259 rc
= afsclient_CellClose(cellHandle
, &st
);
261 fprintf(stderr
, "afsclient_CellClose, status %d\n", st
);