From db5e3666b5a2e9d3e35ada41ebf0a1a2e0897e53 Mon Sep 17 00:00:00 2001 From: reinelt Date: Fri, 17 Mar 2000 09:21:42 +0000 Subject: [lcd4linux @ 2000-03-17 09:21:42 by reinelt] various memory statistics added git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@11 3ae390bd-cb1e-0410-b409-cd5a39f66f1f --- MatrixOrbital.c | 11 ++++-- configure | 2 +- configure.in | 2 +- display.c | 9 +++-- display.h | 7 +++- lcd4linux.c | 55 +++++++++++++++++++++++++-- lcd4linux.conf.sample | 25 ++++++++---- parser.c | 27 +++++++++---- parser.h | 7 +++- system.c | 103 ++++++++++++++++++++++++++++++++++++++++++++++---- 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; diff --git a/configure b/configure index 482de95..9c0547a 100755 --- a/configure +++ b/configure @@ -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 diff --git a/display.c b/display.c index e00f791..f7c5870 100644 --- a/display.c +++ b/display.c @@ -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) diff --git a/display.h b/display.h index 988389a..937d030 100644 --- a/display.h +++ b/display.h @@ -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 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; } diff --git a/parser.h b/parser.h index 959eb4d..fbef9f9 100644 --- a/parser.h +++ b/parser.h @@ -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, diff --git a/system.c b/system.c index bca5fd4..e29c2cb 100644 --- a/system.c +++ b/system.c @@ -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 +#include +#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]; diff --git a/system.h b/system.h index 50246e6..5cb5e0e 100644 --- a/system.h +++ b/system.h @@ -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); -- cgit v1.2.3