diff options
-rw-r--r-- | MatrixOrbital.c | 11 | ||||
-rwxr-xr-x | configure | 2 | ||||
-rw-r--r-- | configure.in | 2 | ||||
-rw-r--r-- | display.c | 9 | ||||
-rw-r--r-- | display.h | 7 | ||||
-rw-r--r-- | lcd4linux.c | 55 | ||||
-rw-r--r-- | lcd4linux.conf.sample | 25 | ||||
-rw-r--r-- | parser.c | 27 | ||||
-rw-r--r-- | parser.h | 7 | ||||
-rw-r--r-- | system.c | 103 | ||||
-rw-r--r-- | system.h | 8 |
11 files changed, 216 insertions, 40 deletions
diff --git a/MatrixOrbital.c b/MatrixOrbital.c index 510ae26..8e7a0c5 100644 --- a/MatrixOrbital.c +++ b/MatrixOrbital.c @@ -1,4 +1,4 @@ -/* $Id: MatrixOrbital.c,v 1.5 2000/03/13 15:58:24 reinelt Exp $ +/* $Id: MatrixOrbital.c,v 1.6 2000/03/17 09:21:42 reinelt Exp $ * * driver for Matrix Orbital serial display modules * @@ -20,6 +20,10 @@ * * * $Log: MatrixOrbital.c,v $ + * Revision 1.6 2000/03/17 09:21:42 reinelt + * + * various memory statistics added + * * Revision 1.5 2000/03/13 15:58:24 reinelt * * release 0.9 @@ -30,7 +34,6 @@ * * first unstable but running release * - * */ /* @@ -246,7 +249,7 @@ static void MO_define_chars (void) } Segment[i].ascii=c; buffer[2]=c; - switch (Segment[i].type & (BAR_L | BAR_R | BAR_U | BAR_D)) { + switch (Segment[i].type) { case BAR_L: for (j=0; j<4; j++) { char Pixel[] = { 0, 1, 3, 7, 15, 31 }; @@ -360,7 +363,7 @@ int MO_bar (int type, int row, int col, int max, int len1, int len2) if (len2<1) len2=1; else if (len2>max) len2=max; - switch (type & (BAR_L | BAR_R | BAR_U | BAR_D)) { + switch (type) { case BAR_L: len1=max-len1; len2=max-len2; @@ -691,7 +691,7 @@ fi PACKAGE=lcd4linux -VERSION=0.9 +VERSION=0.91 if test "`cd $srcdir && pwd`" != "`pwd`" && test -f $srcdir/config.status; then { echo "configure: error: source directory already configured; run "make distclean" there first" 1>&2; exit 1; } diff --git a/configure.in b/configure.in index 487344a..bac7539 100644 --- a/configure.in +++ b/configure.in @@ -1,6 +1,6 @@ dnl Process this file with autoconf to produce a configure script. AC_INIT(lcd4linux.c) -AM_INIT_AUTOMAKE(lcd4linux, 0.9) +AM_INIT_AUTOMAKE(lcd4linux, 0.91) dnl Checks for programs. AC_PROG_CC @@ -1,4 +1,4 @@ -/* $Id: display.c,v 1.5 2000/03/13 15:58:24 reinelt Exp $ +/* $Id: display.c,v 1.6 2000/03/17 09:21:42 reinelt Exp $ * * framework for device drivers * @@ -20,6 +20,10 @@ * * * $Log: display.c,v $ + * Revision 1.6 2000/03/17 09:21:42 reinelt + * + * various memory statistics added + * * Revision 1.5 2000/03/13 15:58:24 reinelt * * release 0.9 @@ -127,11 +131,10 @@ int lcd_bar (int type, int row, int col, int max, int len1, int len2) if (col<1 || col>Display->cols) return -1; if (!(type & (BAR_H2 | BAR_V2))) len2=len1; if (type & BAR_LOG) { - type &= ~BAR_LOG; len1=(double)max*log(len1+1)/log(max); len2=(double)max*log(len2+1)/log(max); } - return Display->bar(type, row-1, col-1, max, len1, len2); + return Display->bar (type & BAR_HV, row-1, col-1, max, len1, len2); } int lcd_flush (void) @@ -1,4 +1,4 @@ -/* $Id: display.h,v 1.6 2000/03/13 15:58:24 reinelt Exp $ +/* $Id: display.h,v 1.7 2000/03/17 09:21:42 reinelt Exp $ * * framework for device drivers * @@ -20,6 +20,10 @@ * * * $Log: display.h,v $ + * Revision 1.7 2000/03/17 09:21:42 reinelt + * + * various memory statistics added + * * Revision 1.6 2000/03/13 15:58:24 reinelt * * release 0.9 @@ -56,6 +60,7 @@ #define BAR_H (BAR_L | BAR_R) #define BAR_V (BAR_U | BAR_D) +#define BAR_HV (BAR_H | BAR_V) typedef struct DISPLAY { char name[16]; diff --git a/lcd4linux.c b/lcd4linux.c index 383dc45..9a264dc 100644 --- a/lcd4linux.c +++ b/lcd4linux.c @@ -1,4 +1,4 @@ -/* $Id: lcd4linux.c,v 1.3 2000/03/13 15:58:24 reinelt Exp $ +/* $Id: lcd4linux.c,v 1.4 2000/03/17 09:21:42 reinelt Exp $ * * LCD4Linux * @@ -20,6 +20,10 @@ * * * $Log: lcd4linux.c,v $ + * Revision 1.4 2000/03/17 09:21:42 reinelt + * + * various memory statistics added + * * Revision 1.3 2000/03/13 15:58:24 reinelt * * release 0.9 @@ -51,6 +55,7 @@ double overload; int tick, tack, tau; int rows, cols, xres, yres, supported_bars; +struct { int total, used, free, shared, buffer, cache, apps; } ram; struct { double load1, load2, load3, overload; } load; struct { double user, nice, system, idle; } busy; struct { int read, write, total, max, peak; } disk; @@ -65,8 +70,12 @@ static void usage(void) static void collect_data (void) { - Busy (&busy.user, &busy.nice, &busy.system, &busy.idle); + Ram (&ram.total, &ram.free, &ram.shared, &ram.buffer, &ram.cache); + ram.used=ram.total-ram.free; + ram.apps=ram.used-ram.buffer-ram.cache; + Load (&load.load1, &load.load2, &load.load3); + Busy (&busy.user, &busy.nice, &busy.system, &busy.idle); Disk (&disk.read, &disk.write); disk.total=disk.read+disk.write; @@ -88,6 +97,21 @@ static double query (int token) { switch (token) { + case T_MEM_TOTAL: + return ram.total; + case T_MEM_USED: + return ram.used; + case T_MEM_FREE: + return ram.free; + case T_MEM_SHARED: + return ram.shared; + case T_MEM_BUFFER: + return ram.buffer; + case T_MEM_CACHE: + return ram.cache; + case T_MEM_APP: + return ram.apps; + case T_LOAD_1: return load.load1; case T_LOAD_2: @@ -151,6 +175,16 @@ static double query_bar (int token) double value=query(token); switch (token) { + + case T_MEM_TOTAL: + case T_MEM_USED: + case T_MEM_FREE: + case T_MEM_SHARED: + case T_MEM_BUFFER: + case T_MEM_CACHE: + case T_MEM_APP: + return value/ram.total; + case T_LOAD_1: case T_LOAD_2: case T_LOAD_3: @@ -207,6 +241,15 @@ void print_token (int token, char **p) case T_OVERLOAD: *(*p)++=load.load1>load.overload?'!':' '; break; + case T_MEM_TOTAL: + case T_MEM_USED: + case T_MEM_FREE: + case T_MEM_SHARED: + case T_MEM_BUFFER: + case T_MEM_CACHE: + case T_MEM_APP: + *p+=sprintf (*p, "%6.0f", query(token)); + break; case T_CPU_USER: case T_CPU_NICE: case T_CPU_SYSTEM: @@ -247,9 +290,13 @@ char *process_row (int r, char *s) val2=val1; lcd_bar (type, r, p-buffer+1, len*xres, val1*len*xres, val2*len*xres); - for (i=0; i<len && p-buffer<cols; i++) + if (type & BAR_H) { + for (i=0; i<len && p-buffer<cols; i++) + *p++='\t'; + } else { *p++='\t'; - + } + } else { *p++=*s; } diff --git a/lcd4linux.conf.sample b/lcd4linux.conf.sample index 4970c9b..799dc35 100644 --- a/lcd4linux.conf.sample +++ b/lcd4linux.conf.sample @@ -3,23 +3,34 @@ Port /dev/ttyS2 Speed 19200 Contrast 160 -#Row1 "*** %o %r ***" -#Row2 "%p CPU %m MB RAM" -#Row3 "Busy %cu%% $r10cs" +#Row1 "*** %o %v ***" +#Row2 "%p CPU %r MB RAM" +#Row3 "Busy %cu%% $r10cs+cb" #Row4 "Load %l1%L$r10l1" -Row1 "Busy %cb%% $r10cs+cb" -Row2 "Disk %dm $R10dr+dw" +Row1 "CPU %cu%% $r10cs+cb" +Row2 "%mf %ms %ma" +#Row2 "Disk %dm $R10dr+dw" Row3 "Net %nm $R10nr+nw" Row4 "ISDN %im $r10ii+io" +#Row1 "CPU $l6cs+cb$R6dr+dw I/O" +#Row2 "I/O $R16dr+dw" +#Row3 "LAN $R16nr+nw" +#Row4 "WAN $r16ii+io" + +#Row1 "" +#Row2 "" +#Row3 "$u3cs $u3cb " +#Row4 "CPU I/O LAN WAN" + Tick 100 Tack 400 Tau 500 Overload 2.0 -Fifo /var/run/lcd4linux - Sensor1 /proc/sys/dev/sensors/w83781d-isa-0290/temp2 Sensor1_min 30 Sensor1_max 50 + +Fifo /var/run/lcd4linux @@ -1,4 +1,4 @@ -/* $Id: parser.c,v 1.1 2000/03/13 15:58:24 reinelt Exp $ +/* $Id: parser.c,v 1.2 2000/03/17 09:21:42 reinelt Exp $ * * row definition parser * @@ -20,6 +20,10 @@ * * * $Log: parser.c,v $ + * Revision 1.2 2000/03/17 09:21:42 reinelt + * + * various memory statistics added + * * Revision 1.1 2000/03/13 15:58:24 reinelt * * release 0.9 @@ -53,9 +57,16 @@ typedef struct { static SYMTAB Symtab[] = {{ "%", T_PERCENT, 0 }, { "$", T_DOLLAR, 0 }, { "o", T_OS, 0 }, - { "r", T_RELEASE, 0 }, + { "v", T_RELEASE, 0 }, { "p", T_CPU, 0 }, - { "m", T_RAM, 0 }, + { "r", T_RAM, 0 }, + { "mt", T_MEM_TOTAL, 1 }, + { "mu", T_MEM_USED, 1 }, + { "mf", T_MEM_FREE, 1 }, + { "ms", T_MEM_SHARED, 1 }, + { "mb", T_MEM_BUFFER, 1 }, + { "mc", T_MEM_CACHE, 1 }, + { "ma", T_MEM_APP, 1 }, { "l1", T_LOAD_1, 1 }, { "l2", T_LOAD_2, 1 }, { "l3", T_LOAD_3, 1 }, @@ -128,10 +139,9 @@ char *parse (char *string, int supported_bars) do { switch (*s) { - + case '%': - if ((token=get_token (s+1, &s, 0))==-1) { - s++; + if ((token=get_token (++s, &s, 0))==-1) { fprintf (stderr, "WARNING: unknown token <%%%c> in <%s>\n", *s, string); } else { *p++='%'; @@ -192,7 +202,7 @@ char *parse (char *string, int supported_bars) fprintf (stderr, "WARNING: illegal '\\' in <%s>\n", string); } else { *p++=c; - s+=n; + s+=n-1; } } break; @@ -202,7 +212,8 @@ char *parse (char *string, int supported_bars) } } while (*s); - + + *p='\0'; return buffer; } @@ -1,4 +1,4 @@ -/* $Id: parser.h,v 1.1 2000/03/13 15:58:24 reinelt Exp $ +/* $Id: parser.h,v 1.2 2000/03/17 09:21:42 reinelt Exp $ * * row definition parser * @@ -20,6 +20,10 @@ * * * $Log: parser.h,v $ + * Revision 1.2 2000/03/17 09:21:42 reinelt + * + * various memory statistics added + * * Revision 1.1 2000/03/13 15:58:24 reinelt * * release 0.9 @@ -34,6 +38,7 @@ typedef enum { T_PERCENT=128, T_DOLLAR, T_OS, T_RELEASE, T_CPU, T_RAM, + T_MEM_TOTAL, T_MEM_USED, T_MEM_FREE, T_MEM_SHARED, T_MEM_BUFFER, T_MEM_CACHE, T_MEM_APP, T_LOAD_1, T_LOAD_2, T_LOAD_3, T_OVERLOAD, T_CPU_USER, T_CPU_NICE, T_CPU_SYSTEM, T_CPU_BUSY, T_CPU_IDLE, T_DISK_READ, T_DISK_WRITE, T_DISK_TOTAL, T_DISK_MAX, @@ -1,4 +1,4 @@ -/* $Id: system.c,v 1.5 2000/03/10 17:36:02 reinelt Exp $ +/* $Id: system.c,v 1.6 2000/03/17 09:21:42 reinelt Exp $ * * system status retreivement * @@ -20,6 +20,10 @@ * * * $Log: system.c,v $ + * Revision 1.6 2000/03/17 09:21:42 reinelt + * + * various memory statistics added + * * Revision 1.5 2000/03/10 17:36:02 reinelt * * first unstable but running release @@ -54,6 +58,10 @@ * int Memory (void); * returns main memory (Megabytes) * + * int Ram (int *total, int *free, int *shared, int *buffer, int *cached) + * sets various usage of ram + * retuns 0 if ok, -1 on error + * * int Load (double *load1, double *load2, double *load3) * sets load average during thwe last 1, 5 and 15 minutes * retuns 0 if ok, -1 on error @@ -94,6 +102,28 @@ #include "cfg.h" #include "filter.h" +#ifdef USE_SYSINFO +#include <linux/kernel.h> +#include <linux/sys.h> +#endif + +static unsigned long parse_meminfo (char *tag, char *buffer) +{ + char *p; + unsigned long val; + + p=strstr(buffer, tag); + if (p==NULL) { + fprintf (stderr, "parse(/proc/meminfo) failed: no %s line\n", tag); + return -1; + } + if (sscanf(p+strlen(tag), "%lu", &val)<1) { + fprintf (stderr, "scanf(/proc/meminfo) failed\n"); + return -1; + } + return val; +} + char *System(void) { static char buffer[32]=""; @@ -126,7 +156,6 @@ char *Release(void) return buffer; } - char *Processor(void) { static char buffer[16]=""; @@ -143,7 +172,6 @@ char *Processor(void) return buffer; } - int Memory(void) { static int value=-1; @@ -160,6 +188,69 @@ int Memory(void) return value; } +int Ram (int *total, int *free, int *shared, int *buffered, int *cached) +{ + static int fd=-2; + unsigned long v1, v2, v3, v4, v5; + char buffer[4096]; + + *total=0; + *free=0; + *shared=0; + *buffered=0; + *cached=0; + + if (fd==-1) return -1; + + if (fd==-2) { + fd = open("/proc/meminfo", O_RDONLY | O_NDELAY); + if (fd==-1) { + perror ("open(/proc/meminfo) failed"); + return -1; + } + } + + if (lseek(fd, 0L, SEEK_SET)!=0) { + perror ("lseek(/proc/meminfo) failed"); + fd=-1; + return -1; + } + if (read (fd, &buffer, sizeof(buffer)-1)==-1) { + perror ("read(/proc/meminfo) failed"); + fd=-1; + return -1; + } + + if ((v1=parse_meminfo ("MemTotal:", buffer))<0) { + fd=-1; + return -1; + } + if ((v2=parse_meminfo ("MemFree:", buffer))<0) { + fd=-1; + return -1; + } + if ((v3=parse_meminfo ("MemShared:", buffer))<0) { + fd=-1; + return -1; + } + if ((v4=parse_meminfo ("Buffers:", buffer))<0) { + fd=-1; + return -1; + } + if ((v5=parse_meminfo ("Cached:", buffer))<0) { + fd=-1; + return -1; + } + + *total=v1; + *free=v2; + *shared=v3; + *buffered=v4; + *cached=v5; + + return 0; + +} int Load (double *load1, double *load2, double *load3) { @@ -169,7 +260,7 @@ int Load (double *load1, double *load2, double *load3) static double val2=0; static double val3=0; static time_t now=0; - + *load1=val1; *load2=val2; *load3=val3; @@ -209,7 +300,6 @@ int Load (double *load1, double *load2, double *load3) return 0; } - int Busy (double *user, double *nice, double *system, double *idle) { static int fd=-2; @@ -262,7 +352,6 @@ int Busy (double *user, double *nice, double *system, double *idle) return 0; } - int Disk (int *r, int *w) { char buffer[4096], *p; @@ -322,7 +411,6 @@ int Disk (int *r, int *w) return 0; } - int Net (int *rx, int *tx) { char buffer[4096], *p, *s; @@ -369,7 +457,6 @@ int Net (int *rx, int *tx) return 0; } - int Sensor (int index, double *val, double *min, double *max) { char buffer[32]; @@ -1,4 +1,4 @@ -/* $Id: system.h,v 1.4 2000/03/10 17:36:02 reinelt Exp $ +/* $Id: system.h,v 1.5 2000/03/17 09:21:42 reinelt Exp $ * * system status retreivement * @@ -20,6 +20,10 @@ * * * $Log: system.h,v $ + * Revision 1.5 2000/03/17 09:21:42 reinelt + * + * various memory statistics added + * * Revision 1.4 2000/03/10 17:36:02 reinelt * * first unstable but running release @@ -32,7 +36,6 @@ * * minor cleanups * - * */ #ifndef _SYSTEM_H_ @@ -44,6 +47,7 @@ char *System (void); char *Release (void); char *Processor (void); int Memory (void); +int Ram (int *total, int *free, int *shared, int *buffered, int *cached); int Load (double *load1, double *load2, double *load3); int Busy (double *user, double *nice, double *system, double *idle); int Disk (int *r, int *w); |