/* $Copyright:	$
 * Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
 * Sequent Computer Systems, Inc.   All rights reserved.
 *  
 * This software is furnished under a license and may be used
 * only in accordance with the terms of that license and with the
 * inclusion of the above copyright notice.   This software may not
 * be provided or otherwise made available to, or used by, any
 * other person.  No title to or ownership of the software is
 * hereby transferred.
 */

#ident "$Header: text.c 1.5 89/07/26 $"

/*
 * text.c
 *
 * Data structures for the screen
 */

#include <stdio.h>
#include <sys/types.h>
#include <sys/vm.h>
#include <sys/fcntl.h>
#include <sys/flock.h>
#include "monitor.h"
#include "sslib.h"

char *percent[] = {
	"0    10    20    30    40    50    60    70    80    90    100",
	"0    20    40    60    80    100",
	"0  20  40  60  80  100"
};

char *hashes[] = {
	"+-----+-----+-----+-----+-----+-----+-----+-----+-----+------+",
	"+--+--+--+--+--+--+--+--+--+---+",
	"+-+-+-+-+-+-+-+-+-+--+"
};

int p_bar_len[] = {
	60, 30, 20
};

/* >>>>> Perhaps, for total, just use the stuff for 1 col, (it is the same) */

int tot_bar_len = 60;

extern struct disk_summary disk_sum;
extern struct vmmeter rate;	/* rate over last interval */
extern struct procstate ps;
extern ulong	totprocs;
extern ulong	pt_user;	/* total user time */
extern ulong	pt_sys;		/* total sys time */
extern ulong	pt_total;	/* total processor time */
extern ulong	fsreadhit, fswritehit; /* File Sys hit ratios */
extern unsigned deficit;
extern ulong	pgin, pgpgin;	/* converted from vmmeter */
extern ulong	pgout, pgpgout;	/* converted from vmmeter */
extern ulong	freemem, dirtymem;	/* converted from mem_stats */
extern ulong	totalvm;		/* converted from mem_stats */
extern struct flckinfo flckinfo;
extern struct flock_stats fl_stats;

struct sstat scr_text[] = {
  /*
   * Processor time stats
   *  pt	fmt	datav		verbose			terse	display
   */
  { {0,0},	"%5d",	&pt_user,	"Total User Time",	"usr %", 1 },
  { {0,0},	"%5d",	&pt_sys,	"Total System Time",	"sys %", 1 },
  { {0,0},	"%5d",	&pt_total,	"Total Time",		"tot %", 1 },
  /*
   * Process stats
   *  pt		datav		verbose			terse	display
   */
  { {0,0},	"%5d",	&totprocs,	"Number of Procs",	"procs", 1 },
  { {0,0},	"%5d",	&ps.ps_onproc,	"Running Procs",	"on p",	1 },
  { {0,0},	"%5d",	&ps.ps_runq,	"Runnable Procs",	"runq",	1 },
  { {0,0},	"%5d",	&ps.ps_fastwait,"Fast Wait",		"wait",	1 },
  { {0,0},	"%5d",	&ps.ps_sleep,	"Sleeping Procs",	"sleep",1 },
  { {0,0},	"%5d",	&ps.ps_swap,	"Swapped Procs",	"swapped",1 },
  { {0,0},	"%5d",	&ps.ps_filewait,"Procs FS io Wait",	"fs io",1 },
  { {0,0},	"%5d",	&ps.ps_physwait,"Procs Phy io Wait",	"phys io",1 },
  /*
   * Misc. System stats
   *  pt		datav		verbose			terse	display
   */
  { {0,0},	"%5d",	&rate.v_syscall, "System Calls",	"sysc", 1 },
  { {0,0},	"%5d",	&rate.v_swtch,	"Context Switches",	"csw",	1 },
  { {0,0},	"%5d",	&rate.v_intr,	"Interrupts",		"intr",	1 },
  { {0,0},	"%5d",	&rate.v_trap,	"Traps",		"traps", 1 },
  /*
   * Process creation stats (fork/vfork/exec)
   *  pt		datav		verbose			terse	display
   */
  { {0,0},	"%5d",	&rate.v_cntfork, "Forks",		"fork",	1 },
  { {0,0},	"%5d",	&rate.v_cntvfork, "Vforks",		"vfork", 1 },
  { {0,0},	"%5d",	&rate.v_cntexec, "Execs",		"exec", 1 },
  /*
   * Disk stats
   *  pt		datav		verbose			terse	display
   */
  { {0,0},"%5lu",(ulong *)&disk_sum.xfers,"Disk Transfers",	"dk xf", 1 },
  { {0,0},"%5lu",(ulong *)&disk_sum.kbytes, "Disk KBytes",	"dk KB", 1 },
  /*
   * TTY stats - rate.v_rawch is really v_rawch + v_canch
   *  pt		datav		verbose			terse	display
   */
  { {0,0},	"%5d",	&rate.v_rawch,	"TTY Chars In",		"ttyin", 1 },
  { {0,0},	"%5d",	&rate.v_outch,	"TTY Chars Out",	"ttyout", 1 },
  /*
   * Paging stats
   *  pt		datav		verbose			terse	display
   */
  { {0,0},	"%5d",	&rate.v_faults,	"Page Faults",		"pf",	1 },
  { {0,0},	"%5d",	&rate.v_pgfrec,	"Free Page Recs",	"pg rec",1 },
  { {0,0},	"%5d",	&rate.v_pgdrec,	"Dirty Page Recs",	"pgdrec",1 },
  { {0,0},	"%5d",	&pgin,"Page Ins",			"pgin", 1 },
  { {0,0},	"%5d",	&pgpgin,"Pages Paged In",		"ppgin", 1 },
  { {0,0},	"%5d",	&pgout,"Page Outs",			"pgout", 1 },
  { {0,0},	"%5d",	&pgpgout,"Pages Paged Out",		"ppgout", 1 },
  /*
   * Swapping stats
   *  pt		datav		verbose			terse	display
   */
  { {0,0},	"%5d",	&rate.v_swpin,	"Swap Ins",		"sw in", 1 },
  { {0,0},	"%5d",	&rate.v_pswpin,	"Pages Swapped In",	"pswin", 1 },
  { {0,0},	"%5d",	&rate.v_swpout,	"Swap Outs",		"sw out", 1 },
  { {0,0},	"%5d",	&rate.v_pswpout,"Pages Swapped Out",	"pswout", 1 },
  /*
   * Memory Use stats
   *  pt		datav		verbose			terse	display
   */
  { {0,0}, "%5d", (ulong *)&deficit, "Deficit",		"deficit", 1 },
  { {0,0}, "%5lu", (ulong *)&freemem, "Free Memory",	"free", 1 },
  { {0,0}, "%5lu", (ulong *)&dirtymem, "Dirty Memory",	"dirty", 1 },
  { {0,0}, "%5lu", (ulong *)&totalvm, "Total Virtual Mem",	"tot vm", 1 },
#ifdef FREESWAP
  { {0,0}, "%5lu", (ulong *)&memstats.m_freeswap,"Free Swap Space","free sw",1 },
#endif /* FREESWAP */
  /*
   * File System stats
   *  pt		datav		verbose			terse	display
   */
  { {0,0},	"%5d",	&rate.v_bread,	"FS Blk Reads",		"fs brd", 1 },
  { {0,0},	"%5d",	&rate.v_bwrite,	"FS Blk Writes",	"fs bwt", 1 },
  { {0,0},	"%5d",	&fsreadhit,	"FS Read Hit",		"fs rdh", 1 },
  { {0,0},	"%5d",	&fswritehit,	"FS Write Hit",		"fs wth", 1 },
  /*
   * Physical I/O stats
   *  pt		datav		verbose			terse	display
   */
  { {0,0},	"%5d",	&rate.v_phread,	"Raw Reads",		"raw rd", 1 },
  { {0,0},	"%5d",	&rate.v_phwrite,"Raw Writes",		"raw wt", 1 },
  { {0,0},	"%5d",	&rate.v_phreadblks,	"Raw Read KB",	"raw rKB", 1 },
  { {0,0},	"%5d",	&rate.v_phwriteblks,	"Raw Write KB",	"raw wKB", 1 },
  /*
   * File/Record locking stats
   *  pt		datav		verbose			terse	display
   */
  { {0,0},	"%5lu",	(ulong *)&flckinfo.reccnt,"Locks Used","lckcnt", 1 },
  { {0,0},	"%5d",	&fl_stats.lck_ut,"Percent Locks Used",	"%locks", 1 },
  /*
   * SysV IPC stats
   *  pt		datav		verbose			terse	display
   */
  { {0,0},	"%5d",	&rate.v_msg, "Message Ops",		"msgops", 1 },
  { {0,0},	"%5d",	&rate.v_sema, "Semaphore Ops",		"semops", 1 },
};

int n_text = sizeof(scr_text)/sizeof(scr_text[0]);
