From c716d0fbdfbe92583592a46c99e5f8d87d34bb68 Mon Sep 17 00:00:00 2001 From: reinelt <> Date: Sat, 18 Mar 2000 10:31:06 +0000 Subject: [lcd4linux @ 2000-03-18 10:31:06 by reinelt] added sensor handling (for temperature etc.) made data collecting happen only if data is used (reading /proc/meminfo takes a lot of CPU!) released lcd4linux-0.92 --- configure | 68 +++++++++++++++------------- configure.in | 5 +-- lcd4linux.c | 99 +++++++++++++++++++++++++++++++---------- lcd4linux.conf.sample | 21 +++++++-- parser.c | 121 +++++++++++++++++++++++++++----------------------- parser.h | 17 +++++-- 6 files changed, 211 insertions(+), 120 deletions(-) diff --git a/configure b/configure index 9c0547a..89cc8de 100755 --- a/configure +++ b/configure @@ -691,7 +691,7 @@ fi PACKAGE=lcd4linux -VERSION=0.91 +VERSION=0.92 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; } @@ -997,9 +997,9 @@ else fi -echo $ac_n "checking for main in -lm""... $ac_c" 1>&6 -echo "configure:1002: checking for main in -lm" >&5 -ac_lib_var=`echo m'_'main | sed 'y%./+-%__p_%'` +echo $ac_n "checking for log in -lm""... $ac_c" 1>&6 +echo "configure:1002: checking for log in -lm" >&5 +ac_lib_var=`echo m'_'log | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -1008,12 +1008,16 @@ LIBS="-lm $LIBS" cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1021: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -1042,7 +1046,7 @@ fi echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6 -echo "configure:1046: checking how to run the C preprocessor" >&5 +echo "configure:1050: checking how to run the C preprocessor" >&5 # On Suns, sometimes $CPP names a directory. if test -n "$CPP" && test -d "$CPP"; then CPP= @@ -1057,13 +1061,13 @@ else # On the NeXT, cc -E runs the code through the compiler's parser, # not just through cpp. cat > conftest.$ac_ext < Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1067: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1071: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then : @@ -1074,13 +1078,13 @@ else rm -rf conftest* CPP="${CC-cc} -E -traditional-cpp" cat > conftest.$ac_ext < Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1084: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1088: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then : @@ -1091,13 +1095,13 @@ else rm -rf conftest* CPP="${CC-cc} -nologo -E" cat > conftest.$ac_ext < Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1101: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1105: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then : @@ -1122,12 +1126,12 @@ fi echo "$ac_t""$CPP" 1>&6 echo $ac_n "checking for ANSI C header files""... $ac_c" 1>&6 -echo "configure:1126: checking for ANSI C header files" >&5 +echo "configure:1130: checking for ANSI C header files" >&5 if eval "test \"`echo '$''{'ac_cv_header_stdc'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < #include @@ -1135,7 +1139,7 @@ else #include EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1139: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1143: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then rm -rf conftest* @@ -1152,7 +1156,7 @@ rm -f conftest* if test $ac_cv_header_stdc = yes; then # SunOS 4.x string.h does not declare mem*, contrary to ANSI. cat > conftest.$ac_ext < EOF @@ -1170,7 +1174,7 @@ fi if test $ac_cv_header_stdc = yes; then # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. cat > conftest.$ac_ext < EOF @@ -1191,7 +1195,7 @@ if test "$cross_compiling" = yes; then : else cat > conftest.$ac_ext < #define ISLOWER(c) ('a' <= (c) && (c) <= 'z') @@ -1202,7 +1206,7 @@ if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) exit(2); exit (0); } EOF -if { (eval echo configure:1206: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null +if { (eval echo configure:1210: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext} && (./conftest; exit) 2>/dev/null then : else @@ -1229,17 +1233,17 @@ for ac_hdr in fcntl.h sys/ioctl.h sys/time.h unistd.h do ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 -echo "configure:1233: checking for $ac_hdr" >&5 +echo "configure:1237: checking for $ac_hdr" >&5 if eval "test \"`echo '$''{'ac_cv_header_$ac_safe'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:1243: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +{ (eval echo configure:1247: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` if test -z "$ac_err"; then rm -rf conftest* @@ -1267,12 +1271,12 @@ done echo $ac_n "checking whether time.h and sys/time.h may both be included""... $ac_c" 1>&6 -echo "configure:1271: checking whether time.h and sys/time.h may both be included" >&5 +echo "configure:1275: checking whether time.h and sys/time.h may both be included" >&5 if eval "test \"`echo '$''{'ac_cv_header_time'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < #include @@ -1281,7 +1285,7 @@ int main() { struct tm *tp; ; return 0; } EOF -if { (eval echo configure:1285: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then +if { (eval echo configure:1289: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then rm -rf conftest* ac_cv_header_time=yes else @@ -1304,13 +1308,13 @@ fi if test $ac_cv_prog_gcc = yes; then echo $ac_n "checking whether ${CC-cc} needs -traditional""... $ac_c" 1>&6 -echo "configure:1308: checking whether ${CC-cc} needs -traditional" >&5 +echo "configure:1312: checking whether ${CC-cc} needs -traditional" >&5 if eval "test \"`echo '$''{'ac_cv_prog_gcc_traditional'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else ac_pattern="Autoconf.*'x'" cat > conftest.$ac_ext < Autoconf TIOCGETP @@ -1328,7 +1332,7 @@ rm -f conftest* if test $ac_cv_prog_gcc_traditional = no; then cat > conftest.$ac_ext < Autoconf TCGETA @@ -1352,12 +1356,12 @@ fi for ac_func in gettimeofday strdup strerror strstr strtol uname do echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 -echo "configure:1356: checking for $ac_func" >&5 +echo "configure:1360: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:1388: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else diff --git a/configure.in b/configure.in index bac7539..b195cb6 100644 --- a/configure.in +++ b/configure.in @@ -1,13 +1,12 @@ dnl Process this file with autoconf to produce a configure script. AC_INIT(lcd4linux.c) -AM_INIT_AUTOMAKE(lcd4linux, 0.91) +AM_INIT_AUTOMAKE(lcd4linux, 0.92) dnl Checks for programs. AC_PROG_CC dnl Checks for libraries. -dnl Replace `main' with a function in -lm: -AC_CHECK_LIB(m, main) +AC_CHECK_LIB(m, log) dnl Checks for header files. AC_HEADER_STDC diff --git a/lcd4linux.c b/lcd4linux.c index 9797d9e..f006f97 100644 --- a/lcd4linux.c +++ b/lcd4linux.c @@ -1,4 +1,4 @@ -/* $Id: lcd4linux.c,v 1.5 2000/03/18 08:07:04 reinelt Exp $ +/* $Id: lcd4linux.c,v 1.6 2000/03/18 10:31:06 reinelt Exp $ * * LCD4Linux * @@ -20,6 +20,13 @@ * * * $Log: lcd4linux.c,v $ + * Revision 1.6 2000/03/18 10:31:06 reinelt + * + * added sensor handling (for temperature etc.) + * made data collecting happen only if data is used + * (reading /proc/meminfo takes a lot of CPU!) + * released lcd4linux-0.92 + * * Revision 1.5 2000/03/18 08:07:04 reinelt * * vertical bars implemented @@ -60,12 +67,15 @@ double overload; int tick, tack, tau; int rows, cols, xres, yres, supported_bars; +int token_usage[256]={0,}; + 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; struct { int rx, tx, total, max, peak; } net; struct { int usage, in, out, total, max, peak; } isdn; +struct { double val, min, max; } sensor[SENSORS]; static void usage(void) { @@ -75,27 +85,48 @@ static void usage(void) static void collect_data (void) { - 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; + int i; - 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; - disk.max=disk.read>disk.write?disk.read:disk.write; - if (disk.max>disk.peak) disk.peak=disk.max; + if (token_usage[C_MEM]) { + 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; + } + + if (token_usage[C_LOAD]) { + Load (&load.load1, &load.load2, &load.load3); + } + + if (token_usage[C_CPU]) { + Busy (&busy.user, &busy.nice, &busy.system, &busy.idle); + } + + if (token_usage[C_DISK]) { + Disk (&disk.read, &disk.write); + disk.total=disk.read+disk.write; + disk.max=disk.read>disk.write?disk.read:disk.write; + if (disk.max>disk.peak) disk.peak=disk.max; + } + + if (token_usage[C_NET]) { + Net (&net.rx, &net.tx); + net.total=net.rx+net.tx; + net.max=net.rx>net.tx?net.rx:net.tx; + if (net.max>net.peak) net.peak=net.max; + } - Net (&net.rx, &net.tx); - net.total=net.rx+net.tx; - net.max=net.rx>net.tx?net.rx:net.tx; - if (net.max>net.peak) net.peak=net.max; + if (token_usage[C_ISDN]) { + Isdn (&isdn.in, &isdn.out, &isdn.usage); + isdn.total=isdn.in+isdn.out; + isdn.max=isdn.in>isdn.out?isdn.in:isdn.out; + if (isdn.max>isdn.peak) isdn.peak=isdn.max; + } - Isdn (&isdn.in, &isdn.out, &isdn.usage); - isdn.total=isdn.in+isdn.out; - isdn.max=isdn.in>isdn.out?isdn.in:isdn.out; - if (isdn.max>isdn.peak) isdn.peak=isdn.max; + for (i=1; i @@ -51,54 +60,54 @@ typedef struct { char *symbol; TOKEN token; + CLASS class; int bar; } SYMTAB; -static SYMTAB Symtab[] = {{ "%", T_PERCENT, 0 }, - { "$", T_DOLLAR, 0 }, - { "o", T_OS, 0 }, - { "v", T_RELEASE, 0 }, - { "p", T_CPU, 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 }, - { "L", T_OVERLOAD, 0 }, - { "cu", T_CPU_USER, 1 }, - { "cn", T_CPU_NICE, 1 }, - { "cs", T_CPU_SYSTEM, 1 }, - { "cb", T_CPU_BUSY, 1 }, - { "ci", T_CPU_IDLE, 1 }, - { "dr", T_DISK_READ, 1 }, - { "dw", T_DISK_WRITE, 1 }, - { "dt", T_DISK_TOTAL, 1 }, - { "dm", T_DISK_MAX, 1 }, - { "nr", T_NET_RX, 1 }, - { "nw", T_NET_TX, 1 }, - { "nt", T_NET_TOTAL, 1 }, - { "nm", T_NET_MAX, 1 }, - { "ii", T_ISDN_IN, 1 }, - { "io", T_ISDN_OUT, 1 }, - { "it", T_ISDN_TOTAL, 1 }, - { "im", T_ISDN_MAX, 1 }, - { "s1", T_SENSOR_1, 1 }, - { "s1", T_SENSOR_2, 1 }, - { "s2", T_SENSOR_3, 1 }, - { "s3", T_SENSOR_4, 1 }, - { "s4", T_SENSOR_5, 1 }, - { "s5", T_SENSOR_6, 1 }, - { "s6", T_SENSOR_7, 1 }, - { "s7", T_SENSOR_8, 1 }, - { "s8", T_SENSOR_9, 1 }, - { "", -1 }}; - +static SYMTAB Symtab[] = {{ "%", T_PERCENT, C_GENERIC, 0 }, + { "$", T_DOLLAR, C_GENERIC, 0 }, + { "o", T_OS, C_GENERIC, 0 }, + { "v", T_RELEASE, C_GENERIC, 0 }, + { "p", T_CPU, C_GENERIC, 0 }, + { "r", T_RAM, C_GENERIC, 0 }, + { "mt", T_MEM_TOTAL, C_MEM, 1 }, + { "mu", T_MEM_USED, C_MEM, 1 }, + { "mf", T_MEM_FREE, C_MEM, 1 }, + { "ms", T_MEM_SHARED, C_MEM, 1 }, + { "mb", T_MEM_BUFFER, C_MEM, 1 }, + { "mc", T_MEM_CACHE, C_MEM, 1 }, + { "ma", T_MEM_APP, C_MEM, 1 }, + { "l1", T_LOAD_1, C_LOAD, 1 }, + { "l2", T_LOAD_2, C_LOAD, 1 }, + { "l3", T_LOAD_3, C_LOAD, 1 }, + { "L", T_OVERLOAD, C_LOAD, 0 }, + { "cu", T_CPU_USER, C_CPU, 1 }, + { "cn", T_CPU_NICE, C_CPU, 1 }, + { "cs", T_CPU_SYSTEM, C_CPU, 1 }, + { "cb", T_CPU_BUSY, C_CPU, 1 }, + { "ci", T_CPU_IDLE, C_CPU, 1 }, + { "dr", T_DISK_READ, C_DISK, 1 }, + { "dw", T_DISK_WRITE, C_DISK, 1 }, + { "dt", T_DISK_TOTAL, C_DISK, 1 }, + { "dm", T_DISK_MAX, C_DISK, 1 }, + { "nr", T_NET_RX, C_NET, 1 }, + { "nw", T_NET_TX, C_NET, 1 }, + { "nt", T_NET_TOTAL, C_NET, 1 }, + { "nm", T_NET_MAX, C_NET, 1 }, + { "ii", T_ISDN_IN, C_ISDN, 1 }, + { "io", T_ISDN_OUT, C_ISDN, 1 }, + { "it", T_ISDN_TOTAL, C_ISDN, 1 }, + { "im", T_ISDN_MAX, C_ISDN, 1 }, + { "s1", T_SENSOR_1, C_SENSOR, 1 }, + { "s2", T_SENSOR_2, C_SENSOR, 1 }, + { "s3", T_SENSOR_3, C_SENSOR, 1 }, + { "s4", T_SENSOR_4, C_SENSOR, 1 }, + { "s5", T_SENSOR_5, C_SENSOR, 1 }, + { "s6", T_SENSOR_6, C_SENSOR, 1 }, + { "s7", T_SENSOR_7, C_SENSOR, 1 }, + { "s8", T_SENSOR_8, C_SENSOR, 1 }, + { "s9", T_SENSOR_9, C_SENSOR, 1 }, + { "", -1, 0 }}; static int bar_type (char tag) { @@ -116,7 +125,7 @@ static int bar_type (char tag) } } -static TOKEN get_token (char *s, char **p, int bar) +static TOKEN get_token (char *s, char **p, int bar, int usage[]) { int i; for (i=0; Symtab[i].token!=-1; i++) { @@ -124,24 +133,27 @@ static TOKEN get_token (char *s, char **p, int bar) if (bar && !Symtab[i].bar) continue; if (strncmp(Symtab[i].symbol, s, l)==0) { *p=s+l; + usage[Symtab[i].token]++; + usage[Symtab[i].class]++; return Symtab[i].token; } } return -1; } -char *parse (char *string, int supported_bars) +char *parse (char *string, int supported_bars, int usage[]) { static char buffer[256]; char *s=string; char *p=buffer; - int token, token2, type, len; + TOKEN token, token2; + int type, len; do { switch (*s) { case '%': - if ((token=get_token (++s, &s, 0))==-1) { + if ((token=get_token (++s, &s, 0, usage))==-1) { fprintf (stderr, "WARNING: unknown token <%%%c> in <%s>\n", *s, string); } else { *p++='%'; @@ -165,7 +177,7 @@ char *parse (char *string, int supported_bars) fprintf (stderr, "WARNING: invalid bar length in <%s>\n", string); break; } - if ((token=get_token (s, &s, 0))==-1) { + if ((token=get_token (s, &s, 0, usage))==-1) { fprintf (stderr, "WARNING: unknown token <$%c> in <%s>\n", *s, string); break; } @@ -179,7 +191,7 @@ char *parse (char *string, int supported_bars) fprintf (stderr, "WARNING: driver does not support double bars\n"); break; } - if ((token2=get_token (s+1, &s, 0))==-1) { + if ((token2=get_token (s+1, &s, 0, usage))==-1) { fprintf (stderr, "WARNING: unknown token <$%c> in <%s>\n", *s, string); break; } @@ -202,7 +214,7 @@ char *parse (char *string, int supported_bars) fprintf (stderr, "WARNING: illegal '\\' in <%s>\n", string); } else { *p++=c; - s+=n-1; + s+=n+1; } } break; @@ -216,4 +228,3 @@ char *parse (char *string, int supported_bars) *p='\0'; return buffer; } - diff --git a/parser.h b/parser.h index fbef9f9..8f42218 100644 --- a/parser.h +++ b/parser.h @@ -1,4 +1,4 @@ -/* $Id: parser.h,v 1.2 2000/03/17 09:21:42 reinelt Exp $ +/* $Id: parser.h,v 1.3 2000/03/18 10:31:06 reinelt Exp $ * * row definition parser * @@ -20,6 +20,13 @@ * * * $Log: parser.h,v $ + * Revision 1.3 2000/03/18 10:31:06 reinelt + * + * added sensor handling (for temperature etc.) + * made data collecting happen only if data is used + * (reading /proc/meminfo takes a lot of CPU!) + * released lcd4linux-0.92 + * * Revision 1.2 2000/03/17 09:21:42 reinelt * * various memory statistics added @@ -45,9 +52,13 @@ typedef enum { T_NET_RX, T_NET_TX, T_NET_TOTAL, T_NET_MAX, T_ISDN_IN, T_ISDN_OUT, T_ISDN_TOTAL, T_ISDN_MAX, T_SENSOR_1, T_SENSOR_2, T_SENSOR_3, T_SENSOR_4, T_SENSOR_5, - T_SENSOR_6, T_SENSOR_7, T_SENSOR_8, T_SENSOR_9, + T_SENSOR_6, T_SENSOR_7, T_SENSOR_8, T_SENSOR_9 } TOKEN; -char *parse (char *string, int supported_bars); +typedef enum { + C_GENERIC, C_MEM, C_LOAD, C_CPU, C_DISK, C_NET, C_ISDN, C_SENSOR +} CLASS; + +char *parse (char *string, int supported_bars, int usage[]); #endif -- cgit v1.2.3