use a cell that actually exists
[arla.git] / rx / rx_trace.c
blob0cbb49b450cd5e70e5ae035e4522a8dcc01fbfad
1 /*
2 ****************************************************************************
3 * Copyright IBM Corporation 1988, 1989 - All Rights Reserved *
4 * *
5 * Permission to use, copy, modify, and distribute this software and its *
6 * documentation for any purpose and without fee is hereby granted, *
7 * provided that the above copyright notice appear in all copies and *
8 * that both that copyright notice and this permission notice appear in *
9 * supporting documentation, and that the name of IBM not be used in *
10 * advertising or publicity pertaining to distribution of the software *
11 * without specific, written prior permission. *
12 * *
13 * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL *
14 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL IBM *
15 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY *
16 * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER *
17 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING *
18 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *
19 ****************************************************************************
22 #include "rx_locl.h"
24 RCSID("$Id$");
26 #ifdef RXTRACEON
27 char rxi_tracename[80] = "/tmp/rxcalltrace";
29 #else
30 char rxi_tracename[80] = "\0Change This pathname (and preceding NUL) to initiate tracing";
32 #endif
34 #ifdef RXDEBUG
36 int rxi_logfd = 0;
37 char rxi_tracebuf[4096];
38 unsigned long rxi_tracepos = 0;
40 struct rx_trace rxtinfo;
42 void
43 rxi_flushtrace(void)
45 write(rxi_logfd, rxi_tracebuf, rxi_tracepos);
46 rxi_tracepos = 0;
49 void
50 rxi_calltrace(unsigned int event, struct rx_call *call)
52 struct clock now;
54 if (!rxi_tracename[0])
55 return;
57 if (!rxi_logfd) {
58 rxi_logfd = open(rxi_tracename, O_WRONLY | O_CREAT | O_TRUNC, 0777);
59 if (!rxi_logfd)
60 rxi_tracename[0] = '\0';
62 clock_GetTime(&now);
64 rxtinfo.event = event;
65 rxtinfo.now = now.sec * 1000 + now.usec / 1000;
66 rxtinfo.cid = call->conn->cid;
67 rxtinfo.call = *(call->callNumber);
68 rxtinfo.qlen = rx_nWaiting;
69 rxtinfo.servicetime = 0;
70 rxtinfo.waittime = 0;
72 switch (event) {
73 case RX_CALL_END:
74 clock_Sub(&now, &(call->traceStart));
75 rxtinfo.servicetime = now.sec * 10000 + now.usec / 100;
76 if (call->traceWait.sec) {
77 now = call->traceStart;
78 clock_Sub(&now, &(call->traceWait));
79 rxtinfo.waittime = now.sec * 10000 + now.usec / 100;
80 } else
81 rxtinfo.waittime = 0;
82 call->traceWait.sec = call->traceWait.usec =
83 call->traceStart.sec = call->traceStart.usec = 0;
84 break;
86 case RX_CALL_START:
87 call->traceStart = now;
88 if (call->traceWait.sec) {
89 clock_Sub(&now, &(call->traceWait));
90 rxtinfo.waittime = now.sec * 10000 + now.usec / 100;
91 } else
92 rxtinfo.waittime = 0;
93 break;
95 case RX_TRACE_DROP:
96 if (call->traceWait.sec) {
97 clock_Sub(&now, &(call->traceWait));
98 rxtinfo.waittime = now.sec * 10000 + now.usec / 100;
99 } else
100 rxtinfo.waittime = 0;
101 break;
103 case RX_CALL_ARRIVAL:
104 call->traceWait = now;
105 default:
106 break;
109 memcpy(rxi_tracebuf + rxi_tracepos, &rxtinfo, sizeof(struct rx_trace));
110 rxi_tracepos += sizeof(struct rx_trace);
111 if (rxi_tracepos >= (4096 - sizeof(struct rx_trace)))
112 rxi_flushtrace();
115 #endif /* RXDEBUG */