mirror of https://github.com/lindes/ttyload.git
ugh, stuff still isn't happy on vax... but I think that may just
be vax. checkpoint checkin so I can try it elsewhere. Ugh, though, I need to re-write large chunks of this stuff.
This commit is contained in:
parent
6304f61fae
commit
bc331aac01
22
Makefile
22
Makefile
|
@ -1 +1,21 @@
|
|||
ttyload: ttyload.c ttyload.h
|
||||
ARCH = `uname -s`
|
||||
|
||||
OBJS = arch/$(ARCH)/getload.o
|
||||
|
||||
# for the things in the sub-directory:
|
||||
INCLUDES = -I${PWD}
|
||||
|
||||
# Hopefully you don't need this:
|
||||
OTHER_FLAGS = -DNEED_LOCAL_HEADERS
|
||||
|
||||
CFLAGS = $(INCLUDES) $(OTHER_FLAGS)
|
||||
|
||||
default:
|
||||
make ttyload ARCH=`uname -s`
|
||||
|
||||
ttyload.c: ttyload.h
|
||||
|
||||
ttyload: $(OBJS) ttyload.o
|
||||
|
||||
clean:
|
||||
rm -f *.o $(OBJS)
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
#include "ttyload.h"
|
||||
|
||||
#include <stdio.h> /* for perror */
|
||||
#include <stdlib.h> /* for exit() */
|
||||
#include <unistd.h> /* for sleep() */
|
||||
|
||||
#ifdef NEED_LOCAL_HEADERS
|
||||
#include "loadavg.h"
|
||||
#else /* don't NEED_LOCAL_HEADERS */
|
||||
#include <sys/loadavg.h> /* for getloadavg() */
|
||||
#endif /* (don't) NEED_LOCAL_HEADERS */
|
||||
|
||||
void getload(load_list *loadavgs)
|
||||
{
|
||||
double theload[3];
|
||||
int ret;
|
||||
|
||||
if((ret = getloadavg(theload, 3)) < 0)
|
||||
{
|
||||
perror("getloadavg() failed");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
switch(ret)
|
||||
{
|
||||
case 1:
|
||||
loadavgs->one_minute = theload[0];
|
||||
fprintf(stderr, "5 minute Load average is unreliable.\n");
|
||||
sleep(1);
|
||||
/* we warned, but fall through anyway */
|
||||
case 2:
|
||||
loadavgs->five_minute = theload[1];
|
||||
fprintf(stderr, "15 minute Load average is unreliable.\n");
|
||||
sleep(1);
|
||||
/* we warned, but fall through anyway */
|
||||
case 3:
|
||||
/* so the caller _can_ know how we did */
|
||||
loadavgs->numloads = ret;
|
||||
loadavgs->fifteen_minute = theload[2];
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Sorry, couldn't get any load "
|
||||
"averages. This is, therefore, pointless.\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
/* the important (to me, anyway) bits of sys/loadavg.h: */
|
||||
|
||||
int getloadavg(double loadavg[], int nelem);
|
||||
|
||||
#define LOADAVG_1MIN 0
|
||||
#define LOADAVG_5MIN 1
|
||||
#define LOADAVG_15MIN 2
|
28
ttyload.c
28
ttyload.c
|
@ -6,7 +6,7 @@
|
|||
* Copyright 1996 by David Lindes
|
||||
* all right reserved.
|
||||
*
|
||||
* Version information: $Id: ttyload.c,v 1.4 1996-06-16 19:28:21 lindes Exp $
|
||||
* Version information: $Id: ttyload.c,v 1.5 2000-05-20 01:31:30 lindes Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
|
@ -15,7 +15,9 @@
|
|||
#include <stdlib.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#if 0
|
||||
#include <sys/sysmp.h>
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
@ -29,7 +31,7 @@
|
|||
#define MINROWS (HEIGHTPAD + 6)
|
||||
#define MINCOLS (WIDTHPAD + 6)
|
||||
|
||||
char *c="$Id: ttyload.c,v 1.4 1996-06-16 19:28:21 lindes Exp $";
|
||||
char *c="$Id: ttyload.c,v 1.5 2000-05-20 01:31:30 lindes Exp $";
|
||||
|
||||
char *kmemfile = "/dev/kmem",
|
||||
strbuf[BUFSIZ],
|
||||
|
@ -44,6 +46,17 @@ char *kmemfile = "/dev/kmem",
|
|||
int kmemfd,clockpad,clocks;
|
||||
clock_info *theclocks;
|
||||
|
||||
char *loadstrings[] = {
|
||||
" ", /* blank */
|
||||
"\033[31m*\033[m", /* one minute average */
|
||||
"\033[32m*\033[m", /* five minute average */
|
||||
"\033[33m*\033[m", /* one & five, together */
|
||||
"\033[34m*\033[m", /* fifteen minute average */
|
||||
"\033[35m*\033[m", /* one & fifteen, together */
|
||||
"\033[36m*\033[m", /* five & fifteen, together */
|
||||
"\033[37m*\033[m" /* one, five & fifteen, together */
|
||||
};
|
||||
|
||||
/* The following two variables should probably be assigned
|
||||
using some sort of real logic, rather than these hard-coded
|
||||
defaults, but the defaults work for now... */
|
||||
|
@ -58,7 +71,8 @@ int rows = 40,
|
|||
c,i,j,k */;
|
||||
|
||||
|
||||
void getload(long,long,load_list *);
|
||||
// void getload(long,long,load_list *);
|
||||
void getload(load_list *);
|
||||
int compute_height(load_t,load_t,int);
|
||||
void showloads(load_list *);
|
||||
void clear_screen();
|
||||
|
@ -150,6 +164,7 @@ int main(argc,argv,envp)
|
|||
theclocks[i].pos = -1;
|
||||
}
|
||||
|
||||
#if 0 /* need to pull this */
|
||||
loadaddr = sysmp(MP_KERNADDR,MPKA_AVENRUN);
|
||||
|
||||
if(loadaddr == -1)
|
||||
|
@ -165,6 +180,7 @@ int main(argc,argv,envp)
|
|||
perror("Couldn't open memory file");
|
||||
exit(1);
|
||||
}
|
||||
#endif /* 0 */
|
||||
|
||||
for(i=0;i<width;i++)
|
||||
{
|
||||
|
@ -176,7 +192,7 @@ int main(argc,argv,envp)
|
|||
time(&thetime);
|
||||
thetimetm = localtime(&thetime);
|
||||
|
||||
getload(kmemfd,loadaddr,&loadavgs[i]);
|
||||
getload(&loadavgs[i]);
|
||||
|
||||
if(((thetimetm->tm_sec) / intsecs) == 0)
|
||||
{
|
||||
|
@ -237,7 +253,7 @@ int main(argc,argv,envp)
|
|||
printf("CYCLING LOAD LIST...\n");
|
||||
sleep(3);
|
||||
}
|
||||
getload(kmemfd,loadaddr,&newload);
|
||||
getload(&newload);
|
||||
cycle_load_list(loadavgs,newload,width);
|
||||
i--;
|
||||
}
|
||||
|
@ -411,6 +427,7 @@ void showloads(loadavgs)
|
|||
NULL);
|
||||
}
|
||||
|
||||
#if 0 /* being phased out... ugliness. */
|
||||
void getload(kmemfd,loadaddr,loadavgs)
|
||||
long kmemfd,loadaddr;
|
||||
load_list *loadavgs;
|
||||
|
@ -427,6 +444,7 @@ void getload(kmemfd,loadaddr,loadavgs)
|
|||
exit(1);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
int compute_height(thisload,maxload,height)
|
||||
load_t thisload,
|
||||
|
|
14
ttyload.h
14
ttyload.h
|
@ -8,7 +8,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
char *h="$Id: ttyload.h,v 1.3 1996-06-16 19:28:21 lindes Exp $";
|
||||
static char *h="$Id: ttyload.h,v 1.4 2000-05-20 01:31:30 lindes Exp $";
|
||||
|
||||
#define MIN(a,b) (((a)<(b))?(a):(b))
|
||||
#define MAX(a,b) (((a)>(b))?(a):(b))
|
||||
|
@ -17,17 +17,6 @@ char *h="$Id: ttyload.h,v 1.3 1996-06-16 19:28:21 lindes Exp $";
|
|||
#define FIVE 02;
|
||||
#define FIFTEEN 04;
|
||||
|
||||
char *loadstrings[] = {
|
||||
" ", /* blank */
|
||||
"\033[31m*\033[m", /* one minute average */
|
||||
"\033[32m*\033[m", /* five minute average */
|
||||
"\033[33m*\033[m", /* one & five, together */
|
||||
"\033[34m*\033[m", /* fifteen minute average */
|
||||
"\033[35m*\033[m", /* one & fifteen, together */
|
||||
"\033[36m*\033[m", /* five & fifteen, together */
|
||||
"\033[37m*\033[m" /* one, five & fifteen, together */
|
||||
};
|
||||
|
||||
typedef long load_t;
|
||||
|
||||
typedef struct load_list {
|
||||
|
@ -37,6 +26,7 @@ typedef struct load_list {
|
|||
int height1;
|
||||
int height5;
|
||||
int height15;
|
||||
int numloads;
|
||||
} load_list;
|
||||
|
||||
typedef struct clock_info {
|
||||
|
|
Loading…
Reference in New Issue