xtrapstats.c revision 876ff6fe
1/* $XFree86: xc/programs/xtrap/xtrapstats.c,v 1.1tsi Exp $ */
2/*
3 * @DEC_COPYRIGHT@
4 */
5/*
6 * HISTORY
7 * Log: xtrapstats.c,v $
8 * Revision 1.1.4.2  1993/12/14  12:37:41  Kenneth_Miller
9 * 	ANSI-standardize code and turn client build on
10 * 	[1993/12/09  20:16:19  Kenneth_Miller]
11 *
12 * Revision 1.1.2.2  1992/04/27  13:52:12  Leela_Obilichetti
13 * 	initial load of xtrap clients - from silver BL6 pool
14 * 	[92/04/27  13:49:48  Leela_Obilichetti]
15 *
16 * EndLog$
17 */
18/*****************************************************************************
19Copyright 1987, 1988, 1989, 1990, 1991, 1992, 1993 by Digital Equipment Corp.,
20Maynard, MA
21
22Permission to use, copy, modify, and distribute this software and its
23documentation for any purpose and without fee is hereby granted,
24provided that the above copyright notice appear in all copies and that
25both that copyright notice and this permission notice appear in
26supporting documentation, and that the name of Digital not be
27used in advertising or publicity pertaining to distribution of the
28software without specific, written prior permission.
29
30DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
31ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
32DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
33ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
34WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
35ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
36SOFTWARE.
37
38*****************************************************************************/
39/*
40 *
41 *  CONTRIBUTORS:
42 *
43 *      Dick Annicchiarico
44 *      Robert Chesler
45 *      Dan Coutu
46 *      Gene Durso
47 *      Marc Evans
48 *      Alan Jamison
49 *      Mark Henry
50 *      Ken Miller
51 *
52 */
53#include <stdio.h>
54#include <stdlib.h>
55#include <X11/extensions/xtraplib.h>
56#include <X11/extensions/xtraplibp.h>
57#include <ctype.h>
58
59int
60main(int argc, char *argv[])
61{
62    XETrapGetAvailRep     ret_avail;
63    XETrapGetStatsRep     ret_stats;
64    Widget  appW;
65    XtAppContext app;
66    char *tmp = NULL;
67    XETC    *tc;
68    Display *dpy;
69    Bool done;
70    char    buffer[10];
71    ReqFlags   requests;
72    EventFlags events;
73    int i;
74
75    /* Connect to Server */
76    appW = XtAppInitialize(&app,"XTrap",NULL,(Cardinal)0L,
77        (int *)&argc, (String *)argv, (String *)NULL,(ArgList)&tmp,
78        (Cardinal)NULL);
79    dpy = XtDisplay(appW);
80#ifdef DEBUG
81    XSynchronize(dpy, True);
82#endif
83    printf("Display:  %s \n", DisplayString(dpy));
84    if ((tc = XECreateTC(dpy,0L, NULL)) == False)
85    {
86        fprintf(stderr,"%s: could not initialize extension\n",argv[0]);
87        exit(1L);
88    }
89
90    (void)XEGetAvailableRequest(tc,&ret_avail);
91    if (BitIsFalse(ret_avail.valid, XETrapStatistics))
92    {
93        printf("\nStatistics not available from '%s'.\n",
94            DisplayString(dpy));
95        exit(1L);
96    }
97    XETrapSetStatistics(tc, True);
98    for (i=0; i<256L; i++)
99    {
100        BitTrue(requests, i);
101    }
102    XETrapSetRequests(tc, True, requests);
103    for (i=KeyPress; i<=MotionNotify; i++)
104    {
105        BitTrue(events, i);
106    }
107    XETrapSetEvents(tc, True, events);
108    done = False;
109    while(done == False)
110    {
111        fprintf(stderr,"Stats Command (Zero, Quit, [Show])? ");
112        fgets(buffer, sizeof(buffer), stdin);
113        switch(toupper(buffer[0]))
114        {
115            case '\n':  /* Default command */
116            case 'S':   /* Request fresh counters & display */
117                (void)XEGetStatisticsRequest(tc,&ret_stats);
118                (void)XEPrintStatistics(stdout,&ret_stats,tc);
119                break;
120            case 'Z':  /* Zero out counters */
121                XETrapSetStatistics(tc, False);
122                break;
123            case 'Q':
124                done = True;
125                break;
126            default:
127                printf("Invalid command, reenter!\n");
128                break;
129        }
130    }
131    (void)XEFreeTC(tc);
132    (void)XCloseDisplay(dpy);
133    exit(0L);
134}
135