diff --git a/Makefile b/Makefile index 21a7ff2..4c5f1d3 100644 --- a/Makefile +++ b/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) diff --git a/arch/SunOS/getload.c b/arch/SunOS/getload.c new file mode 100644 index 0000000..a55ab85 --- /dev/null +++ b/arch/SunOS/getload.c @@ -0,0 +1,46 @@ +#include "ttyload.h" + +#include /* for perror */ +#include /* for exit() */ +#include /* for sleep() */ + +#ifdef NEED_LOCAL_HEADERS +#include "loadavg.h" +#else /* don't NEED_LOCAL_HEADERS */ +#include /* 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); + } +} diff --git a/arch/SunOS/loadavg.h b/arch/SunOS/loadavg.h new file mode 100644 index 0000000..36af975 --- /dev/null +++ b/arch/SunOS/loadavg.h @@ -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 diff --git a/ttyload.c b/ttyload.c index 6104e0f..7626911 100644 --- a/ttyload.c +++ b/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 #include #include +#if 0 #include +#endif #include #include @@ -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;itm_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, diff --git a/ttyload.h b/ttyload.h index 9748bd7..f5f7496 100644 --- a/ttyload.h +++ b/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 {