1876ff6feSmrg/* $XFree86: xc/programs/xtrap/xtrapstats.c,v 1.1tsi Exp $ */ 2876ff6feSmrg/* 3876ff6feSmrg * @DEC_COPYRIGHT@ 4876ff6feSmrg */ 5876ff6feSmrg/* 6876ff6feSmrg * HISTORY 7876ff6feSmrg * Log: xtrapstats.c,v $ 8876ff6feSmrg * Revision 1.1.4.2 1993/12/14 12:37:41 Kenneth_Miller 9876ff6feSmrg * ANSI-standardize code and turn client build on 10876ff6feSmrg * [1993/12/09 20:16:19 Kenneth_Miller] 11876ff6feSmrg * 12876ff6feSmrg * Revision 1.1.2.2 1992/04/27 13:52:12 Leela_Obilichetti 13876ff6feSmrg * initial load of xtrap clients - from silver BL6 pool 14876ff6feSmrg * [92/04/27 13:49:48 Leela_Obilichetti] 15876ff6feSmrg * 16876ff6feSmrg * EndLog$ 17876ff6feSmrg */ 18876ff6feSmrg/***************************************************************************** 19876ff6feSmrgCopyright 1987, 1988, 1989, 1990, 1991, 1992, 1993 by Digital Equipment Corp., 20876ff6feSmrgMaynard, MA 21876ff6feSmrg 22876ff6feSmrgPermission to use, copy, modify, and distribute this software and its 23876ff6feSmrgdocumentation for any purpose and without fee is hereby granted, 24876ff6feSmrgprovided that the above copyright notice appear in all copies and that 25876ff6feSmrgboth that copyright notice and this permission notice appear in 26876ff6feSmrgsupporting documentation, and that the name of Digital not be 27876ff6feSmrgused in advertising or publicity pertaining to distribution of the 28876ff6feSmrgsoftware without specific, written prior permission. 29876ff6feSmrg 30876ff6feSmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 31876ff6feSmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 32876ff6feSmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 33876ff6feSmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 34876ff6feSmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 35876ff6feSmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 36876ff6feSmrgSOFTWARE. 37876ff6feSmrg 38876ff6feSmrg*****************************************************************************/ 39876ff6feSmrg/* 40876ff6feSmrg * 41876ff6feSmrg * CONTRIBUTORS: 42876ff6feSmrg * 43876ff6feSmrg * Dick Annicchiarico 44876ff6feSmrg * Robert Chesler 45876ff6feSmrg * Dan Coutu 46876ff6feSmrg * Gene Durso 47876ff6feSmrg * Marc Evans 48876ff6feSmrg * Alan Jamison 49876ff6feSmrg * Mark Henry 50876ff6feSmrg * Ken Miller 51876ff6feSmrg * 52876ff6feSmrg */ 53876ff6feSmrg#include <stdio.h> 54876ff6feSmrg#include <stdlib.h> 55876ff6feSmrg#include <X11/extensions/xtraplib.h> 56876ff6feSmrg#include <X11/extensions/xtraplibp.h> 57876ff6feSmrg#include <ctype.h> 58876ff6feSmrg 59876ff6feSmrgint 60876ff6feSmrgmain(int argc, char *argv[]) 61876ff6feSmrg{ 62876ff6feSmrg XETrapGetAvailRep ret_avail; 63876ff6feSmrg XETrapGetStatsRep ret_stats; 64876ff6feSmrg Widget appW; 65876ff6feSmrg XtAppContext app; 66876ff6feSmrg char *tmp = NULL; 67876ff6feSmrg XETC *tc; 68876ff6feSmrg Display *dpy; 69876ff6feSmrg Bool done; 70876ff6feSmrg char buffer[10]; 71876ff6feSmrg ReqFlags requests; 72876ff6feSmrg EventFlags events; 73876ff6feSmrg int i; 74876ff6feSmrg 75876ff6feSmrg /* Connect to Server */ 76876ff6feSmrg appW = XtAppInitialize(&app,"XTrap",NULL,(Cardinal)0L, 77876ff6feSmrg (int *)&argc, (String *)argv, (String *)NULL,(ArgList)&tmp, 7899435119Smrg 0); 79876ff6feSmrg dpy = XtDisplay(appW); 80876ff6feSmrg#ifdef DEBUG 81876ff6feSmrg XSynchronize(dpy, True); 82876ff6feSmrg#endif 83876ff6feSmrg printf("Display: %s \n", DisplayString(dpy)); 8499435119Smrg if ((tc = XECreateTC(dpy,0L, NULL)) == NULL) 85876ff6feSmrg { 86876ff6feSmrg fprintf(stderr,"%s: could not initialize extension\n",argv[0]); 87876ff6feSmrg exit(1L); 88876ff6feSmrg } 89876ff6feSmrg 90876ff6feSmrg (void)XEGetAvailableRequest(tc,&ret_avail); 91876ff6feSmrg if (BitIsFalse(ret_avail.valid, XETrapStatistics)) 92876ff6feSmrg { 93876ff6feSmrg printf("\nStatistics not available from '%s'.\n", 94876ff6feSmrg DisplayString(dpy)); 95876ff6feSmrg exit(1L); 96876ff6feSmrg } 97876ff6feSmrg XETrapSetStatistics(tc, True); 98876ff6feSmrg for (i=0; i<256L; i++) 99876ff6feSmrg { 100876ff6feSmrg BitTrue(requests, i); 101876ff6feSmrg } 102876ff6feSmrg XETrapSetRequests(tc, True, requests); 103876ff6feSmrg for (i=KeyPress; i<=MotionNotify; i++) 104876ff6feSmrg { 105876ff6feSmrg BitTrue(events, i); 106876ff6feSmrg } 107876ff6feSmrg XETrapSetEvents(tc, True, events); 108876ff6feSmrg done = False; 109876ff6feSmrg while(done == False) 110876ff6feSmrg { 111876ff6feSmrg fprintf(stderr,"Stats Command (Zero, Quit, [Show])? "); 112876ff6feSmrg fgets(buffer, sizeof(buffer), stdin); 113876ff6feSmrg switch(toupper(buffer[0])) 114876ff6feSmrg { 115876ff6feSmrg case '\n': /* Default command */ 116876ff6feSmrg case 'S': /* Request fresh counters & display */ 117876ff6feSmrg (void)XEGetStatisticsRequest(tc,&ret_stats); 118876ff6feSmrg (void)XEPrintStatistics(stdout,&ret_stats,tc); 119876ff6feSmrg break; 120876ff6feSmrg case 'Z': /* Zero out counters */ 121876ff6feSmrg XETrapSetStatistics(tc, False); 122876ff6feSmrg break; 123876ff6feSmrg case 'Q': 124876ff6feSmrg done = True; 125876ff6feSmrg break; 126876ff6feSmrg default: 127876ff6feSmrg printf("Invalid command, reenter!\n"); 128876ff6feSmrg break; 129876ff6feSmrg } 130876ff6feSmrg } 131876ff6feSmrg (void)XEFreeTC(tc); 132876ff6feSmrg (void)XCloseDisplay(dpy); 133876ff6feSmrg exit(0L); 134876ff6feSmrg} 135