Monitor source part 5 of 9
jct
jct at jct.UUCP
Tue Jul 11 14:27:08 AEST 1989
#! /bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of archive 5 (of 9)."
# Contents: lib/scrops1.c monitor2.c
# Wrapped by jct@ on Mon Jul 10 22:48:22 1989
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'lib/scrops1.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'lib/scrops1.c'\"
else
echo shar: Extracting \"'lib/scrops1.c'\" \(17878 characters\)
sed "s/^X//" >'lib/scrops1.c' <<'END_OF_FILE'
X/* Module screen operations */
X
X/*
X Preforms various functions for menu driven for screen oriented programs
X*/
X
X/*
X Created February 1, 1986 by JCT
X*/
X
X/*
X * Copyright (c) John C. Tompkins 1989
X * All rights reserved.
X *
X * Permission is granted to use this for any personal, noncommercial use.
X * You may not distribute source or executable code for profit, nor
X * may you distribute it with a commercial product without the prior
X * written consent of the author. Please send modifications to the
X * author for inclusion in updates to the program.
X */
X
X#include <stdio.h>
X#include <ctype.h>
X#include <string.h>
X
X#include <km/defs.h>
X#include <km/ascii.h>
X#include <km/scrio.h>
X#include <km/scrops.h>
X#include <km/string1.h>
X#include <km/string2.h>
X#include <km/docmd.h>
X
X#define SCR_TBL_SIZE 20
X
X/* declare user defined data */
X
int scr_quit = FALSE, scr_main = FALSE, scr_backup = FALSE;
int scr_level = -1, menu_column;
int msg_line, msg_column;
X
static int to_level, want_level;
static int entry_number;
static SCR *scr_tbl[SCR_TBL_SIZE];
X
X/* declare external UNIX functions */
X
extern long time();
extern unsigned alarm();
extern void longjmp();
extern int isatty();
extern void exit();
extern int atoi();
X
int setup()
X{
X
X/*
X first function called for entry to all screen oriented programs
X*/
X
X static int setup_done = FALSE;
X
X if (initscr() == WIN_NULL)
X exit(1);
X if (!setup_done)
X {
X if (streq(ttytype, "dumb", TRUE))
X {
X printf("terminal type %s can't do screen operations\n", ttytype);
X endwin();
X exit(2);
X }
X if (COLS < 100)
X menu_column = 10;
X else
X menu_column = 20;
X msg_column = menu_column;
X setup_done = TRUE;
X }
X return(TRUE);
X}
X
int setdown()
X{
X
X/*
X Last function called for exit from screen oriented modes
X*/
X
X endwin();
X return(TRUE);
X}
X
int wcenter(win, message)
X WINDOW *win;
X char *message;
X{
X return(((win->x_max - strlen(message)) / 2) - 1);
X}
X
int wput_str(win, line, column, message, highlight)
X WINDOW *win;
X int line;
X int column;
X char *message;
X int highlight;
X{
X int stat;
X
X wmove(win, line, column);
X if (highlight)
X wstandout(win);
X stat = waddstr(win, message);
X if (highlight)
X wstandend(win);
X return(stat);
X}
X
X#ifdef XEXIX86
int wput_fstr(win, line, column, message, highlight)
X WINDOW *win;
X int line;
X int column;
X char far *message;
X int highlight;
X{
X
X/*
X puts a string from a 'far' segment, typically a shared memory segment
X only for 8086 types and small or medium models
X*/
X
X int stat = TRUE;
X
X wmove(win, line, column);
X if (highlight)
X wstandout(win);
X while (*message && stat)
X stat = waddch(win, *message++);
X if (highlight)
X wstandend(win);
X return(stat);
X}
X#endif
X
int wput_msg(win, message)
X WINDOW *win;
X char *message;
X{
X return(wput_str(win, msg_line, msg_column, message, FALSE));
X}
X
int wput_int(win, line, column, number, places, highlight)
X WINDOW *win;
X int line;
X int column;
X int number;
X int places;
X int highlight;
X{
X char nstr[20];
X
X return(wput_str(win, line, column, strint(nstr, number, places, ' '), highlight));
X}
X
int wput_time(win, line, column, when, format, highlight)
X WINDOW *win;
X int line;
X int column;
X long when;
X int format;
X int highlight;
X{
X char tstr[20];
X
X return(wput_str(win, line, column, strtime(tstr, when, format), highlight));
X}
X
int wput_date(win, line, column, when, format, highlight)
X WINDOW *win;
X int line;
X int column;
X long when;
X int format;
X int highlight;
X{
X char dstr[40];
X
X return(wput_str(win, line, column, strdate(dstr, when, format), highlight));
X}
X
int wput_when(win, line, column, when, format, highlight)
X WINDOW *win;
X int line;
X int column;
X long when;
X int format;
X int highlight;
X{
X char wstr[80], *sptr;
X
X if (format & DATE_FIRST)
X {
X strdate(wstr, when, format);
X sptr = strend(wstr);
X *sptr++ = ' ';
X strtime(sptr, when, format);
X }
X else
X {
X strtime(wstr, when, format);
X sptr = strend(wstr);
X *sptr++ = ' ';
X strdate(sptr, when, format);
X }
X return(wput_str(win, line, column, wstr, highlight));
X}
X
int wput_head(win, head)
X WINDOW *win;
X char *head;
X{
X int y;
X
X if (head)
X {
X y = ((win->flags & BOX_FLAG) ? 1 : 0);
X return(wput_str(win, y, wcenter(win, head), head, TRUE));
X }
X return(FALSE);
X}
X
int wput_prompt(win, message)
X WINDOW *win;
X char *message;
X{
X int stat, y, x;
X
X if (message)
X {
X y = ((win->flags & BOX_FLAG) ? (win->y_max - 2) : (win->y_max - 1));
X x = ((win->flags & BOX_FLAG) ? 1 : 0);
X wmove(win, y, x);
X wclrtoeol(win);
X wstandout(win);
X stat = waddstr(win, message);
X wstandend(win);
X return(stat);
X }
X return(FALSE);
X}
X
int put_entry(scr, entry, highlight)
X SCR *scr;
X SCR_ENTRY *entry;
X int highlight;
X{
X int temp, y, x;
X WINDOW *win;
X
X if (entry && islower(entry->key))
X {
X if ((win = scr->win) == WIN_NULL)
X win = stdscr;
X if (scr->flags & SCR_MPOPUP)
X {
X y = ((win->flags & BOX_FLAG) ? 2 : 1) + tolower(entry->key) - 'a';
X x = ((win->flags & BOX_FLAG) ? 1 : 0);
X }
X else
X {
X y = INIT_LINE + tolower(entry->key) - 'a';
X if ((y + 2) > msg_line)
X msg_line = y + 2;
X x = menu_column;
X }
X wmove(win, y, x);
X if (highlight)
X wstandout(win);
X if (highlight && !have_standout)
X addch('[');
X else
X waddch(win, ' ');
X if (scr->flags & SCR_NUMERIC)
X {
X temp = toupper(entry->key) - 'A' + 1;
X wprintw(win, "%-2d : %s", temp, entry->text);
X }
X else
X {
X waddch(win, toupper(entry->key));
X waddstr(win, " : ");
X waddstr(win, entry->text);
X }
X if (highlight && !have_standout)
X waddch(win, ']');
X else
X waddch(win, ' ');
X if (highlight)
X wstandend(win);
X return(TRUE);
X }
X return(FALSE);
X}
X
int set_scr(scr)
X REGISTER SCR *scr;
X{
X int temp;
X
X/*
X set the scr level in case of parallel screens
X also reset scr variables
X*/
X
X if (scr)
X {
X if (!scr->win)
X scr->win = stdscr;
X to_level = FALSE;
X for (temp = scr_level; temp >= 0; temp--)
X {
X if (scr_tbl[temp] == scr)
X {
X to_level = TRUE;
X want_level = temp;
X break;
X }
X }
X scr_tbl[++scr_level] = scr;
X if (!(scr->flags & SCR_NO_INI))
X {
X scr->active_entry = (SCR_ENTRY*)0;
X scr->last_active = (SCR_ENTRY*)0;
X scr->lflags = 0;
X }
X return(TRUE);
X }
X return(FALSE);
X}
X
int set_keys(scr)
X REGISTER SCR *scr;
X{
X int menu_char = 'a';
X REGISTER SCR_ENTRY *entry;
X
X/*
X set the menu selection keys if not already specified
X*/
X
X if (scr)
X {
X if ((entry = scr->entry) != (SCR_ENTRY*)NULL)
X {
X while (entry->key != UNDETERMINED)
X {
X if (!islower(entry->key) &&
X !((entry->key >= 0x01) && (entry->key <= 0x1f)))
X entry->key = menu_char++;
X entry++;
X }
X }
X scr->lflags |= SCR_SETKEYS;
X return(TRUE);
X }
X return(FALSE);
X}
X
int put_scr(scr)
X REGISTER SCR *scr;
X{
X
X/*
X display the standard screen fields
X*/
X
X REGISTER SCR_ENTRY *entry;
X WINDOW *win;
X
X if (scr)
X {
X msg_line = 2;
X if ((win = scr->win) == WIN_NULL)
X win = stdscr;
X if ((scr->flags & SCR_MENU) && !(scr->flags & SCR_NO_ERASE))
X werase(win);
X wput_head(win, scr->head);
X if (scr->flags & SCR_MENU)
X {
X if ((entry = scr->entry) != (SCR_ENTRY*)NULL)
X {
X while (entry->key != UNDETERMINED)
X {
X put_entry(scr, entry, (scr->active_entry == entry));
X entry++;
X }
X }
X }
X if (!(scr->flags & SCR_NO_PROMPT))
X {
X if (scr->prompt)
X wput_prompt(win, scr->prompt);
X else
X {
X if (scr_level > 0)
X wput_prompt(win, " (Q)uit, (T)op, <SPACE> to backup or selection ");
X else
X wput_prompt(win, " (Q)uit or selection ");
X }
X }
X scr->lflags |= SCR_UP;
X return(TRUE);
X }
X return(FALSE);
X}
X
int do_active_entry(scr)
X REGISTER SCR *scr;
X{
X REGISTER SCR_ENTRY *entry;
X WINDOW *win;
X
X if (scr && scr->active_entry)
X {
X if ((win = scr->win) == WIN_NULL)
X win = stdscr;
X entry = scr->active_entry;
X if ((scr->flags & SCR_MENU) &&
X ((entry->flags & SCR_PUT_ACTIVE) || (entry->flags & SCR_PICK)))
X {
X if (!(scr->lflags & SCR_UP))
X put_scr(scr);
X else
X {
X if (scr->last_active)
X put_entry(scr, scr->last_active, FALSE);
X put_entry(scr, entry, TRUE);
X }
X wrefresh(win);
X }
X scr->last_active = entry;
X if (entry->flags & SCR_NPARM)
X {
X if (entry->flags & SCR_PPARM)
X return((*entry->func)(entry->number, entry->pointer));
X else
X return((*entry->func)(entry->number));
X }
X else if (entry->flags & SCR_PPARM)
X return((*entry->func)(entry->pointer));
X else
X return((*entry->func)());
X }
X else
X return(FALSE);
X}
X
int check_scr(scr, key)
X REGISTER SCR *scr;
X REGISTER int key;
X{
X
X/*
X check the key and list passed and process accordingly
X*/
X
X if (scr)
X {
X if (scr->func_chk)
X return((*scr->func_chk)(scr, key));
X else
X {
X if ((scr->active_entry = scr->entry) != (SCR_ENTRY*)NULL)
X {
X while (scr->active_entry->key != UNDETERMINED)
X {
X if (scr->active_entry->key == key)
X return(do_active_entry(scr));
X else
X (scr->active_entry)++;
X }
X scr->active_entry = scr->last_active;
X }
X else
X return(FALSE);
X }
X }
X return(FALSE);
X}
X
int do_scr(scr)
X REGISTER SCR *scr;
X{
X
X/*
X processes the screen structure passed to it
X*/
X
X int temp, y, x, save_ml, save_mc;
X WINDOW *win;
X
X if (scr)
X {
X set_scr(scr);
X win = scr->win;
X y = win->y_max - 1;
X if (win->flags & BOX_FLAG)
X {
X y--;
X x = 1;
X }
X else
X x = 0;
X do
X {
X if (!scr_quit && !scr_main && !to_level)
X {
X scr->lflags &= ~SCR_UP;
X entry_number = 0;
X if (have_color && ((scr->flags & SCR_FORCE_COLOR) || !win->color))
X {
X if (scr->color)
X {
X win->color = scr->color;
X win->flags |= SET_COLOR;
X }
X else
X win->color = curscr->color;
X }
X if ((scr->flags & SCR_MENU) && (scr->flags & SCR_TYPE_AHEAD))
X scr->lflags &= ~SCR_DISPLAY;
X else
X scr->lflags |= SCR_DISPLAY;
X if (scr->func_entry)
X (*scr->func_entry)();
X if (!(scr->lflags & SCR_SETKEYS))
X set_keys(scr);
X do
X {
X if (scr->lflags & SCR_DISPLAY) /* no type ahead */
X {
X if (!(scr->lflags & SCR_UP))
X put_scr(scr);
X if (!(scr->flags & SCR_NO_PROMPT))
X wmove(win, y, x);
X if (!(scr->flags & SCR_NO_REFRESH))
X wrefresh(win);
X if (scr->timeout >= 0)
X temp = scr->timeout;
X else
X temp = UNDETERMINED;
X }
X else /* we're in type ahead */
X {
X/*
X if (scr->timeout >= 0)
X temp = scr->timeout;
X else
X*/
X temp = 2;
X }
X save_ml = msg_line;
X save_mc = msg_column;
X if (scr->func_loop)
X (*scr->func_loop)();
X temp = get_key(temp);
X scr->lflags &= ~SCR_HAVE_KEY;
X if ((scr->flags & SCR_RAW) && scr->func_chk)
X (*scr->func_chk)(scr, temp);
X else
X {
X temp = tolower(temp);
X switch (temp) /* process the key */
X {
X case UNDETERMINED :
X if (scr->func_chk)
X {
X if (check_scr(scr, temp))
X scr->lflags |= SCR_HAVE_KEY;
X else
X scr->lflags |= SCR_DISPLAY;
X }
X else
X scr->lflags |= SCR_DISPLAY;
X break;
X case 'q' :
X case K_QUIT :
X scr_quit = TRUE;
X scr->lflags |= SCR_HAVE_KEY;
X break;
X case 't' :
X case K_BEG_SCREEN :
X case K_BEG_BUF :
X case K_BEG_LINE :
X if (scr_level > 0)
X {
X scr_main = TRUE;
X scr->lflags |= SCR_HAVE_KEY;
X }
X break;
X case ' ' :
X case K_BACKUP :
X case K_BWD_SCREEN :
X case K_BWD_WORD :
X if (scr_level > 0)
X {
X scr_backup = TRUE;
X scr->lflags |= SCR_HAVE_KEY;
X }
X break;
X case LF :
X if (scr->flags & SCR_MENU)
X {
X if ((scr->flags & SCR_NUMERIC) && (entry_number > 0))
X {
X if (check_scr(scr, (entry_number + 'a' - 1)))
X scr->lflags |= SCR_HAVE_KEY;
X else
X scr->lflags |= SCR_DISPLAY;
X entry_number = 0;
X }
X else if (do_active_entry(scr))
X scr->lflags |= SCR_HAVE_KEY;
X else
X scr->lflags |= SCR_DISPLAY;
X }
X else
X {
X if (check_scr(scr, temp))
X scr->lflags |= SCR_HAVE_KEY;
X }
X break;
X case CR :
X if (scr->flags & SCR_MENU)
X {
X if ((scr->flags & SCR_NUMERIC) && (entry_number > 0))
X {
X if (check_scr(scr, (entry_number + 'a' - 1)))
X scr->lflags |= SCR_HAVE_KEY;
X else
X scr->lflags |= SCR_DISPLAY;
X entry_number = 0;
X }
X else if (do_active_entry(scr))
X scr->lflags |= SCR_HAVE_KEY;
X else
X scr->lflags |= SCR_DISPLAY;
X }
X else
X {
X if (check_scr(scr, temp))
X scr->lflags |= SCR_HAVE_KEY;
X }
X break;
X case K_UP :
X if (scr->flags & SCR_MENU)
X {
X if (!scr->active_entry)
X {
X if ((scr->active_entry = scr->entry) != (SCR_ENTRY*)NULL)
X {
X temp = 0;
X while (scr->active_entry->key != UNDETERMINED)
X {
X if ((scr->active_entry->key > temp) &&
X (islower(scr->active_entry->key)))
X temp = scr->active_entry->key;
X (scr->active_entry)++;
X }
X }
X }
X else
X {
X temp = scr->active_entry->key - 1;
X put_entry(scr, scr->active_entry, FALSE);
X }
X if ((scr->active_entry = scr->entry) != (SCR_ENTRY*)NULL)
X {
X while ((scr->active_entry->key != UNDETERMINED) &&
X (scr->active_entry->key != temp))
X (scr->active_entry)++;
X if (scr->active_entry->key != UNDETERMINED)
X put_entry(scr, scr->active_entry, TRUE);
X else
X scr->active_entry = (SCR_ENTRY*)0;
X }
X entry_number = 0;
X scr->last_active = scr->active_entry;
X }
X else
X {
X if (check_scr(scr, temp))
X scr->lflags |= SCR_HAVE_KEY;
X }
X break;
X case K_DOWN :
X if (scr->flags & SCR_MENU)
X {
X if (!scr->active_entry)
X temp = 'a';
X else
X {
X temp = scr->active_entry->key + 1;
X put_entry(scr, scr->active_entry, FALSE);
X }
X if ((scr->active_entry = scr->entry) != (SCR_ENTRY*)NULL)
X {
X while ((scr->active_entry->key != UNDETERMINED) &&
X (scr->active_entry->key != temp))
X (scr->active_entry)++;
X if (scr->active_entry->key != UNDETERMINED)
X put_entry(scr, scr->active_entry, TRUE);
X else
X scr->active_entry = (SCR_ENTRY*)0;
X }
X entry_number = 0;
X scr->last_active = scr->active_entry;
X }
X else
X {
X if (check_scr(scr, temp))
X scr->lflags |= SCR_HAVE_KEY;
X }
X break;
X case K_HELP :
X case K_F0 :
X case '?' :
X if (!(scr->flags & SCR_NO_HELP))
X sdo_help(scr);
X break;
X case '0' :
X case '1' :
X case '2' :
X case '3' :
X case '4' :
X case '5' :
X case '6' :
X case '7' :
X case '8' :
X case '9' :
X if ((scr->flags & SCR_MENU) && (scr->flags & SCR_NUMERIC))
X {
X entry_number = (entry_number * 10) + temp - '0';
X if (entry_number > 99)
X entry_number = 0;
X }
X else
X scr->lflags |= SCR_DISPLAY;
X break;
X default :
X if (!((scr->flags & SCR_MENU) && (scr->flags & SCR_NUMERIC)))
X {
X if (check_scr(scr, temp))
X scr->lflags |= SCR_HAVE_KEY;
X else
X scr->lflags |= SCR_DISPLAY;
X }
X else
X scr->lflags |= SCR_DISPLAY;
X break;
X }
X }
X msg_line = save_ml;
X msg_column = save_mc;
X }
X while (!(scr->lflags & SCR_QUIT) && !(scr->lflags & SCR_HAVE_KEY));
X }
X if (scr_level == 0)
X {
X scr_main = FALSE;
X to_level = FALSE;
X }
X }
X while (!(scr->lflags & SCR_QUIT) && !scr_quit && !scr_main && !scr_backup && !to_level);
X scr_backup = FALSE;
X if (scr_level >= 0)
X scr_tbl[scr_level--] = 0;
X if (scr_level == -1)
X {
X scr_main = FALSE;
X to_level = FALSE;
X }
X else if (to_level && (scr_level == want_level))
X to_level = FALSE;
X return(TRUE);
X }
X else
X return(FALSE);
X}
X
END_OF_FILE
if test 17878 -ne `wc -c <'lib/scrops1.c'`; then
echo shar: \"'lib/scrops1.c'\" unpacked with wrong size!
fi
# end of 'lib/scrops1.c'
fi
if test -f 'monitor2.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \"'monitor2.c'\"
else
echo shar: Extracting \"'monitor2.c'\" \(16643 characters\)
sed "s/^X//" >'monitor2.c' <<'END_OF_FILE'
X/* System activity monitor */
X
X/*
X*/
X
X/*
X Created Sept 5, 1987 by JCT
X*/
X
X/*
X * Copyright (c) John C. Tompkins 1989
X * All rights reserved.
X *
X * Permission is granted to use this for any personal, noncommercial use.
X * You may not distribute source or executable code for profit, nor
X * may you distribute it with a commercial product without the prior
X * written consent of the author. Please send modifications to the
X * author for inclusion in updates to the program.
X */
X
X#include <stdio.h>
X
X#include <km/defs.h>
X#include <km/ascii.h>
X#include <km/scrio.h>
X#include <km/scrops.h>
X#include <km/rdspec.h>
X#include <km/string1.h>
X#include <km/string2.h>
X#include <km/monitor.h> /* must come after defs.h and scrops.h */
X
extern int setup_mode(); /* forward reference */
extern int plot_data();
extern int chk_key();
X
SCR mode_scr =
X {
X 0, /* window */
X 0, /* head */
X setup_mode, /* entry function */
X plot_data, /* loop function */
X chk_key, /* check key function */
X 0, /* prompt */
X 0, /* entry */
X 0, /* active entry */
X 0, /* last active */
X 5, /* get key timeout */
X 0, /* help file */
X 0, /* help section */
X (SCR_NO_REFRESH | SCR_HELP_LOOP), /* flags */
X 0, /* local flags */
X 0 /* color */
X };
X
int get_interval()
X{
X int stat = FALSE, num;
X WINDOW *win;
X
X if (win = newwin(3, 42, 8, 15))
X {
X wsetcolor(win, (win->color & 0x0f), ((win->color >> 4) & 0x0f));
X wclear(win);
X box(win);
X wmove(win, 1, 2);
X waddstr(win, "Enter update interval (1-100) : ");
X wrefresh(win);
X if (wget_int(win, &num, 1, 100, 4, FALSE))
X {
X sample_interval = num;
X stat = TRUE;
X }
X delwin(win, TRUE);
X }
X return(stat);
X}
X
static int chk_key(scr, key)
X SCR *scr;
X int key;
X{
X switch (tolower(key))
X {
X case UNDETERMINED :
X return (TRUE);
X break;
X case 'w' :
X if (get_interval())
X {
X mode_scr.timeout = sample_interval;
X return (TRUE);
X }
X break;
X }
X}
X
void plot_CPU()
X{
X long cpu_idle, cpu_user, cpu_system, wait_io, wait_swap, wait_pio;
X
X cpu_idle = si_new.cpu[CPU_IDLE] - si_last.cpu[CPU_IDLE];
X cpu_user = si_new.cpu[CPU_USER] - si_last.cpu[CPU_USER];
X cpu_system = si_new.cpu[CPU_KERNEL] - si_last.cpu[CPU_KERNEL];
X wait_io = si_new.wait[W_IO] - si_last.wait[W_IO];
X wait_swap = si_new.wait[W_SWAP] - si_last.wait[W_SWAP];
X wait_pio = si_new.wait[W_PIO] - si_last.wait[W_PIO];
X bar_percent(LINE_1, COL_1, cpu_idle , time_interval);
X bar_percent(LINE_2, COL_1, cpu_user , time_interval);
X bar_percent(LINE_3, COL_1, cpu_system , time_interval);
X bar_percent(LINE_1, COL_2, wait_io , time_interval);
X bar_percent(LINE_2, COL_2, wait_swap , time_interval);
X bar_percent(LINE_3, COL_2, wait_pio , time_interval);
X}
X
void plot_disk()
X{
X long bread, bwrite, lread, lwrite;
X
X bread = si_new.bread - si_last.bread;
X bwrite = si_new.bwrite - si_last.bwrite;
X lread = si_new.lread - si_last.lread;
X lwrite = si_new.lwrite - si_last.lwrite;
X bar_persec(LINE_1, COL_1, lread, &lr_limit, 10L);
X bar_persec(LINE_1, COL_2, lwrite, &lw_limit, 10L);
X bar_percent(LINE_2, COL_1, (lread - bread) , lread);
X bar_percent(LINE_2, COL_2, (lwrite - bwrite) , lwrite);
X#ifdef XENIX
X bar_persec(LINE_3, COL_1, (si_new.swapin - si_last.swapin), &si_limit, 10L);
X bar_persec(LINE_3, COL_2, (si_new.swapout - si_last.swapout), &so_limit, 10L);
X#else
X bar_persec(LINE_3, COL_1, (si_new.bswapin - si_last.bswapin), &si_limit, 10L);
X bar_persec(LINE_3, COL_2, (si_new.bswapout - si_last.bswapout), &so_limit, 10L);
X#endif
X}
X
void plot_IO()
X{
X bar_persec(LINE_1, COL_1, (si_new.readch - si_last.readch), &rc_limit, 10L);
X bar_persec(LINE_1, COL_2, (si_new.writech - si_last.writech), &wc_limit, 10L);
X bar_persec(LINE_2, COL_1, (si_new.rcvint - si_last.rcvint), &ri_limit, 10L);
X bar_persec(LINE_2, COL_2, (si_new.xmtint - si_last.xmtint), &wi_limit, 10L);
X bar_persec(LINE_3, COL_1, ((si_new.rawch - si_last.rawch) + (si_new.canch - si_last.canch)), &rt_limit, 10L);
X bar_persec(LINE_3, COL_2, (si_new.outch - si_last.outch), &wt_limit, 10L);
X}
X
void plot_misc()
X{
X#ifdef XENIX
X bar_persec(LINE_1, COL_1, (si_new.syscall - si_last.syscall), &sc_limit, 10L);
X bar_persec(LINE_2, COL_1, (si_new.pswitch - si_last.pswitch), &ps_limit, 10L);
X bar_persec(LINE_2, COL_2, (si_new.iget - si_last.iget), &ig_limit, 10L);
X bar_persec(LINE_3, COL_1, (si_new.namei - si_last.namei), &ni_limit, 10L);
X bar_persec(LINE_3, COL_2, (si_new.dirblk - si_last.dirblk), &db_limit, 10L);
X#else
X bar_persec(LINE_1, COL_1, (si_new.runque - si_last.runque), &rq_limit, 10L);
X bar_persec(LINE_1, COL_2, (si_new.swpque - si_last.swpque), &sq_limit, 10L);
X bar_persec(LINE_2, COL_1, (si_new.pswitch - si_last.pswitch), &ps_limit, 10L);
X bar_persec(LINE_2, COL_2, (si_new.iget - si_last.iget), &ig_limit, 10L);
X bar_persec(LINE_3, COL_1, (si_new.namei - si_last.namei), &ni_limit, 10L);
X bar_persec(LINE_3, COL_2, (si_new.dirblk - si_last.dirblk), &db_limit, 10L);
X#endif
X}
X
void plot_capacity()
X{
X int i;
X
X#ifdef XENIX
X move(LINE_1, COL_1 + 27);
X if (si_new.wait[W_SWAP] != si_last.wait[W_SWAP])
X addstr("(Swap)");
X else
X {
X for (i = 0; i < 6; i++)
X addgraphic(G_H);
X }
X bar_absolute(LINE_1, COL_1, free_mem, &fm_limit, 10L);
X move(LINE_1, COL_2 + 16);
X printw("%-10d", free_wait);
X for (i = 0; i < 5; i++)
X {
X move(LINE_1 + 1 + i, COL_2 + 16);
X if (free_max[i])
X printw("%-10ld", free_max[i]);
X else
X addstr(" ");
X }
X#endif
X bar_absolute(LINE_2, COL_1, nproc, &pr_limit, 10L);
X bar_absolute(LINE_2, COL_2, ntext, &tx_limit, 10L);
X bar_absolute(LINE_3, COL_1, nfile, &of_limit, 10L);
X bar_absolute(LINE_3, COL_2, ninode, &in_limit, 10L);
X}
X
X#ifdef SYSV
void plot_scall()
X{
X bar_persec(LINE_1, COL_1, (si_new.syscall - si_last.syscall), &sc_limit, 10L);
X bar_persec(LINE_2, COL_1, (si_new.sysfork - si_last.sysfork), &sf_limit, 10L);
X bar_persec(LINE_2, COL_2, (si_new.sysexec - si_last.sysexec), &se_limit, 10L);
X bar_persec(LINE_3, COL_1, (si_new.sysread - si_last.sysread), &sr_limit, 10L);
X bar_persec(LINE_3, COL_2, (si_new.syswrite - si_last.syswrite), &sw_limit, 10L);
X}
X
void plot_HD()
X{
X long operations, blocks, active, response, av_wait, av_serv;
X
X operations = io_new[disk].ios.io_ops - io_last[disk].ios.io_ops;
X blocks = io_new[disk].io_bcnt - io_last[disk].io_bcnt;
X active = io_new[disk].io_act - io_last[disk].io_act;
X response = io_new[disk].io_resp - io_last[disk].io_resp;
X av_wait = (operations ? (((response - active) * 1000) / operations / hz) : 0);
X av_serv = (operations ? ((response * 1000) / operations / hz) : 0);
X bar_percent(LINE_1, COL_1, active, time_interval);
X bar_persec(LINE_2, COL_1, operations, &aq_limit, 10L);
X bar_persec(LINE_2, COL_2, blocks, &bc_limit, 10L);
X bar_absolute(LINE_3, COL_1, av_wait, &aw_limit, 10L);
X bar_absolute(LINE_3, COL_2, av_serv, &as_limit, 10L);
X}
X
void plot_IPC()
X{
X bar_persec(LINE_1, COL_1, si_new.sema - si_last.sema, &sm_limit, 10L);
X bar_persec(LINE_1, COL_2, si_new.msg - si_last.msg, &mg_limit, 10L);
X}
X#endif
X
int plot_data()
X{
X#ifdef SYSV
X int i;
X#endif
X
X if (!read_data(FALSE))
X return(FALSE);
X put_when(0, COLS - 24, curr_time, 0, FALSE);
X switch (mode)
X {
X case 0 :
X plot_CPU();
X break;
X case 1 :
X plot_disk();
X break;
X case 2 :
X plot_IO();
X break;
X case 3 :
X plot_misc();
X break;
X case 4 :
X plot_capacity();
X break;
X#ifdef SYSV
X case 5 :
X plot_scall();
X break;
X case 6 :
X plot_HD();
X break;
X case 7 :
X plot_IPC();
X break;
X#endif
X case 8 :
X plot_top();
X break;
X case 9 :
X break;
X default :
X break;
X }
X move((LINES - 1), 0);
X refresh();
X return(TRUE);
X}
X
void chart_config()
X{
X move(LINE_1, COL_1);
X printw ("Num of disk buffers : %-8d", v_buf.v_buf);
X move(LINE_1 + 1, COL_1);
X printw ("System addressable buffers : %-8d", v_buf.v_sabuf);
X move(LINE_1 + 2, COL_1);
X printw ("Num of hash buffers : %-8d", v_buf.v_hbuf);
X move(LINE_1 + 3, COL_1);
X printw ("Num of buffer headers : %-8d", v_buf.v_maxbuf);
X move(LINE_1 + 4, COL_1);
X printw ("Max number of filesystems : %-8d", v_buf.v_mount);
X move(LINE_1 + 5, COL_1);
X printw ("Max open inodes/filesystem : %-8d", v_buf.v_inode);
X move(LINE_1 + 6, COL_1);
X printw ("Max open files/filesystem : %-8d", v_buf.v_file);
X move(LINE_1 + 7, COL_1);
X printw ("Max open files/process : %-8d", NOFILE);
X move(LINE_1 + 8, COL_1);
X printw ("Max number of file locks : %-8d", v_buf.v_lock);
X move(LINE_1 + 9, COL_1);
X printw ("Max total processes : %-8d", v_buf.v_proc);
X move(LINE_1 + 10, COL_1);
X printw ("Max processes per user : %-8d", v_buf.v_maxup);
X move(LINE_1 + 11, COL_1);
X printw ("Max open text segments : %-8d", v_buf.v_text);
X move(LINE_1 + 12, COL_1);
X printw ("Max timeout calls : %-8d", v_buf.v_call);
X move(LINE_1 + 13, COL_1);
X printw ("Number of clists : %-8d", v_buf.v_clist);
X move(LINE_1 + 14, COL_1);
X printw ("Number of 8-bits maps : %-8d", v_buf.v_emap);
X move(LINE_1 + 15, COL_1);
X printw ("Max shell-layer sessions : %-8d", v_buf.v_sxt);
X move(LINE_1 + 16, COL_1);
X printw ("Max number of multiscreens : %-8d", v_buf.v_scrn);
X move(LINE_1 + 17, COL_1);
X printw ("Timezone offset in minutes : %-8d", tz);
X move(LINE_1 + 18, COL_1);
X printw ("Daylight savings in effect : %s", (dstflag ? "Yes " : "No "));
X move(LINE_1, COL_2);
X printw ("Max messages to process : %-8d", v_buf.v_msgmap);
X move(LINE_1 + 1, COL_2);
X printw ("Max single message size : %-8d", v_buf.v_msgmax);
X move(LINE_1 + 2, COL_2);
X printw ("Max bytes in message queue : %-8d", v_buf.v_msgmnb);
X move(LINE_1 + 3, COL_2);
X printw ("Max message queues : %-8d", v_buf.v_msgmni);
X move(LINE_1 + 4, COL_2);
X printw ("Max message headers : %-8d", v_buf.v_msgtql);
X move(LINE_1 + 5, COL_2);
X printw ("Max bytes/message segment : %-8d", v_buf.v_msgssz);
X move(LINE_1 + 6, COL_2);
X printw ("Max message segments : %-8d", v_buf.v_msgseg);
X move(LINE_1 + 7, COL_2);
X printw ("Max semaphores to process : %-8d", v_buf.v_semmap);
X move(LINE_1 + 8, COL_2);
X printw ("Max number of semaphores : %-8d", v_buf.v_semmni);
X move(LINE_1 + 9, COL_2);
X printw ("Max semaphore undo entrys : %-8d", v_buf.v_semmnu);
X move(LINE_1 + 10, COL_2);
X printw ("Max semaphores/identifier : %-8d", v_buf.v_semmsl);
X move(LINE_1 + 11, COL_2);
X printw ("Max semaphore ops/call : %-8d", v_buf.v_semopm);
X move(LINE_1 + 12, COL_2);
X printw ("Max semaphore undo/process : %-8d", v_buf.v_semume);
X move(LINE_1 + 13, COL_2);
X printw ("Max semaphore value : %-8d", v_buf.v_semvmx);
X move(LINE_1 + 14, COL_2);
X printw ("Max semaphore adjust-exit : %-8d", v_buf.v_semaem);
X move(LINE_1 + 15, COL_2);
X printw ("Max semaphores in system : %-8d", v_buf.v_semmns);
X move(LINE_1 + 16, COL_2);
X printw ("Max shared data segments : %-8d", v_buf.v_sdata);
X move(LINE_1 + 17, COL_2);
X printw ("Max shared data slots : %-8d", v_buf.v_sdslots);
X}
X
int setup_mode()
X{
X int i;
X
X erase();
X switch (mode)
X {
X case 0 :
X mode_scr.head = " CPU Monitor ";
X chart_percent(LINE_1, COL_1, "% CPU Idle");
X chart_percent(LINE_2, COL_1, "% CPU User");
X chart_percent(LINE_3, COL_1, "% CPU System");
X chart_percent(LINE_1, COL_2, "% Wait I/O");
X chart_percent(LINE_2, COL_2, "% Wait Swap");
X chart_percent(LINE_3, COL_2, "% Wait Physical I/O");
X break;
X case 1 :
X mode_scr.head = " Disk Monitor ";
X chart_absolute(LINE_1, COL_1, "Reads / Second", lr_limit);
X chart_absolute(LINE_1, COL_2, "Writes / Second", lw_limit);
X chart_percent(LINE_2, COL_1, "% Read Cache");
X chart_percent(LINE_2, COL_2, "% Write Cache");
X chart_absolute(LINE_3, COL_1, "Swap Ins / Second", si_limit);
X chart_absolute(LINE_3, COL_2,"Swap Outs / Second", so_limit);
X break;
X case 2 :
X mode_scr.head = " I/O Monitor ";
X chart_absolute(LINE_1, COL_1, "Read Characters / Second", rc_limit);
X chart_absolute(LINE_1, COL_2, "Write Characters / Second", wc_limit);
X chart_absolute(LINE_2, COL_1, "Read Interrupts / Second", ri_limit);
X chart_absolute(LINE_2, COL_2, "Write Interrupts / Second", wi_limit);
X chart_absolute(LINE_3, COL_1, "Read TTY Chars / Second", rt_limit);
X chart_absolute(LINE_3, COL_2, "Write TTY Chars / Second", wt_limit);
X break;
X#ifdef XENIX
X case 3 :
X mode_scr.head = " Miscellaneous Monitor ";
X chart_absolute(LINE_1, COL_1, "System Calls / Second", sc_limit);
X chart_absolute(LINE_2, COL_1, "Process Switches / Second", ps_limit);
X chart_absolute(LINE_2, COL_2, "Igets / Second", ig_limit);
X chart_absolute(LINE_3, COL_1, "Nameis / Second", ni_limit);
X chart_absolute(LINE_3, COL_2, "Dirblks / Second", db_limit);
X break;
X#else
X case 3 :
X mode_scr.head = " Miscellaneous Monitor ";
X chart_absolute(LINE_1, COL_1, "Run Queue Size", rq_limit);
X chart_absolute(LINE_1, COL_2, "Swap Queue Size", sq_limit);
X chart_absolute(LINE_2, COL_1, "Process Switches / Second", ps_limit);
X chart_absolute(LINE_2, COL_2, "Igets / Second", ig_limit);
X chart_absolute(LINE_3, COL_1, "Nameis / Second", ni_limit);
X chart_absolute(LINE_3, COL_2, "Dirblks / Second", db_limit);
X break;
X#endif
X case 4 :
X mode_scr.head = " Capacity Monitor ";
X#ifdef XENIX
X chart_absolute(LINE_1, COL_1, "Free Memory in Bytes", fm_limit);
X move(LINE_1, COL_2);
X printw("Wait count : %-10d", free_wait);
X move(LINE_1 + 1, COL_2);
X printw("Free mem size : %-10ld", free_max[0]);
X for (i = 1; i < 5; i++)
X {
X move(LINE_1 + 1 + i, COL_2 + 16);
X printw("%-10ld", free_max[i]);
X }
X#endif
X chart_capacity(LINE_2, COL_1, "Process Count", pr_limit, (long)v_buf.v_proc);
X chart_capacity(LINE_2, COL_2, "Open Text Segment Count", tx_limit, (long)v_buf.v_text);
X chart_capacity(LINE_3, COL_1, "Open File Count", of_limit, (long)v_buf.v_file);
X chart_capacity(LINE_3, COL_2, "Open Inode Count", in_limit, (long)v_buf.v_inode);
X break;
X#ifdef SYSV
X case 5 :
X mode_scr.head = " System Call Monitor ";
X chart_absolute(LINE_1, COL_1, "System Calls / Second", sc_limit);
X chart_absolute(LINE_2, COL_1, "Forks / Second", sf_limit);
X chart_absolute(LINE_2, COL_2, "Execs / Second", se_limit);
X chart_absolute(LINE_3, COL_1, "Reads / Second", sr_limit);
X chart_absolute(LINE_3, COL_2, "Writes / Second", sw_limit);
X break;
X case 6 :
X mode_scr.head = " Hard Disk Monitor ";
X move(0, (COLS - 12));
X printw("Drive # %2d", (disk + 1));
X chart_percent(LINE_1, COL_1, "% Busy");
X chart_absolute(LINE_2, COL_1, "Disk Queue Size", aq_limit);
X chart_absolute(LINE_2, COL_2, "Disk Blocks / Second", bc_limit);
X chart_absolute(LINE_3, COL_1, "Average Wait in mSec", aw_limit);
X chart_absolute(LINE_3, COL_2, "Average Service in mSec", as_limit);
X break;
X case 7 :
X mode_scr.head = " IPC Monitor ";
X chart_absolute(LINE_1, COL_1, "Semaphores / Second", sm_limit);
X chart_absolute(LINE_1, COL_2, "Messages / Second", mg_limit);
X break;
X#endif
X case 8 :
X mode_scr.head = " Top CPU Monitor ";
X chart_top();
X break;
X case 9 :
X mode_scr.head = " Configuration Monitor ";
X chart_config();
X break;
X }
X si_last = si_llast;
X#ifdef SYSV
X for (i = 0; i < DISKS; i++)
X io_last[i] = io_llast[i];
X#endif
X last_time = llast_time;
X}
X
void set_mode(what)
X int what;
X{
X mode = what;
X mode_scr.help_file = main_menu.help_file;
X mode_scr.help_section = main_menu.active_entry->help_section;
X if (what == 8)
X mode_scr.prompt = " (Q)uit, (T)op, (W)hen, <SPACE> to backup or selection ";
X else
X mode_scr.prompt = " (Q)uit, (T)op, (W)hen or <SPACE> to backup ";
X mode_scr.timeout = sample_interval;
X do_scr(&mode_scr);
X mode_scr.prompt = 0;
X}
X
int mode_CPU()
X{
X set_mode(0);
X return(TRUE);
X}
X
int mode_disk()
X{
X set_mode(1);
X return(TRUE);
X}
X
int mode_IO()
X{
X set_mode(2);
X return(TRUE);
X}
X
int mode_misc()
X{
X set_mode(3);
X return(TRUE);
X}
X
int mode_capacity()
X{
X set_mode(4);
X return(TRUE);
X}
X
X#ifdef SYSV
int mode_scall()
X{
X set_mode(5);
X return(TRUE);
X}
X
int do_disk(number)
X int number;
X{
X disk = number;
X set_mode(6);
X return(TRUE);
X}
X
int mode_HD()
X{
X disk_menu.timeout = sample_interval;
X do_scr(&disk_menu);
X return(TRUE);
X}
X
int mode_IPC()
X{
X set_mode(7);
X return(TRUE);
X}
X#endif
X
int mode_proc()
X{
X do_proc_menu();
X return(TRUE);
X}
X
int mode_top()
X{
X name_ptr = name_buf;
X mode_scr.func_chk = top_chk;
X set_mode(8);
X mode_scr.func_chk = chk_key;
X return(TRUE);
X}
X
int mode_config()
X{
X set_mode(9);
X return(TRUE);
X}
X
END_OF_FILE
if test 16643 -ne `wc -c <'monitor2.c'`; then
echo shar: \"'monitor2.c'\" unpacked with wrong size!
fi
# end of 'monitor2.c'
fi
echo shar: End of archive 5 \(of 9\).
cp /dev/null ark5isdone
MISSING=""
for I in 1 2 3 4 5 6 7 8 9 ; do
if test ! -f ark${I}isdone ; then
MISSING="${MISSING} ${I}"
fi
done
if test "${MISSING}" = "" ; then
echo You have unpacked all 9 archives.
rm -f ark[1-9]isdone ark[1-9][0-9]isdone
else
echo You still need to unpack the following archives:
echo " " ${MISSING}
fi
## End of shell archive.
exit 0
More information about the Comp.unix.xenix
mailing list