From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 30-NOV-1989 10:52
To:	MRGATE::"ARISIA::EVERHART"
Subj:	PerfMeter V2.0 for DECWindows/VMS, Part 3 of 5 Parts

Received: From CRASH.CS.UMASS.EDU by GIZMO.SRI.COM with TCP; Thu, 30 NOV 89 06:30:10 PDT
Received: from vax5.cs.umass.edu by crash.cs.umass.edu (5.61/Ultrix2.0-B)
	id AA08083; Thu, 30 Nov 89 09:26:59 -0500
Message-Id: <8911301426.AA08083@crash.cs.umass.edu>
Date: Thu, 30 Nov 89 09:29 EST
From: "From the screen of Deneva...  30-Nov-1989 0929" <HELLER@cs.umass.EDU>
Subject: PerfMeter V2.0 for DECWindows/VMS, Part 3 of 5 Parts
To: info-vax@kl.sri.COM
X-Vms-To: coins::in%"info-vax@kl.sri.com"

X	   NewDevice_2_IO, DeltaDevice_2_IO, LastDeltaDevice_2_IO = -1,
X	   NewDevice_3_IO, DeltaDevice_3_IO, LastDeltaDevice_3_IO = -1,
X	   LastDeltaPageFaults = -1, LastDeltaPageIO = -1,
X	   LastDeltaFreePages = -1, LastDeltaModPages = -1;
X    register int NewPageFaults, DeltaPageFaults, 
X		 NewPageIO, DeltaPageIO, 
X		 NewFreePages, DeltaFreePages, 
X		 NewModPages, DeltaModPages, NewDispFlag;
X    register int total_time, NullTime,
X	   UserTime,
X	   SupeTime,
X	   ExecTime,
X	   KernTime,
X	   InteTime,
X	   CompTime,
X	   DeltaIO,ix;
X    static char label_buffer[32];
X	
X    if (cpu_graph_wind == 0) {
X	cpu_graph_wind = XtWindow(widget_array[PFM_CPU_GRAPH]);
X	cpu_graph_gc1  = MakeGC(cpu_graph_disp, cpu_graph_wind, GXinvert);
X	cpu_graph_gc0  = MakeGC(cpu_graph_disp, cpu_graph_wind, GXclear);
X	}
X    if (state_graph_wind == 0) {
X	state_graph_wind = XtWindow(widget_array[PFM_STATE_GRAPH]);
X	state_graph_gc1  = MakeGC(state_graph_disp, state_graph_wind, GXinvert);
X	state_graph_gc0  = MakeGC(state_graph_disp, state_graph_wind, GXclear);
X	}
X
X    get_cpu_times(&NewNullTime,
X	   &NewUserTime,
X	   &NewSupeTime,
X	   &NewExecTime,
X	   &NewKernTime,
X	   &NewInteTime,
X	   &NewCompTime);
X    NewPageFaults = current_faults;
X    NewPageIO = current_pageio;
X    NewFreePages = current_freepages;
X    NewModPages = current_modpages;
X
X    total_time = NewNullTime + NewUserTime + NewSupeTime + NewExecTime +
X		 NewKernTime + NewInteTime + NewCompTime;
X    if (total_time > 0) {
X	NullTime = (NewNullTime * 100) / total_time;
X	UserTime = (NewUserTime * 100) / total_time;
X	SupeTime = (NewSupeTime * 100) / total_time;
X	ExecTime = (NewExecTime * 100) / total_time;
X	KernTime = (NewKernTime * 100) / total_time;
X	InteTime = (NewInteTime * 100) / total_time;
X	CompTime = (NewCompTime * 100) / total_time;
X	}
X    else {
X	NullTime = NewNullTime;
X	UserTime = NewUserTime;
X	SupeTime = NewSupeTime;
X	ExecTime = NewExecTime;
X	KernTime = NewKernTime;
X	InteTime = NewInteTime;
X	CompTime = NewCompTime;
X	}
X
X    XClearArea(state_graph_disp,state_graph_wind,NullTimeX,0,7,100,0);
X    XFillRectangle(state_graph_disp,state_graph_wind,state_graph_gc1,NullTimeX,
X								    100-NullTime,
X								    7,NullTime);
X    XClearArea(state_graph_disp,state_graph_wind,UserTimeX,0,7,100,0);
X    XFillRectangle(state_graph_disp,state_graph_wind,state_graph_gc1,UserTimeX,
X								    100-UserTime,
X								    7,UserTime);
X    XClearArea(state_graph_disp,state_graph_wind,SupeTimeX,0,7,100,0);
X    XFillRectangle(state_graph_disp,state_graph_wind,state_graph_gc1,SupeTimeX,
X								    100-SupeTime,
X								    7,SupeTime);
X    XClearArea(state_graph_disp,state_graph_wind,ExecTimeX,0,7,100,0);
X    XFillRectangle(state_graph_disp,state_graph_wind,state_graph_gc1,ExecTimeX,
X								    100-ExecTime,
X								    7,ExecTime);
X    XClearArea(state_graph_disp,state_graph_wind,KernTimeX,0,7,100,0);
X    XFillRectangle(state_graph_disp,state_graph_wind,state_graph_gc1,KernTimeX,
X								    100-KernTime,
X								    7,KernTime);
X    XClearArea(state_graph_disp,state_graph_wind,InteTimeX,0,7,100,0);
X    XFillRectangle(state_graph_disp,state_graph_wind,state_graph_gc1,InteTimeX,
X								    100-InteTime,
X								    7,InteTime);
X    XClearArea(state_graph_disp,state_graph_wind,CompTimeX,0,7,100,0);
X    XFillRectangle(state_graph_disp,state_graph_wind,state_graph_gc1,CompTimeX,
X								    100-CompTime,
X								    7,CompTime);
X
X    CPUPercent[100] = 100 - NullTime;
X    for (ix = 0; ix < 100; ix++) {
X	CPUPercent[ix] = CPUPercent[ix+1];
X	XClearArea(cpu_graph_disp,cpu_graph_wind,ix,0,1,100,0);
X	XFillRectangle(cpu_graph_disp,cpu_graph_wind,cpu_graph_gc1,ix,100-CPUPercent[ix],
X								  1,CPUPercent[ix]);
X	}
X
X    if ((widget_array[PFM_DEVICE_0_IOCOUNT_TOTAL] != NULL) &&
X	(widget_array[PFM_DEVICE_0_IOCOUNT_DELTA] != NULL))
X	{
X	get_disk_opcnt(0, &NewDevice_0_IO);
X	if ((NewDispFlag = (Device_0_IO < 0))) Device_0_IO = NewDevice_0_IO;
X	DeltaDevice_0_IO = NewDevice_0_IO - Device_0_IO;
X	if (DeltaDevice_0_IO || NewDispFlag)
X		{
X		Device_0_IO = NewDevice_0_IO;
X		sprintf(label_buffer," %8d",Device_0_IO);
X		set_something(widget_array[PFM_DEVICE_0_IOCOUNT_TOTAL],DwtNlabel,
X			DwtLatin1String(label_buffer));
X		}
X	if (DeltaDevice_0_IO != LastDeltaDevice_0_IO)
X		{
X		if (DeltaDevice_0_IO == 0)
X		strcpy(label_buffer,"      ");
X		else
X		sprintf(label_buffer,"  %4d",DeltaDevice_0_IO);
X		set_something(widget_array[PFM_DEVICE_0_IOCOUNT_DELTA],DwtNlabel,
X			DwtLatin1String(label_buffer));
X		LastDeltaDevice_0_IO = DeltaDevice_0_IO;
X		}
X	}
X
X    if ((widget_array[PFM_DEVICE_1_IOCOUNT_TOTAL] != NULL) &&
X	(widget_array[PFM_DEVICE_1_IOCOUNT_DELTA] != NULL))
X	{
X	get_disk_opcnt(1, &NewDevice_1_IO);
X	if ((NewDispFlag = (Device_1_IO < 0))) Device_1_IO = NewDevice_1_IO;
X	DeltaDevice_1_IO = NewDevice_1_IO - Device_1_IO;
X	if ((DeltaDevice_1_IO || NewDispFlag) && Device_1_IO >= 0)
X	    {
X	    Device_1_IO = NewDevice_1_IO;
X	    sprintf(label_buffer," %8d",Device_1_IO);
X	    set_something(widget_array[PFM_DEVICE_1_IOCOUNT_TOTAL],DwtNlabel,
X			DwtLatin1String(label_buffer));
X	    }
X	if (DeltaDevice_1_IO != LastDeltaDevice_1_IO)
X	    {
X	    if (DeltaDevice_1_IO == 0)
X		strcpy(label_buffer,"      ");
X	    else
X		sprintf(label_buffer,"  %4d",DeltaDevice_1_IO);
X	    set_something(widget_array[PFM_DEVICE_1_IOCOUNT_DELTA],DwtNlabel,
X			DwtLatin1String(label_buffer));
X	    LastDeltaDevice_1_IO = DeltaDevice_1_IO;
X	    }
X	}
X
X    if ((widget_array[PFM_DEVICE_2_IOCOUNT_TOTAL] != NULL) &&
X	(widget_array[PFM_DEVICE_2_IOCOUNT_DELTA] != NULL))
X	{
X	get_disk_opcnt(2, &NewDevice_2_IO);
X	if ((NewDispFlag = (Device_2_IO < 0))) Device_2_IO = NewDevice_2_IO;
X	DeltaDevice_2_IO = NewDevice_2_IO - Device_2_IO;
X	if ((DeltaDevice_2_IO || NewDispFlag) && Device_2_IO >= 0)
X	    {
X	    Device_2_IO = NewDevice_2_IO;
X	    sprintf(label_buffer," %8d",Device_2_IO);
X	    set_something(widget_array[PFM_DEVICE_2_IOCOUNT_TOTAL],DwtNlabel,
X			DwtLatin1String(label_buffer));
X	    }
X	if (DeltaDevice_2_IO != LastDeltaDevice_2_IO)
X	    {
X	    if (DeltaDevice_2_IO == 0)
X		strcpy(label_buffer,"      ");
X	    else
X		sprintf(label_buffer,"  %4d",DeltaDevice_2_IO);
X	    set_something(widget_array[PFM_DEVICE_2_IOCOUNT_DELTA],DwtNlabel,
X			DwtLatin1String(label_buffer));
X	    LastDeltaDevice_2_IO = DeltaDevice_2_IO;
X	    }
X	}
X
X    if ((widget_array[PFM_DEVICE_3_IOCOUNT_TOTAL] != NULL) &&
X	(widget_array[PFM_DEVICE_3_IOCOUNT_DELTA] != NULL))
X	{
X	get_disk_opcnt(3, &NewDevice_3_IO);
X	if ((NewDispFlag = (Device_3_IO < 0))) Device_3_IO = NewDevice_3_IO;
X	DeltaDevice_3_IO = NewDevice_3_IO - Device_3_IO;
X	if ((DeltaDevice_3_IO || NewDispFlag) && Device_3_IO >= 0)
X	    {
X	    Device_3_IO = NewDevice_3_IO;
X	    sprintf(label_buffer," %8d",Device_3_IO);
X	    set_something(widget_array[PFM_DEVICE_3_IOCOUNT_TOTAL],DwtNlabel,
X			DwtLatin1String(label_buffer));
X	    }
X	if (DeltaDevice_3_IO != LastDeltaDevice_3_IO)
X	    {
X	    if (DeltaDevice_3_IO == 0)
X		strcpy(label_buffer,"      ");
X	    else
X		sprintf(label_buffer,"  %4d",DeltaDevice_3_IO);
X	    set_something(widget_array[PFM_DEVICE_3_IOCOUNT_DELTA],DwtNlabel,
X			DwtLatin1String(label_buffer));
X	    LastDeltaDevice_3_IO = DeltaDevice_3_IO;
X	    }
X	}
X
X    if ((NewDispFlag = (PageFaults < 0))) PageFaults = NewPageFaults;
X    DeltaPageFaults = NewPageFaults - PageFaults;
X    if (DeltaPageFaults || NewDispFlag)
X	{
X	PageFaults = NewPageFaults;
X	sprintf(label_buffer," %8d",PageFaults);
X	set_something(widget_array[PFM_PAGEFAULTS_TOTAL],DwtNlabel,
X		    DwtLatin1String(label_buffer));
X	}
X    if (DeltaPageFaults != LastDeltaPageFaults)
X	{
X	if (DeltaPageFaults == 0)
X	    strcpy(label_buffer,"      ");
X	else
X	    sprintf(label_buffer,"  %4d",DeltaPageFaults);
X	set_something(widget_array[PFM_PAGEFAULTS_DELTA],DwtNlabel,
X		    DwtLatin1String(label_buffer));
X	LastDeltaPageFaults = DeltaPageFaults;
X	}
X
X    if ((NewDispFlag = (PageIO < 0))) PageIO = NewPageIO;
X    DeltaPageIO = NewPageIO - PageIO;
X    if (DeltaPageIO || NewDispFlag)
X	{
X	PageIO = NewPageIO;
X	sprintf(label_buffer," %8d",PageIO);
X	set_something(widget_array[PFM_PAGEIO_TOTAL],DwtNlabel,
X		    DwtLatin1String(label_buffer));
X	}
X    if (DeltaPageIO != LastDeltaPageIO)
X	{
X	if (DeltaPageIO == 0)
X	    strcpy(label_buffer,"      ");
X	else
X	    sprintf(label_buffer,"  %4d",DeltaPageIO);
X	set_something(widget_array[PFM_PAGEIO_DELTA],DwtNlabel,
X		    DwtLatin1String(label_buffer));
X	LastDeltaPageIO = DeltaPageIO;
X	}
X
X    if ((NewDispFlag = (FreePages < 0))) FreePages = NewFreePages;
X    DeltaFreePages = NewFreePages - FreePages;
X    if (DeltaFreePages || NewDispFlag)
X	{
X	FreePages = NewFreePages;
X	sprintf(label_buffer," %8d",FreePages);
X	set_something(widget_array[PFM_FREEPAGES_TOTAL],DwtNlabel,
X		    DwtLatin1String(label_buffer));
X	}
X    if (DeltaFreePages != LastDeltaFreePages)
X	{
X	if (DeltaFreePages == 0)
X	    strcpy(label_buffer,"      ");
X	else
X	    sprintf(label_buffer,"  %4d",DeltaFreePages);
X	set_something(widget_array[PFM_FREEPAGES_DELTA],DwtNlabel,
X		    DwtLatin1String(label_buffer));
X	LastDeltaFreePages = DeltaFreePages;
X	}
X
X    if ((NewDispFlag = (ModPages < 0))) ModPages = NewModPages;
X    DeltaModPages = NewModPages - ModPages;
X    if (DeltaModPages || NewDispFlag)
X	{
X	ModPages = NewModPages;
X	sprintf(label_buffer," %8d",ModPages);
X	set_something(widget_array[PFM_MODPAGES_TOTAL],DwtNlabel,
X		    DwtLatin1String(label_buffer));
X	}
X    if (DeltaModPages != LastDeltaModPages)
X	{
X	if (DeltaModPages == 0)
X	    strcpy(label_buffer,"      ");
X	else
X	    sprintf(label_buffer,"  %4d",DeltaModPages);
X	set_something(widget_array[PFM_MODPAGES_DELTA],DwtNlabel,
X		      DwtLatin1String(label_buffer));
X	LastDeltaModPages = DeltaModPages;
X	}
X
X    XtAddTimeOut(update_period*1000, update, 0);
X    }
X
Xstatic GC MakeGC(disp,wind,fun)
XDisplay *disp;
XWindow wind;
Xint fun;
X{
X    static XGCValues gcvalues = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
X
X    gcvalues.function = fun;
X    return(XCreateGC(disp,wind,GCFunction,&gcvalues));
X    }
X
Xstatic long int last_user, last_super, last_exec, last_kernel,
X		last_interrupt, last_compat, last_spin, last_idle;
X
X#define K_TIME 0
X#define E_TIME 1
X#define S_TIME 2
X#define U_TIME 3
X#define I_TIME 4
X#define C_TIME 5
X#define SPIN_TIME 6
X#define IDLE_TIME 7
X
Xstatic init_cpu_times()
X    {
X    register int i, j, k;
X    long int *PMS$GL_KERNEL;
X
X    last_user = last_super = last_exec = last_kernel = last_interrupt =
X	last_compat = last_spin = last_idle = 0;
X
X    for (k = SMP$GL_ACTIVE_CPUS, j = 0; k != 0; j++, k = k >> 1) {
X	if ((k & 01) == 0) continue;
X	PMS$GL_KERNEL = (SMP$GL_CPU_DATA[j])->cpu$l_kernel;
X	last_kernel += PMS$GL_KERNEL[K_TIME];
X	last_exec += PMS$GL_KERNEL[E_TIME];
X	last_super += PMS$GL_KERNEL[S_TIME];
X	last_user += PMS$GL_KERNEL[U_TIME];
X	last_interrupt += PMS$GL_KERNEL[I_TIME];
X	last_compat += PMS$GL_KERNEL[C_TIME];
X	last_spin += PMS$GL_KERNEL[SPIN_TIME];
X	last_idle += PMS$GL_KERNEL[IDLE_TIME];
X	}
X    last_interrupt -= last_idle;
X    }
X
Xstatic get_cpu_times(null,user,super,exec,kernel,interrupt,compat)
Xint *null,*user,*super,*exec,*kernel,*interrupt,*compat;
X    {
X    register long int new_null, new_user, new_super, new_exec,
X		    new_kernel, new_interrupt, new_compat,
X		    new_idle, new_spin;
X    register int i, j, k;
X    long int *PMS$GL_KERNEL;
X    register long int new_abstime, totaltime;
X
X    new_user = new_super = new_exec = new_kernel = new_interrupt =
X	new_compat = new_spin = new_idle = 0;
X
X    for (k = SMP$GL_ACTIVE_CPUS, j = 0; k != 0; j++, k = k >> 1) {
X	if ((k & 01) == 0) continue;
X	PMS$GL_KERNEL = (SMP$GL_CPU_DATA[j])->cpu$l_kernel;
X	new_kernel += PMS$GL_KERNEL[K_TIME];
X	new_exec += PMS$GL_KERNEL[E_TIME];
X	new_super += PMS$GL_KERNEL[S_TIME];
X	new_user += PMS$GL_KERNEL[U_TIME];
X	new_interrupt += PMS$GL_KERNEL[I_TIME];
X	new_compat += PMS$GL_KERNEL[C_TIME];
X	new_spin += PMS$GL_KERNEL[SPIN_TIME];
X	new_idle += PMS$GL_KERNEL[IDLE_TIME];
X	}
X    new_interrupt -= new_idle;
X
X    *user = new_user - last_user; last_user = new_user;
X    *super = new_super - last_super; last_super = new_super;
X    *exec = new_exec - last_exec; last_exec = new_exec;
X    *kernel = new_kernel - last_kernel; last_kernel = new_kernel;
X    *interrupt = new_interrupt - last_interrupt; last_interrupt = new_interrupt;
X    *compat = new_compat - last_compat; last_compat = new_compat;
X
X    *null = new_idle - last_idle; last_idle = new_idle;
X    }
X
Xstatic get_disk_opcnt(devnum, count)
Xregister int devnum;
Xregister int *count;
X    {
X    static struct {
X	unsigned short int blen, icode;
X	int *buff;
X	unsigned short int *rlen;
X	} dvi_itmlst[] = {
X	{sizeof(int), DVI$_OPCNT, NULL, NULL},
X	{0, 0, NULL, NULL}
X	};
X    static struct {
X	unsigned short int istat, bytes;
X	long int fill;
X	} iosb;
X    char devname[64];
X    $DESCRIPTOR(dev,devname);
X    int status;
X
X    sprintf(devname, "PFM$DEVICE_%d_NAME", devnum);
X    dvi_itmlst[0].buff = count;
X    *count = -1;
X    dev.dsc$w_length = strlen(devname);
X    status = sys$getdviw(0,0,&dev,dvi_itmlst,&iosb,0,0,0);
X    if ((status == SS$_IVDEVNAM) && (devnum == 0))
X	{
X	$DESCRIPTOR(sysdev, "SYS$SYSDEVICE:");
X
X	sys$getdviw(0,0,&sysdev,dvi_itmlst,&iosb,0,0,0);
X	}
X    }
X
X
Xstatic update_disk_name_label(w, devnum)
XWidget w;
Xint devnum;
X    {
X    char devname[64];
X    char *title;
X
X    sprintf(devname, "PFM$DEVICE_%d_TITLE", devnum);
X    title = getenv(devname);
X    if (NULL == title)
X	{
X	sprintf(devname, "PFM$DEVICE_%d_NAME", devnum);
X	title = getenv(devname);
X	if ((NULL == title) && (0 == devnum))
X	    title = "SYS$SYSDEVICE:";
X	}
X    if (title != NULL) set_something(w,DwtNlabel,DwtLatin1String(title));
X    }
$ GoSub Convert_File

