itpmon - a program to watch itp status

Warren Tucker wht at tridom.uucp
Tue Jun 27 02:01:53 AEST 1989


No, this isn't alt.sources.  But since it's for pyramid only:

Here is a program to watch itp status.  I don't know what
hardware it will work on, but it works well on our 90/X under 4.4
and has helped to track down a few tedious problems we've had with
noisy EIA lines.  The program makes > 10 characters in the rawq
stand out.  This can almost always (in our shop, anyway) be linked
to lines that are interrupting at a high rate, though programs
putting a line in raw mode will cause rawq to light up at times too.

It's an expensive cpu user; a feature to nice it a bit is in
there since when we've needed to use it, the system was being
swamped with 20 or 40 itp interrupts a second!  Lighted rawq
numbers lead to the faulty line evry time.

Hope it's of use -- it is at least interesting to watch.

#!/bin/sh
# shar:	Shell Archiver  (v1.22)
#
#	Run the following text with /bin/sh to create:
#	  itpmon.c
#
sed 's/^X//' << 'SHAR_EOF' > itpmon.c &&
X/* CHK=0x3454 */
X/*+-------------------------------------------------------------------------
X	itpmon.c -- watch 90/x itps
X	...!gatech!emory!tridom!wht
X
Xcc -O -s itpmon.c -o itpmon -lcurses -ltermcap
X/etc/chown root itpmon
Xchmod u+s itpmon
X
X0000000000111111111122222222223333333333
X0123456789012345678901234567890123456789
X tty  raw  can   out   speed  flags
X ##   ###  ###  #####  #####   OCB
X
X	int	t_state;		flags
XTS_ISOPEN	0x000004	device is open
XTS_CARR_ON	0x000010	software copy of carrier-present
XTS_BUSY		0x000020	output in progress
X--------------------------------------------------------------------------*/
X/*+:EDITS:*/
X/*:02-18-1989-17:00-wht-update for pyr OSx 4.4 */
X/*:10-20-1988-14:43-wht-creation */
X
X#include <stdio.h>
X#include <signal.h>
X#include <nlist.h>
X#include <sys/types.h>
X
X#include <curses.h>
X#include <sys/tty.h>
X#include <sys/time.h>
X
X#define HY 2	/* header line */
X#define TX 1
X#define RX 6
X#define CX 11
X#define OX 16
X#define SX 23
X#define FX 30
X
Xchar	*vmunix_file = "/vmunix";
Xchar	*kmem_file = "/dev/kmem";
X
Xint		kmemfd;
X
Xstruct nlist nlst[] = {
X	{ "_itp_tty" },
X#define N_ITP_TTY	0
X	{ 0 }
X};
X
Xlong	itp_tty;
X
X#define TTQUAN	32
Xstruct tty ttt[TTQUAN];
X
Xtypedef struct b_to_br
X{
X	unsigned	baud_rate;
X	int			B_code;
X} B_TO_BR;
X
XB_TO_BR speeds[] = 
X{
X	110,	B110,
X	300,	B300,
X	1200,	B1200,
X	2400,	B2400,
X	4800,	B4800,
X	9600,	B9600,
X	19200,	EXTA,
X	38400,	EXTB,
X	0,
X};
X
Xstruct tchars tchars;
Xstruct sgttyb oldsgttyb;
Xstruct sgttyb newsgttyb;
Xint		delay = 4;
X
X/*+-------------------------------------------------------------------------
X	B_to_baud_rate(code)
X--------------------------------------------------------------------------*/
Xunsigned int
XB_to_baud_rate(code)
X{
Xregister int n;
X
X	for (n=0; speeds[n].baud_rate; n++)
X		if (speeds[n].B_code == code)
X			return(speeds[n].baud_rate);
X	return(0);
X}	/* end of B_to_baud_rate */
X
X/*+-------------------------------------------------------------------------
X	kmem_read(pos,buf,len)
X--------------------------------------------------------------------------*/
Xvoid
Xkmem_read(pos,buf,len)
Xlong	pos;
Xint		*buf;
Xint		len;
X{
X	if (lseek(kmemfd,pos,0) == -1)
X	{
X		perror("kmem lseek failure");
X		exit(3);
X	}
X	if (read(kmemfd,buf,len) == -1)
X	{
X		perror("kmem read failure");
X		exit(3);
X	}
X}	/* end of kmem_read */
X
X/*+-------------------------------------------------------------------------
X	disp_tty(ttnum,ttt)
X--------------------------------------------------------------------------*/
Xdisp_tty(ttnum,ttt)
Xint		ttnum;
Xregister struct tty *ttt;
X{
Xregister int xo = (ttnum > 15) ? 40 : 0;	/* x offset */
Xregister int y  = HY + 2 + (ttnum & 15);
Xregister unsigned int itmp;
Xchar	s8[8];
X
X	sprintf(s8,"%02u",ttnum);
X	move(y,TX + xo);
X	addstr(s8);
X
X	if((itmp = (unsigned)ttt->t_rawq.c_cc) > 999)
X		itmp = 999;
X	sprintf(s8,"%3u",itmp);
X	move(y,RX + xo);
X	if(itmp > 10)
X		standout();
X	addstr(s8);
X	if(itmp > 10)
X		standend();
X
X	if((itmp = (unsigned)ttt->t_canq.c_cc) > 999)
X		itmp = 999;
X	sprintf(s8,"%3u",itmp);
X	move(y,CX + xo);
X	addstr(s8);
X
X	if((itmp = (unsigned)ttt->t_outq.c_cc) > 99999)
X		itmp = 99999;
X	sprintf(s8,"%5u",itmp);
X	move(y,OX + xo);
X	addstr(s8);
X
X	sprintf(s8,"%5u",B_to_baud_rate(ttt->t_ospeed & 0xF));
X	move(y,SX + xo);
X	addstr(s8);
X
X	strcpy(s8,"     ");
X	if(ttt->t_state & TS_ISOPEN)
X		s8[1] = 'O';
X	if(ttt->t_state & TS_CARR_ON)
X		s8[2] = 'C';
X	if(ttt->t_state & TS_BUSY)
X		s8[3] = 'B';
X	move(y,FX + xo);
X	addstr(s8);
X
X}	/* end of disp_tty */
X
X/*+-------------------------------------------------------------------------
X	disp_nice()
X--------------------------------------------------------------------------*/
Xvoid
Xdisp_nice()
X{
Xchar nmsg[10];
X
X	sprintf(nmsg,"nice:%3d",getpriority(0,getpid()));
X	move(0,35);
X	addstr(nmsg);
X}	/* end of disp_nice */
X
X/*+-------------------------------------------------------------------------
X	disp_delay()
X--------------------------------------------------------------------------*/
Xvoid
Xdisp_delay()
X{
Xchar dmsg[12];
X
X	sprintf(dmsg,"delay: %2d",delay);
X	move(0,50);
X	addstr(dmsg);
X}	/* end of disp_delay */
X
X/*+-------------------------------------------------------------------------
X	disp_tod()
X--------------------------------------------------------------------------*/
Xdisp_tod()
X{
Xregister struct tm *lt;		/* local time */
Xstruct tm *localtime();
Xlong now;
Xchar buf[10];
X
X	time(&now);
X	lt = localtime(&now);
X	sprintf(buf,"%02d:%02d:%02d",lt->tm_hour,lt->tm_min,lt->tm_sec);
X	move(0,COLS - 13);
X	addstr(buf);
X}	/* end of disp_tod */
X
X/*+-----------------------------------------------------------------------
X	make_char_graphic(character) - Make all chars "printable"
X
X  returns pointer to a static string containing printable version
X  of a character.
X------------------------------------------------------------------------*/
Xchar *
Xmake_char_graphic(ch)
Xregister char	ch;
X{
Xstatic char gg[4];
X
X	ch &= 0x7F;
X	if((ch >= 0x20) && (ch < 0x7F))
X	{
X		gg[0] = ch; gg[1] = 0;
X	}
X	else if(ch == 0x7F)
X		strcpy(gg,"DEL");
X	else
X	{
X		gg[0] = '^'; 
X		gg[1] = ch + 0x40;
X		gg[2] = 0;
X	}
X	return(gg);
X}	/* end of make_char_graphic */
X
X/*+-------------------------------------------------------------------------
X	draw_template()
X--------------------------------------------------------------------------*/
Xvoid
Xdraw_template()
X{
Xstatic char *header  = " tty  raw  can   out   speed  flags";
Xstatic char *hyphens = " ---  ---  ---  -----  -----  -----";
X	clear();
X	move(0,0);
X	standout();
X	addstr(" itpmon 4.4 ");
X	standend();
X	move(HY,0);
X	addstr(header);
X	move(HY,40);
X	addstr(header);
X	move(HY + 1,0);
X	addstr(hyphens);
X	move(HY + 1,40);
X	addstr(hyphens);
X	move(LINES - 3,0);
X	addstr("Flags: O open  C carrier on  B busy (output active)");
X	move(LINES - 2,0);
X	addstr(
X"Commands:  + inc delay  - dec delay  ^L refresh  < nice -5  0 nice 0  q quit");
X	disp_nice();
X	disp_delay();
X	refresh();
X}	/* end of draw_template */
X
X/*+-------------------------------------------------------------------------
X	leave()
X--------------------------------------------------------------------------*/
Xvoid
Xleave()
X{
X	refresh();
X	fflush(stderr);
X	move(LINES - 1,0);
X	refresh();
X	ioctl(0,TIOCSETP,&oldsgttyb);
X	endwin();
X	exit(0);
X}	/* end of leave */
X
X/*+-------------------------------------------------------------------------
X	main(argc,argv,envp)
X--------------------------------------------------------------------------*/
Xmain(argc,argv,envp)
Xint		argc;
Xchar	**argv;
Xchar	**envp;
X{
Xregister struct nlist *nn = nlst;
Xregister int ttnum;
Xstruct timeval timeout;
Xint		readfds;
X
X	if ((kmemfd = open(kmem_file,0)) < 0)
X	{
X		perror(kmem_file);
X		exit(2);
X	}
X
X	nlist(vmunix_file,nlst);
X	if(nlst[0].n_type == 0)
X	{
X		fprintf(stderr,"nlist failure: %s\n",vmunix_file);
X		exit(2);
X	}
X
X	kmem_read(nlst[N_ITP_TTY].n_value,&itp_tty,sizeof(itp_tty),
X		nlst[N_ITP_TTY].n_name);
X
X	signal(SIGINT,leave);
X	signal(SIGTERM,leave);
X
X	ioctl(0,TIOCGETC,&tchars);
X
X	initscr();
X	if(ioctl(0,TIOCGETP,&oldsgttyb))
X	{
X		perror("terminal ioctl");
X		exit(2);
X	}
X	newsgttyb = oldsgttyb;
X	newsgttyb.sg_flags |= CBREAK;
X	newsgttyb.sg_flags &= ~(ECHO|XTABS);
X	ioctl(0,TIOCSETP,&newsgttyb);
X
XREFRESH:
X	draw_template();
X
X	while(1)
X	{
X		kmem_read(itp_tty,ttt,sizeof(ttt),"tty struct");
X		for(ttnum = 0; ttnum < TTQUAN; ttnum++)
X		{
X			disp_tty(ttnum,&ttt[ttnum]);
X		}
X		disp_tod();
X		move(LINES - 1,0);
X		refresh();
X		readfds = 1;			/* for standard input */
X		timeout.tv_sec  = delay;
X		timeout.tv_usec = 0;
X		if(select(32,&readfds,0,0,&timeout) > 0)
X		{
X		char	ch;
X			read(0,&ch,1);
X			switch(ch & 0x7F)
X			{
X			case 'L' & 0x1F:		/* redraw screen */
X			case 'R' & 0x1F:		/* redraw screen */
X				goto REFRESH;
X
X			case '+':
X				delay++;
X				disp_delay();
X				break;
X
X			case '-':
X				if(delay <= 2)
X					break;
X				delay--;
X				disp_delay();
X				break;
X
X			case '<':
X				setpriority(0,getpid(),-5);
X				disp_nice();
X				break;
X
X			case '0':
X				setpriority(0,getpid(),0);
X				disp_nice();
X				break;
X
X			case 'q':		/* quit */
X				leave(0);
X				break;
X			}
X		}
X	}
X}	/* end of main */
X
X/* vi: set tabstop=4 shiftwidth=4: */
X/* end of itpmon.c */
SHAR_EOF
chmod 0644 itpmon.c || echo "restore of itpmon.c fails"
exit 0
-- 
-------------------------------------------------------------------
Warren Tucker, Tridom Corporation       ...!gatech!emory!tridom!wht 
Sforzando (It., sfohr-tsahn'-doh).  A direction to perform the tone
or chord with special stress, or marked and sudden emphasis.



More information about the Comp.sys.pyramid mailing list