Prototypes for rxdebug
[openafs.git] / src / rxdebug / rxdumptrace.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
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  */
9
10 #include <afsconfig.h>
11 #include <afs/param.h>
12
13
14 #ifdef RXDEBUG
15 #include <string.h>
16 #ifdef AFS_NT40_ENV
17 #include <fcntl.h>
18 #include <io.h>
19 #else
20 #include <sys/file.h>
21 #include <unistd.h>
22 #endif
23 #include "rx.h"
24 #include "rx_globals.h"
25 #include "rx_trace.h"
26
27 extern char *rxi_tracename;
28 extern int rxi_logfd;
29
30 struct rx_trace {
31     afs_uint32 cid;
32     unsigned short call;
33     unsigned short qlen;
34     afs_uint32 now;
35     afs_uint32 waittime;
36     afs_uint32 servicetime;
37     afs_uint32 event;
38 };
39
40 #include <errno.h>
41 #ifdef AFS_NT40_ENV
42 #include <afs/afsutil.h>
43 #endif
44
45 int
46 main(int argc, char **argv)
47 {
48     struct rx_trace ip;
49     int err = 0;
50
51     setlinebuf(stdout);
52     argv++;
53     argc--;
54     while (argc && **argv == '-') {
55         if (strcmp(*argv, "-trace") == 0) {
56             strcpy(rxi_tracename, *(++argv));
57             argc--;
58         } else {
59             err++;
60             break;
61         }
62         argv++, argc--;
63     }
64     if (err || argc != 0) {
65         printf("usage: dumptrace [-trace pathname]");
66         exit(1);
67     }
68
69     rxi_logfd = open(rxi_tracename, O_RDONLY);
70     if (rxi_logfd < 0) {
71         perror("");
72         exit(errno);
73     }
74
75     while (read(rxi_logfd, &ip, sizeof(struct rx_trace))) {
76         printf("%9u ", ip.now);
77         switch (ip.event) {
78         case RX_CALL_END:
79             putchar('E');
80             break;
81         case RX_CALL_START:
82             putchar('S');
83             break;
84         case RX_CALL_ARRIVAL:
85             putchar('A');
86             break;
87         case RX_TRACE_DROP:
88             putchar('D');
89             break;
90         default:
91             putchar('U');
92             break;
93         }
94         printf(" %3u %7u %7u      %x.%x\n", ip.qlen, ip.servicetime,
95                ip.waittime, ip.cid, ip.call);
96     }
97     return 0;
98 }
99
100 #endif