Some doc path fixes from Anders
[pkg-k5-afs_openafs.git] / src / rx / rx_trace.c
blob94dc117140e3851dd1d746fb3abf2ab54bd2b8f2
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
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
8 */
10 #include <afsconfig.h>
11 #include <afs/param.h>
13 #include <roken.h>
15 #ifndef RXDEBUG
16 char rxi_tracename[80] = "\0Tracing not compiled in";
17 #ifdef DUMPTRACE
18 int
19 main(int argc, char **argv)
21 return 0;
23 #endif
24 #else
26 #include "rx.h"
27 #include "rx_atomic.h"
28 #include "rx_globals.h"
29 #include "rx_internal.h"
30 #include "rx_trace.h"
32 #include "rx_conn.h"
33 #include "rx_call.h"
35 #ifdef RXTRACEON
36 char rxi_tracename[80] = "/tmp/rxcalltrace";
37 #else
38 char rxi_tracename[80] =
39 "\0Change This pathname (and preceding NUL) to initiate tracing";
40 #endif
41 int rxi_logfd = -1;
42 char rxi_tracebuf[4096];
43 afs_uint32 rxi_tracepos = 0;
45 struct rx_trace {
46 afs_uint32 cid;
47 unsigned short call;
48 unsigned short qlen;
49 afs_uint32 now;
50 afs_uint32 waittime;
51 afs_uint32 servicetime;
52 afs_uint32 event;
55 void
56 rxi_flushtrace(void)
58 afs_uint32 len = rxi_tracepos;
60 rxi_tracepos = 0;
61 if (rxi_logfd < 0)
62 return;
63 if (write(rxi_logfd, rxi_tracebuf, len) < 0)
64 ; /* don't care */
67 void
68 rxi_calltrace(unsigned int event, struct rx_call *call)
70 struct clock now;
71 struct rx_trace rxtinfo;
73 if (!rxi_tracename[0])
74 return;
76 if (rxi_logfd < 0) {
77 rxi_logfd = open(rxi_tracename, O_WRONLY | O_CREAT | O_TRUNC, 0777);
78 if (rxi_logfd < 0)
79 rxi_tracename[0] = '\0';
81 clock_GetTime(&now);
83 rxtinfo.event = event;
84 rxtinfo.now = now.sec * 1000 + now.usec / 1000;
85 rxtinfo.cid = call->conn->cid;
86 rxtinfo.call = *(call->callNumber);
87 rxtinfo.qlen = rx_atomic_read(&rx_nWaiting);
88 rxtinfo.servicetime = 0;
89 rxtinfo.waittime = 0;
91 switch (event) {
92 case RX_CALL_END:
93 clock_Sub(&now, &(call->traceStart));
94 rxtinfo.servicetime = now.sec * 10000 + now.usec / 100;
95 if (call->traceWait.sec) {
96 now = call->traceStart;
97 clock_Sub(&now, &(call->traceWait));
98 rxtinfo.waittime = now.sec * 10000 + now.usec / 100;
99 } else
100 rxtinfo.waittime = 0;
101 call->traceWait.sec = call->traceWait.usec = call->traceStart.sec =
102 call->traceStart.usec = 0;
103 break;
105 case RX_CALL_START:
106 call->traceStart = now;
107 if (call->traceWait.sec) {
108 clock_Sub(&now, &(call->traceWait));
109 rxtinfo.waittime = now.sec * 10000 + now.usec / 100;
110 } else
111 rxtinfo.waittime = 0;
112 break;
114 case RX_TRACE_DROP:
115 if (call->traceWait.sec) {
116 clock_Sub(&now, &(call->traceWait));
117 rxtinfo.waittime = now.sec * 10000 + now.usec / 100;
118 } else
119 rxtinfo.waittime = 0;
120 break;
122 case RX_CALL_ARRIVAL:
123 call->traceWait = now;
124 default:
125 break;
128 memcpy(rxi_tracebuf + rxi_tracepos, &rxtinfo, sizeof(struct rx_trace));
129 rxi_tracepos += sizeof(struct rx_trace);
130 if (rxi_tracepos >= (4096 - sizeof(struct rx_trace)))
131 rxi_flushtrace();
134 #ifdef DUMPTRACE
135 #ifdef AFS_NT40_ENV
136 #include <afs/afsutil.h>
137 #endif
140 main(int argc, char **argv)
142 struct rx_trace ip;
143 int err = 0;
145 setlinebuf(stdout);
146 argv++;
147 argc--;
148 while (argc && **argv == '-') {
149 if (strcmp(*argv, "-trace") == 0) {
150 strcpy(rxi_tracename, *(++argv));
151 argc--;
152 } else {
153 err++;
154 break;
156 argv++, argc--;
158 if (err || argc != 0) {
159 printf("usage: dumptrace [-trace pathname]");
160 exit(1);
163 rxi_logfd = open(rxi_tracename, O_RDONLY);
164 if (rxi_logfd < 0) {
165 perror("");
166 exit(errno);
169 while (read(rxi_logfd, &ip, sizeof(struct rx_trace))) {
170 printf("%9u ", ip.now);
171 switch (ip.event) {
172 case RX_CALL_END:
173 putchar('E');
174 break;
175 case RX_CALL_START:
176 putchar('S');
177 break;
178 case RX_CALL_ARRIVAL:
179 putchar('A');
180 break;
181 case RX_TRACE_DROP:
182 putchar('D');
183 break;
184 default:
185 putchar('U');
186 break;
188 printf(" %3u %7u %7u %x.%x\n", ip.qlen, ip.servicetime,
189 ip.waittime, ip.cid, ip.call);
191 return 0;
194 #endif /* DUMPTRACE */
195 #endif /* RXDEBUG */