-/* $Id: drv_T6963.c,v 1.8 2004/06/09 06:40:29 reinelt Exp $
+/* $Id: drv_T6963.c,v 1.9 2004/06/17 06:23:39 reinelt Exp $
*
* new style driver for T6963-based displays
*
*
*
* $Log: drv_T6963.c,v $
+ * Revision 1.9 2004/06/17 06:23:39 reinelt
+ *
+ * hash handling rewritten to solve performance issues
+ *
* Revision 1.8 2004/06/09 06:40:29 reinelt
*
* splash screen for T6963 driver
#include "debug.h"
#include "cfg.h"
+#include "qprintf.h"
#include "udelay.h"
#include "plugin.h"
#include "widget.h"
-/* $Id: hash.c,v 1.20 2004/06/13 01:12:52 reinelt Exp $
+/* $Id: hash.c,v 1.21 2004/06/17 06:23:43 reinelt Exp $
*
* hashes (associative arrays)
*
*
*
* $Log: hash.c,v $
+ * Revision 1.21 2004/06/17 06:23:43 reinelt
+ *
+ * hash handling rewritten to solve performance issues
+ *
* Revision 1.20 2004/06/13 01:12:52 reinelt
*
* debug widgets changed (thanks to Andy Baxter)
/*
* exported functions:
*
- * void hash_set (HASH *Hash, char *key, char *val);
+ * void hash_create (HASH *Hash);
+ * initializes hash
+ *
+ * int hash_age (HASH *Hash, char *key, char **value);
+ * return time of last hash_put
+ *
+ * void hash_put (HASH *Hash, char *key, char *val);
* set an entry in the hash
*
- * void hash_set_delta (HASH *Hash, char *key, char *val);
+ * void hash_put_delta (HASH *Hash, char *key, char *val);
* set a delta entry in the hash
*
- * int hash_age (HASH *Hash, char *key, char **value);
- * return time of last hash_set
- *
* char *hash_get (HASH *Hash, char *key);
* fetch an entry from the hash
*
#define CHUNK_SIZE 16
-// bsearch compare function for hash entries
-static int hash_lookup_f (const void *a, const void *b)
+// initialize a new hash table
+void hash_create (HASH *Hash)
{
- char *key=(char*)a;
- HASH_ITEM *item=(HASH_ITEM*)b;
+ Hash->sorted = 0;
- return strcmp(key, item->key);
+ Hash->timestamp.tv_sec = 0;
+ Hash->timestamp.tv_usec = 0;
+
+ Hash->nItems = 0;
+ Hash->Items = NULL;
+
+ Hash->nColumns = 0;
+ Hash->Columns = NULL;
+
+ Hash->delimiter = strdup (" \t\n");
+}
+
+
+// bsearch compare function for hash items
+static int hash_lookup_item (const void *a, const void *b)
+{
+ char *key = (char*)a;
+ HASH_ITEM *item = (HASH_ITEM*)b;
+
+ return strcasecmp(key, item->key);
}
-// qsort compare function for hash tables
-static int hash_sort_f (const void *a, const void *b)
+// qsort compare function for hash items
+static int hash_sort_item (const void *a, const void *b)
{
- HASH_ITEM *ha=(HASH_ITEM*)a;
- HASH_ITEM *hb=(HASH_ITEM*)b;
+ HASH_ITEM *ha = (HASH_ITEM*)a;
+ HASH_ITEM *hb = (HASH_ITEM*)b;
return strcasecmp(ha->key, hb->key);
}
+// bsearch compare function for hash headers
+static int hash_lookup_column (const void *a, const void *b)
+{
+ char *key = (char*)a;
+ HASH_COLUMN *column = (HASH_COLUMN*)b;
+
+ return strcasecmp(key, column->key);
+}
+
+
+// qsort compare function for hash headers
+static int hash_sort_column (const void *a, const void *b)
+{
+ HASH_COLUMN *ha = (HASH_COLUMN*)a;
+ HASH_COLUMN *hb = (HASH_COLUMN*)b;
+
+ return strcasecmp(ha->key, hb->key);
+}
+
+
+// split a value into columns and
+// return the nth column in a string
+// WARNING: does return a pointer to a static string!!
+static char* split (const char *val, int column, const char *delimiter)
+{
+ static char buffer[256];
+ int num, len;
+ const char *beg, *end;
+
+ if (column < 0) return (char*)val;
+ if (val == NULL) return NULL;
+
+ num = 0;
+ len = 0;
+ beg = val;
+ end = beg;
+ while (beg && *beg) {
+ while (strchr(delimiter, *beg)) beg++;
+ end = strpbrk (beg, delimiter);
+ if (num++ == column) break;
+ beg = end ? end+1 : NULL;
+ }
+ if (beg != NULL) {
+ len = end ? end - beg : strlen(beg);
+ if (len >= sizeof(buffer)) len = sizeof(buffer)-1;
+ strncpy (buffer, beg, len);
+ }
+
+ buffer[len] = '\0';
+ return buffer;
+}
+
+
// search an entry in the hash table:
// If the table is flagged "sorted", the entry is looked
// up using the bsearch function. If the table is
// unsorted, it will be searched in a linear way
-
-static HASH_ITEM* hash_lookup (HASH *Hash, char *key, int sortit)
+static HASH_ITEM* hash_lookup (HASH *Hash, const char *key, int do_sort)
{
- HASH_ITEM *Item=NULL;
+ HASH_ITEM *Item = NULL;
// maybe sort the array
- if (sortit && !Hash->sorted) {
- qsort(Hash->Items, Hash->nItems, sizeof(HASH_ITEM), hash_sort_f);
- Hash->sorted=1;
+ if (do_sort && !Hash->sorted) {
+ qsort(Hash->Items, Hash->nItems, sizeof(HASH_ITEM), hash_sort_item);
+ Hash->sorted = 1;
}
// no key was passed
- if (key==NULL) return NULL;
+ if (key == NULL) return NULL;
// lookup using bsearch
if (Hash->sorted) {
- Item=bsearch(key, Hash->Items, Hash->nItems, sizeof(HASH_ITEM), hash_lookup_f);
+ Item = bsearch(key, Hash->Items, Hash->nItems, sizeof(HASH_ITEM), hash_lookup_item);
}
// linear search
- if (Item==NULL) {
+ if (Item == NULL) {
int i;
- for (i=0;i<Hash->nItems; i++) {
- if (strcmp(key, Hash->Items[i].key)==0) {
- Item=&(Hash->Items[i]);
+ for (i = 0; i < Hash->nItems; i++) {
+ if (strcmp(key, Hash->Items[i].key) == 0) {
+ Item = &(Hash->Items[i]);
break;
}
}
}
-// insert a key/val pair into the hash table
-// If the entry does already exist, it will be overwritten,
-// and the table stays sorted (if it has been before).
-// Otherwise, the entry is appended at the end, and
-// the table will be flagged 'unsorted' afterwards
-
-static HASH_ITEM* hash_set_string (HASH *Hash, char *key, char *val)
+// return the age in milliseconds of an entry from the hash table
+// or from the hash table itself if key is NULL
+// returns -1 if entry does not exist
+int hash_age (HASH *Hash, const char *key)
{
HASH_ITEM *Item;
- int len = strlen(val);
+ struct timeval now, *timestamp;
- Item = hash_lookup (Hash, key, 0);
-
- // entry already exists?
- if (Item != NULL) {
- if (len > Item->len) {
- // buffer is either empty or too small
- if (Item->val) free (Item->val);
- // allocate memory in multiples of CHUNK_SIZE
- // note that length does not count the trailing \0
- Item->len = CHUNK_SIZE*(len/CHUNK_SIZE+1)-1;
- Item->val = malloc(Item->len+1);
- }
- strcpy(Item->val, val);
- goto hash_got_string;
+ if (key == NULL) {
+ timestamp = &(Hash->timestamp);
+ } else {
+ Item = hash_lookup(Hash, key, 1);
+ if (Item == NULL) return -1;
+ timestamp = &(Item->Slot[Item->index].timestamp);
}
-
- // add entry
- Hash->sorted = 0;
- Hash->nItems++;
- Hash->Items = realloc(Hash->Items, Hash->nItems*sizeof(HASH_ITEM));
-
- Item = &(Hash->Items[Hash->nItems-1]);
- Item->key = strdup(key);
-
- Item->len = CHUNK_SIZE*(len/CHUNK_SIZE+1)-1;
- Item->val = malloc(Item->len+1);
- strcpy(Item->val, val);
+ gettimeofday(&now, NULL);
- Item->root = 0;
- Item->Slot = NULL;
-
- hash_got_string:
- // set timestamps
- gettimeofday(&Hash->time, NULL);
- Item->time = Hash->time;
-
- return Item;
+ return (now.tv_sec - timestamp->tv_sec)*1000 + (now.tv_usec - timestamp->tv_usec)/1000;
}
-// insert a string into the hash table
-void hash_set (HASH *Hash, char *key, char *val)
+// add an entry to the column header table
+void hash_set_column (HASH *Hash, int number, const char *column)
{
- hash_set_string (Hash, key, val);
+ if (Hash == NULL) return;
+
+ Hash->nColumns++;
+ Hash->Columns = realloc(Hash->Columns, Hash->nColumns * sizeof(HASH_COLUMN));
+ Hash->Columns[Hash->nColumns-1].key = strdup(column);
+ Hash->Columns[Hash->nColumns-1].val = number;
+
+ qsort(Hash->Columns, Hash->nColumns, sizeof(HASH_COLUMN), hash_sort_column);
+
}
-// insert a string into the hash table
-// convert it into a number, and store it in the
-// delta table, too
-void hash_set_delta (HASH *Hash, char *key, char *val)
+// fetch a column number by column header
+static int hash_get_column (HASH *Hash, const char *key)
{
- double number=atof(val);
- HASH_ITEM *Item;
-
- Item=hash_set_string (Hash, key, val);
-
- // allocate delta table
- if (Item->Slot==NULL) {
- Item->root = 0;
- Item->Slot = malloc(DELTA_SLOTS*sizeof(HASH_SLOT));
- memset(Item->Slot, 0, DELTA_SLOTS*sizeof(HASH_SLOT));
- }
-
- // move the pointer to the next free slot, wrap around if necessary
- if (--Item->root < 0) Item->root = DELTA_SLOTS-1;
+ HASH_COLUMN *Column;
- // set first entry
- gettimeofday(&(Item->Slot[Item->root].time), NULL);
- Item->Slot[Item->root].val=number;
+ if (key == NULL || *key == '\0') return -1;
+
+ Column = bsearch(key, Hash->Columns, Hash->nColumns, sizeof(HASH_COLUMN), hash_lookup_column);
+ if (Column == NULL) return -1;
+ return Column->val;
}
-// get a string from the hash table
-char *hash_get (HASH *Hash, char *key)
+// set column delimiters
+void hash_set_delimiter (HASH *Hash, const char *delimiter)
{
- HASH_ITEM *Item=hash_lookup(Hash, key, 1);
- return Item?Item->val:NULL;
+ if (Hash->delimiter != NULL) free (Hash->delimiter);
+ Hash->delimiter = strdup(delimiter);
}
-// return the age in milliseconds of an entry from the hash table
-// or from the hash table itself if key is NULL
-// returns -1 if entry does not exist
-// if **value is set, return the value, too
-int hash_age (HASH *Hash, char *key, char **value)
+// get a string from the hash table
+char *hash_get (HASH *Hash, const char *key, const char *column)
{
HASH_ITEM *Item;
- timeval now, *stamp;
- int age;
+ int c;
- if (key!=NULL) {
- Item=hash_lookup(Hash, key, 1);
- if (value) *value=Item?Item->val:NULL;
- if (Item==NULL) {
- return -1;
- }
- stamp=&Item->time;
- } else {
- stamp=&Hash->time;
- }
-
- gettimeofday(&now, NULL);
-
- age = (now.tv_sec - stamp->tv_sec)*1000 + (now.tv_usec - stamp->tv_usec)/1000;
+ Item = hash_lookup(Hash, key, 1);
+ if (Item == NULL) return NULL;
- return age;
+ c = hash_get_column(Hash, column);
+ return split(Item->Slot[Item->index].value, c, Hash->delimiter);
}
// get a delta value from the delta table
-double hash_get_delta (HASH *Hash, char *key, int delay)
+double hash_get_delta (HASH *Hash, const char *key, const char *column, int delay)
{
HASH_ITEM *Item;
- timeval now, end;
- int i;
+ HASH_SLOT *Slot1, *Slot2;
+ int i, c;
+ double v1, v2;
double dv, dt;
- HASH_SLOT *pSlot;
+ struct timeval now, end;
// lookup item
- Item=hash_lookup(Hash, key, 1);
- if (Item==NULL) return 0.0;
- if (Item->Slot==NULL) return 0.0;
+ Item = hash_lookup(Hash, key, 1);
+ if (Item == NULL) return 0.0;
+ // this is the "current" Slot
+ Slot1 = &(Item->Slot[Item->index]);
+
+ // fetch column number
+ c = hash_get_column(Hash, column);
+
// if delay is zero, return absolute value
- if (delay==0) return Item->Slot[Item->root].val;
+ if (delay == 0) return atof(split(Slot1->value, c, Hash->delimiter));
// prepare timing values
- now=Item->Slot[Item->root].time;
+ now = Slot1->timestamp;
end.tv_sec = now.tv_sec;
- end.tv_usec = now.tv_usec-1000*delay;
- if (end.tv_usec<0) {
+ end.tv_usec = now.tv_usec - 1000*delay;
+ while (end.tv_usec < 0) {
end.tv_sec--;
end.tv_usec += 1000000;
}
// search delta slot
- for (i=1; i<DELTA_SLOTS; i++) {
- pSlot = &(Item->Slot[(Item->root+i) % DELTA_SLOTS]);
- if (pSlot->time.tv_sec==0) break;
- if (timercmp(&(pSlot->time), &end, <)) break;
- dt = (now.tv_sec - pSlot->time.tv_sec) + (now.tv_usec - pSlot->time.tv_usec)/1000000.0;
+ Slot2 = &(Item->Slot[Item->index]);
+ for (i = 1; i < Item->nSlot; i++) {
+ Slot2 = &(Item->Slot[(Item->index + i) % Item->nSlot]);
+ if (Slot2->timestamp.tv_sec == 0) break;
+ if (timercmp(&(Slot2->timestamp), &end, <)) break;
}
-
- // empty slot => use the one before
- if (pSlot->time.tv_sec==0) {
+ // empty slot => try the one before
+ if (Slot2->timestamp.tv_sec == 0) {
i--;
- pSlot = &(Item->Slot[(Item->root+i) % DELTA_SLOTS]);
+ Slot2 = &(Item->Slot[(Item->index + i) % Item->nSlot]);
}
// not enough slots available...
- if (i==0) return 0.0;
+ if (i == 0) return 0.0;
// delta value, delta time
- dv = Item->Slot[Item->root].val - pSlot->val;
- dt = (now.tv_sec - pSlot->time.tv_sec) + (now.tv_usec - pSlot->time.tv_usec)/1000000.0;
+ v1 = atof(split(Slot1->value, c, Hash->delimiter));
+ v2 = atof(split(Slot2->value, c, Hash->delimiter));
+ dv = v1 - v2;
+ dt = (Slot1->timestamp.tv_sec - Slot2->timestamp.tv_sec)
+ + (Slot1->timestamp.tv_usec - Slot2->timestamp.tv_usec)/1000000.0;
if (dt > 0.0 && dv >= 0.0) return dv/dt;
return 0.0;
// get a delta value from the delta table
// key may contain regular expressions, and the sum
// of all matching entries is returned.
-double hash_get_regex (HASH *Hash, char *key, int delay)
+double hash_get_regex (HASH *Hash, const char *key, const char *column, int delay)
{
- double sum=0.0;
+ double sum;
regex_t preg;
int i, err;
- err=regcomp(&preg, key, REG_ICASE|REG_NOSUB);
- if (err!=0) {
+ err = regcomp(&preg, key, REG_ICASE|REG_NOSUB);
+ if (err != 0) {
char buffer[32];
regerror(err, &preg, buffer, sizeof(buffer));
error ("error in regular expression: %s", buffer);
regfree(&preg);
return 0.0;
}
-
+
// force the table to be sorted by requesting anything
hash_lookup(Hash, NULL, 1);
- for (i=0;i<Hash->nItems; i++) {
- if (regexec(&preg, Hash->Items[i].key, 0, NULL, 0)==0) {
- sum+=hash_get_delta(Hash, Hash->Items[i].key, delay);
+ sum = 0.0;
+ for (i = 0; i < Hash->nItems; i++) {
+ if (regexec(&preg, Hash->Items[i].key, 0, NULL, 0) == 0) {
+ sum += hash_get_delta(Hash, Hash->Items[i].key, column, delay);
}
}
regfree(&preg);
}
+// insert a key/val pair into the hash table
+// If the entry does already exist, it will be overwritten,
+// and the table stays sorted (if it has been before).
+// Otherwise, the entry is appended at the end, and
+// the table will be flagged 'unsorted' afterwards
+
+static HASH_ITEM* hash_set (HASH *Hash, const char *key, const char *value, int delta)
+{
+ HASH_ITEM *Item;
+ HASH_SLOT *Slot;
+ int size;
+
+ Item = hash_lookup (Hash, key, 0);
+
+ if (Item == NULL) {
+
+ // add entry
+ Hash->sorted = 0;
+ Hash->nItems++;
+ Hash->Items = realloc(Hash->Items, Hash->nItems * sizeof(HASH_ITEM));
+
+ Item = &(Hash->Items[Hash->nItems-1]);
+ Item->key = strdup(key);
+ Item->index = 0;
+ Item->nSlot = delta;
+ Item->Slot = malloc (Item->nSlot * sizeof(HASH_SLOT));
+ memset(Item->Slot, 0, Item->nSlot * sizeof(HASH_SLOT));
+
+ } else {
+
+ // maybe enlarge delta table
+ if (Item->nSlot < delta) {
+ Item->nSlot = delta;
+ Item->Slot = realloc (Item->Slot, Item->nSlot * sizeof(HASH_SLOT));
+ }
+
+ }
+
+ if (Item->nSlot > 1) {
+ // move the pointer to the next free slot, wrap around if necessary
+ if (--Item->index < 0) Item->index = Item->nSlot-1;
+ }
+
+ // create entry
+ Slot = &(Item->Slot[Item->index]);
+ size = strlen(value) + 1;
+
+ // maybe enlarge value buffer
+ if (size > Slot->size) {
+ // buffer is either empty or too small
+ // allocate memory in multiples of CHUNK_SIZE
+ Slot->size = CHUNK_SIZE * (size / CHUNK_SIZE + 1);
+ Slot->value = realloc(Slot->value, Slot->size);
+ }
+
+ // set value
+ strcpy(Slot->value, value);
+
+ // set timestamps
+ gettimeofday(&(Hash->timestamp), NULL);
+ Slot->timestamp = Hash->timestamp;
+
+ return Item;
+}
+
+
+// insert a string into the hash table
+// without delta processing
+void hash_put (HASH *Hash, const char *key, const char *value)
+{
+ hash_set (Hash, key, value, 1);
+}
+
+
+// insert a string into the hash table
+// with delta processing
+void hash_put_delta (HASH *Hash, const char *key, const char *value)
+{
+ hash_set (Hash, key, value, DELTA_SLOTS);
+}
+
+
void hash_destroy (HASH *Hash)
{
int i;
if (Hash->Items) {
- // free all entries
- for (i=0;i<Hash->nItems; i++) {
+ // free all headers
+ for (i = 0; i < Hash->nColumns; i++) {
+ if (Hash->Columns[i].key) free (Hash->Columns[i].key);
+ }
+
+ // free header table
+ free (Hash->Columns);
+
+ // free all items
+ for (i = 0; i < Hash->nItems; i++) {
if (Hash->Items[i].key) free (Hash->Items[i].key);
- if (Hash->Items[i].val) free (Hash->Items[i].val);
if (Hash->Items[i].Slot) free (Hash->Items[i].Slot);
}
- // free hash table
+ // free items table
free (Hash->Items);
}
- Hash->nItems=0;
- Hash->sorted=0;
- Hash->Items=NULL;
+ Hash->sorted = 0;
+ Hash->nItems = 0;
+ Hash->Items = NULL;
}
-/* $Id: hash.h,v 1.13 2004/06/13 01:12:52 reinelt Exp $
+/* $Id: hash.h,v 1.14 2004/06/17 06:23:43 reinelt Exp $
*
* hashes (associative arrays)
*
*
*
* $Log: hash.h,v $
+ * Revision 1.14 2004/06/17 06:23:43 reinelt
+ *
+ * hash handling rewritten to solve performance issues
+ *
* Revision 1.13 2004/06/13 01:12:52 reinelt
*
* debug widgets changed (thanks to Andy Baxter)
#ifndef _HASH_H_
#define _HASH_H_
-
+// struct timeval
#include <sys/time.h>
-typedef struct timeval timeval;
+
typedef struct {
- timeval time;
- double val;
+ int size;
+ char *value;
+ struct timeval timestamp;
} HASH_SLOT;
+typedef struct {
+ char *key;
+ int val;
+} HASH_COLUMN;
+
typedef struct {
char *key;
- char *val;
- int len;
- timeval time;
- int root;
+ int index;
+ int nSlot;
HASH_SLOT *Slot;
} HASH_ITEM;
typedef struct {
- int sorted;
- timeval time;
- int nItems;
- HASH_ITEM *Items;
+ int sorted;
+ struct timeval timestamp;
+ int nItems;
+ HASH_ITEM *Items;
+ int nColumns;
+ HASH_COLUMN *Columns;
+ char *delimiter;
} HASH;
-void hash_set (HASH *Hash, char *key, char *val);
-void hash_set_delta (HASH *Hash, char *key, char *val);
-int hash_age (HASH *Hash, char *key, char **value);
-char *hash_get (HASH *Hash, char *key);
-double hash_get_delta (HASH *Hash, char *key, int delay);
-double hash_get_regex (HASH *Hash, char *key, int delay);
-void hash_destroy (HASH *Hash);
+
+void hash_create (HASH *Hash);
+
+int hash_age (HASH *Hash, const char *key);
+
+void hash_set_column (HASH *Hash, int number, const char *column);
+void hash_set_delimiter (HASH *Hash, const char *delimiter);
+
+char *hash_get (HASH *Hash, const char *key, const char *column);
+double hash_get_delta (HASH *Hash, const char *key, const char *column, int delay);
+double hash_get_regex (HASH *Hash, const char *key, const char *column, int delay);
+
+void hash_put (HASH *Hash, const char *key, const char *value);
+void hash_put_delta (HASH *Hash, const char *key, const char *value);
+
+void hash_destroy (HASH *Hash);
+
#endif
class 'Text'
# disk.[rw]blk return blocks, we assume a blocksize of 512
# to get the number in kB/s we would do blk*512/1024, which is blk/2
- expression (proc_stat::disk('.*', 'rblk', 500)+proc_stat::disk('.*', 'wblk', 500))/2
+ # expression (proc_stat::disk('.*', 'rblk', 500)+proc_stat::disk('.*', 'wblk', 500))/2
# with kernel 2.6, disk_io disappeared from /proc/stat but moved to /proc/diskstat
# therefore you have to use another function called 'diskstats':
- #expression diskstats('.*', '.*_sectors', 500)
+ expression diskstats('.*', 'read_sectors', 500) + diskstats('.*', 'write_sectors', 500)
prefix 'disk'
postfix ' '
width 10
Widget DiskBar {
class 'Bar'
- expression proc_stat::disk('.*', 'rblk', 500)
- expression2 proc_stat::disk('.*', 'wblk', 500)
+ #expression proc_stat::disk('.*', 'rblk', 500)
+ #expression2 proc_stat::disk('.*', 'wblk', 500)
# for kernel 2.6:
- #expression diskstats('.*', 'read_sectors', 500)
- #expression2 diskstats('.*', 'write_sectors', 500)
+ expression diskstats('.*', 'read_sectors', 500)
+ expression2 diskstats('.*', 'write_sectors', 500)
length 14
direction 'E'
update tack
#Display 'CF631'
#Display 'CF632'
#Display 'CF633'
-#Display 'Curses'
+Display 'Curses'
#Display 'USBLCD'
-Display 'T6963-240x64'
+#Display 'T6963-240x64'
#Display 'XWindow'
#Display 'Image'
-/* $Id: plugin_apm.c,v 1.1 2004/03/14 07:11:42 reinelt Exp $
+/* $Id: plugin_apm.c,v 1.2 2004/06/17 06:23:43 reinelt Exp $
*
* plugin for APM (battery status)
*
*
*
* $Log: plugin_apm.c,v $
+ * Revision 1.2 2004/06/17 06:23:43 reinelt
+ *
+ * hash handling rewritten to solve performance issues
+ *
* Revision 1.1 2004/03/14 07:11:42 reinelt
* parameter count fixed for plugin_dvb()
* plugin_APM (battery status) ported
int age, i;
// reread every 10 msec only
- age = hash_age (&APM, NULL, NULL);
+ age = hash_age (&APM, NULL);
if (age > 0 && age <= 10) return 0;
if (fd == -2) {
for (i = 0; i < 9 && beg != NULL; i++) {
while (*beg == ' ') beg++;
if ((end = strpbrk(beg, " \n"))) *end='\0';
- hash_set (&APM, key[i], beg);
+ hash_put (&APM, key[i], beg);
beg = end ? end+1 : NULL;
}
-
return 0;
}
{
char *val;
- if (parse_proc_apm()<0) {
+ if (parse_proc_apm() < 0) {
SetResult(&result, R_STRING, "");
return;
}
- val=hash_get(&APM, R2S(arg1));
- if (val==NULL) val="";
+ val = hash_get(&APM, R2S(arg1), NULL);
+ if (val == NULL) val = "";
SetResult(&result, R_STRING, val);
}
int plugin_init_apm (void)
{
+ hash_create (&APM);
+
AddFunction ("apm", 1, my_apm);
+
return 0;
}
close (fd);
}
fd = -2;
+
hash_destroy(&APM);
}
-/* $Id: plugin_cpuinfo.c,v 1.9 2004/03/11 06:39:59 reinelt Exp $
+/* $Id: plugin_cpuinfo.c,v 1.10 2004/06/17 06:23:43 reinelt Exp $
*
* plugin for /proc/cpuinfo parsing
*
*
*
* $Log: plugin_cpuinfo.c,v $
+ * Revision 1.10 2004/06/17 06:23:43 reinelt
+ *
+ * hash handling rewritten to solve performance issues
+ *
* Revision 1.9 2004/03/11 06:39:59 reinelt
* big patch from Martin:
* - reuse filehandles
#include "hash.h"
-static HASH CPUinfo = { 0, };
+static HASH CPUinfo;
static FILE *stream = NULL;
static int parse_cpuinfo (void)
int age;
// reread every second only
- age=hash_age(&CPUinfo, NULL, NULL);
- if (age>0 && age<=1000) return 0;
+ age = hash_age(&CPUinfo, NULL);
+ if (age > 0 && age <= 1000) return 0;
- if (stream == NULL) stream=fopen("/proc/cpuinfo", "r");
+ if (stream == NULL) stream = fopen("/proc/cpuinfo", "r");
if (stream == NULL) {
error ("fopen(/proc/cpuinfo) failed: %s", strerror(errno));
return -1;
char buffer[256];
char *c, *key, *val;
fgets (buffer, sizeof(buffer), stream);
- c=strchr(buffer, ':');
- if (c==NULL) continue;
- key=buffer; val=c+1;
+ c = strchr(buffer, ':');
+ if (c == NULL) continue;
+ key = buffer; val = c+1;
// strip leading blanks from key
- while (isspace(*key)) *key++='\0';
+ while (isspace(*key)) *key++ = '\0';
// strip trailing blanks from key
- do *c='\0'; while (isspace(*--c));
+ do *c = '\0'; while (isspace(*--c));
// strip leading blanks from value
- while (isspace(*val)) *val++='\0';
+ while (isspace(*val)) *val++ = '\0';
// strip trailing blanks from value
- for (c=val; *c!='\0';c++);
- while (isspace(*--c)) *c='\0';
+ for (c = val; *c != '\0'; c++);
+ while (isspace(*--c)) *c = '\0';
// add entry to hash table
- hash_set (&CPUinfo, key, val);
+ hash_put (&CPUinfo, key, val);
}
return 0;
{
char *key, *val;
- if (parse_cpuinfo()<0) {
+ if (parse_cpuinfo() < 0) {
SetResult(&result, R_STRING, "");
return;
}
- key=R2S(arg1);
- val=hash_get(&CPUinfo, key);
- if (val==NULL) val="";
+ key = R2S(arg1);
+ val = hash_get(&CPUinfo, key, NULL);
+ if (val == NULL) val = "";
SetResult(&result, R_STRING, val);
}
int plugin_init_cpuinfo (void)
{
+ hash_create (&CPUinfo);
AddFunction ("cpuinfo", 1, my_cpuinfo);
return 0;
}
-/* $Id: plugin_diskstats.c,v 1.2 2004/05/29 01:07:56 reinelt Exp $
+/* $Id: plugin_diskstats.c,v 1.3 2004/06/17 06:23:43 reinelt Exp $
*
* plugin for /proc/diskstats parsing
*
*
*
* $Log: plugin_diskstats.c,v $
+ * Revision 1.3 2004/06/17 06:23:43 reinelt
+ *
+ * hash handling rewritten to solve performance issues
+ *
* Revision 1.2 2004/05/29 01:07:56 reinelt
* bug in plugin_diskstats fixed
*
#include "debug.h"
#include "plugin.h"
-#include "qprintf.h"
#include "hash.h"
-static HASH DISKSTATS = { 0, };
+static HASH DISKSTATS;
static FILE *stream = NULL;
-static void hash_set2 (char *key1, char *key2, char *val)
-{
- char key[32];
-
- qprintf(key, sizeof(key), "%s.%s", key1, key2);
- hash_set_delta (&DISKSTATS, key, val);
-}
-
-
static int parse_diskstats (void)
{
int age;
// reread every 10 msec only
- age = hash_age(&DISKSTATS, NULL, NULL);
+ age = hash_age(&DISKSTATS, NULL);
if (age > 0 && age <= 10) return 0;
if (stream == NULL) stream = fopen("/proc/diskstats", "r");
while (!feof(stream)) {
char buffer[1024];
+ char dev[64];
char *beg, *end;
- char *major = NULL;
- char *minor = NULL;
- char *name = NULL;
- char *key[] = { "reads", "read_merges", "read_sectors", "read_ticks",
- "writes", "write_merges", "write_sectors", "write_ticks",
- "in_flight", "io_ticks", "time_in_queue"
- };
-
- int i;
+ int num, len;
if (fgets (buffer, sizeof(buffer), stream) == NULL) break;
+ // fetch device name (3rd column) as key
+ num = 0;
beg = buffer;
- i = 0;
- while (beg != NULL) {
- while (*beg == ' ') beg++;
- if ((end = strchr(beg, ' '))) *end = '\0';
- switch (i) {
- case 0:
- major = beg;
- break;
- case 1:
- minor = beg;
- break;
- case 2:
- name = beg;
- hash_set2 (name, "major", major);
- hash_set2 (name, "minor", minor);
- break;
- default:
- hash_set2 (name, key[i-3], beg);
- }
- i++;
+ end = beg;
+ while (*beg) {
+ while (*beg == ' ') beg++;
+ end = beg+1;
+ while (*end && *end != ' ') end++;
+ if (num++ == 2) break;
beg = end ? end+1 : NULL;
}
+ len = end ? end - beg : strlen(beg);
+
+ if (len >= sizeof(dev)) len = sizeof(dev)-1;
+ strncpy (dev, beg, len);
+ dev[len] = '\0';
+
+ hash_put_delta (&DISKSTATS, dev, buffer);
+
}
return 0;
}
static void my_diskstats (RESULT *result, RESULT *arg1, RESULT *arg2, RESULT *arg3)
{
- char *dev, *key, buffer[32];
+ char *dev, *key;
int delay;
double value;
key = R2S(arg2);
delay = R2N(arg3);
- qprintf(buffer, sizeof(buffer), "%s\\.%s", dev, key);
- value = hash_get_regex(&DISKSTATS, buffer, delay);
+ value = hash_get_regex(&DISKSTATS, dev, key, delay);
SetResult(&result, R_NUMBER, &value);
}
int plugin_init_diskstats (void)
{
+ int i;
+ char *header[] = { "major", "minor", "name",
+ "reads", "read_merges", "read_sectors", "read_ticks",
+ "writes", "write_merges", "write_sectors", "write_ticks",
+ "in_flight", "io_ticks", "time_in_queue", "" };
+
+ hash_create (&DISKSTATS);
+ hash_set_delimiter (&DISKSTATS, " \n");
+ for (i=0; *header[i] != '\0'; i++) {
+ hash_set_column (&DISKSTATS, i, header[i]);
+ }
+
AddFunction ("diskstats", 3, my_diskstats);
return 0;
}
-/* $Id: plugin_dvb.c,v 1.4 2004/03/14 07:11:42 reinelt Exp $
+/* $Id: plugin_dvb.c,v 1.5 2004/06/17 06:23:43 reinelt Exp $
*
* plugin for DVB status
*
*
*
* $Log: plugin_dvb.c,v $
+ * Revision 1.5 2004/06/17 06:23:43 reinelt
+ *
+ * hash handling rewritten to solve performance issues
+ *
* Revision 1.4 2004/03/14 07:11:42 reinelt
* parameter count fixed for plugin_dvb()
* plugin_APM (battery status) ported
static char *frontend="/dev/dvb/adapter0/frontend0";
-static HASH DVB = { 0, };
+static HASH DVB;
static int get_dvb_stats (void)
{
char val[16];
// reread every 1000 msec only
- age=hash_age(&DVB, NULL, NULL);
- if (age>0 && age<=1000) return 0;
+ age = hash_age(&DVB, NULL);
+ if (age > 0 && age <= 1000) return 0;
// open frontend
fd = open(frontend, O_RDONLY);
- if (fd==-1) {
+ if (fd == -1) {
error ("open(%s) failed: %s", frontend, strerror(errno));
return -1;
}
- if (ioctl(fd, FE_READ_SIGNAL_STRENGTH, &sig)!=0) {
+ if (ioctl(fd, FE_READ_SIGNAL_STRENGTH, &sig) != 0) {
error("ioctl(FE_READ_SIGNAL_STRENGTH) failed: %s", strerror(errno));
- sig=0;
+ sig = 0;
}
- if (ioctl(fd, FE_READ_SNR, &snr)!=0) {
+ if (ioctl(fd, FE_READ_SNR, &snr) != 0) {
error("ioctl(FE_READ_SNR) failed: %s", strerror(errno));
- snr=0;
+ snr = 0;
}
- if (ioctl(fd, FE_READ_BER, &ber)!=0) {
+ if (ioctl(fd, FE_READ_BER, &ber) != 0) {
error("ioctl(FE_READ_BER) failed: %s", strerror(errno));
- ber=0;
+ ber = 0;
}
- if (ioctl(fd, FE_READ_UNCORRECTED_BLOCKS, &ucb)!=0) {
+ if (ioctl(fd, FE_READ_UNCORRECTED_BLOCKS, &ucb) != 0) {
error("ioctl(FE_READ_UNCORRECTED_BLOCKS) failed: %s", strerror(errno));
- ucb=0;
+ ucb = 0;
}
close (fd);
snprintf (val, sizeof(val), "%f", sig/65535.0);
- hash_set (&DVB, "signal_strength", val);
+ hash_put (&DVB, "signal_strength", val);
snprintf (val, sizeof(val), "%f", snr/65535.0);
- hash_set (&DVB, "snr", val);
+ hash_put (&DVB, "snr", val);
snprintf (val, sizeof(val), "%lu", ber);
- hash_set (&DVB, "ber", val);
+ hash_put (&DVB, "ber", val);
snprintf (val, sizeof(val), "%lu", ucb);
- hash_set (&DVB, "uncorrected_blocks", val);
+ hash_put (&DVB, "uncorrected_blocks", val);
return 0;
}
return;
}
- val=hash_get(&DVB, R2S(arg1));
+ val=hash_get(&DVB, R2S(arg1), NULL);
if (val==NULL) val="";
-
+
SetResult(&result, R_STRING, val);
}
+
int plugin_init_dvb (void)
{
+ hash_create(&DVB);
AddFunction ("dvb", 1, my_dvb);
return 0;
}
+
void plugin_exit_dvb(void)
{
- hash_destroy(&DVB);
+ hash_destroy(&DVB);
}
-/* $Id: plugin_exec.c,v 1.2 2004/04/08 10:48:25 reinelt Exp $
+/* $Id: plugin_exec.c,v 1.3 2004/06/17 06:23:43 reinelt Exp $
*
* plugin for external processes
*
*
*
* $Log: plugin_exec.c,v $
+ * Revision 1.3 2004/06/17 06:23:43 reinelt
+ *
+ * hash handling rewritten to solve performance issues
+ *
* Revision 1.2 2004/04/08 10:48:25 reinelt
* finished plugin_exec
* modified thread handling
static EXEC_THREAD Thread[NUM_THREADS];
static int max_thread = -1;
-static HASH EXEC = { 0, };
+static HASH EXEC;
// x^0 + x^5 + x^12
{
int i, age;
- age = hash_age(&EXEC, key, NULL);
+ age = hash_age(&EXEC, key);
if (age < 0) {
- hash_set (&EXEC, key, "");
+ hash_put (&EXEC, key, "");
// first-time call: create thread
if (delay < 10) {
error ("exec(%s): delay %d is too short! using 10 msec", cmd, delay);
// lock shared memory
mutex_lock(Thread[i].mutex);
// copy data
- hash_set (&EXEC, key, Thread[i].ret);
+ hash_put (&EXEC, key, Thread[i].ret);
// unlock shared memory
mutex_unlock(Thread[i].mutex);
return 0;
return;
}
- val = hash_get(&EXEC, key);
+ val = hash_get(&EXEC, key, NULL);
if (val == NULL) val = "";
SetResult(&result, R_STRING, val);
int plugin_init_exec (void)
{
+ hash_create(&EXEC);
AddFunction ("exec", 2, my_exec);
return 0;
}
-/* $Id: plugin_i2c_sensors.c,v 1.17 2004/06/05 14:56:48 reinelt Exp $
+/* $Id: plugin_i2c_sensors.c,v 1.18 2004/06/17 06:23:43 reinelt Exp $
*
* I2C sensors plugin
*
*
*
* $Log: plugin_i2c_sensors.c,v $
+ * Revision 1.18 2004/06/17 06:23:43 reinelt
+ *
+ * hash handling rewritten to solve performance issues
+ *
* Revision 1.17 2004/06/05 14:56:48 reinelt
*
* Cwlinux splash screen fixed
#endif
static char *path=NULL;
-static HASH I2Csensors = { 0, };
+static HASH I2Csensors;
static const char *procfs_tokens[4][3] = {
{"temp_hyst", "temp_max", "temp_input"}, // for temp#
val[strlen(val)-1]='\0';
}
- hash_set (&I2Csensors, key, val);
+ hash_put (&I2Csensors, key, val);
return 0;
} else {
qprintf (final_key, sizeof(final_key), "%s%s", procfs_tokens[tokens_index][pos], number);
// debug ("%s -> %s", final_key, value);
- hash_set (&I2Csensors, final_key, value);
+ hash_put (&I2Csensors, final_key, value);
pos++;
}
}
char *val;
char *key=R2S(arg);
- age=hash_age(&I2Csensors, key, &val);
+ age=hash_age(&I2Csensors, key);
if (age<0 || age>250) {
parse_i2c_sensors(key);
- val=hash_get(&I2Csensors, key);
}
+ val=hash_get(&I2Csensors, key, NULL);
if (val) {
SetResult(&result, R_STRING, val);
} else {
int plugin_init_i2c_sensors (void)
{
- char *path_cfg = cfg_get(NULL, "i2c_sensors-path", "");
+ char *path_cfg;
+ hash_create(&I2Csensors);
+
+ path_cfg = cfg_get(NULL, "i2c_sensors-path", "");
if (path_cfg == NULL || *path_cfg == '\0') {
// debug("No path to i2c sensors found in the conf, calling my_i2c_sensors_path()");
my_i2c_sensors_path("sysfs");
error("i2c_sensors: unknown path %s, should start with /sys or /proc");
}
}
+
+ hash_create(&I2Csensors);
return 0;
}
-/* $Id: plugin_imon.c,v 1.8 2004/05/27 06:29:29 nicowallmeier Exp $
+/* $Id: plugin_imon.c,v 1.9 2004/06/17 06:23:43 reinelt Exp $
*
* imond/telmond data processing
*
*
*
* $Log: plugin_imon.c,v $
+ * Revision 1.9 2004/06/17 06:23:43 reinelt
+ *
+ * hash handling rewritten to solve performance issues
+ *
* Revision 1.8 2004/05/27 06:29:29 nicowallmeier
* Moved variables to Plugin:imon / Plugin:telmon
*
#include <sys/socket.h>
-static HASH TELMON = { 0, };
-static HASH IMON = { 0, };
+static HASH TELMON;
+static HASH IMON;
static char thost[256];
static int tport;
int age;
// reread every 1 sec only
- age=hash_age(&TELMON, NULL, NULL);
+ age=hash_age(&TELMON, NULL);
if (age>0 && age<=1000) return 0;
if (telmond_fd != -1){
char number[256];
char msn[256];
sscanf(telbuf,"%s %s %s %s",date,time,number,msn);
- hash_set (&TELMON, "time", time);
+ hash_put (&TELMON, "time", time);
date[4]='\0';
date[7]='\0';
qprintf(time, sizeof(time), "%s.%s.%s",date+8,date+5,date);
- hash_set (&TELMON, "number", number);
- hash_set (&TELMON, "msn", msn);
- hash_set (&TELMON, "date", time);
+ hash_put (&TELMON, "number", number);
+ hash_put (&TELMON, "msn", msn);
+ hash_put (&TELMON, "date", time);
phonebook(number);
phonebook(msn);
- hash_set (&TELMON, "name", number);
- hash_set (&TELMON, "msnname", msn);
+ hash_put (&TELMON, "name", number);
+ hash_put (&TELMON, "msnname", msn);
}
close (telmond_fd);
strcpy(oldanswer,telbuf);
return;
}
- val=hash_get(&TELMON, R2S(arg1));
+ val=hash_get(&TELMON, R2S(arg1), NULL);
if (val==NULL) val="";
SetResult(&result, R_STRING, val);
}
static int parse_imon(char *cmd){
// reread every half sec only
- int age=hash_age(&IMON, cmd, NULL);
+ int age=hash_age(&IMON, cmd);
if (age>0 && age<=500) return 0;
init(); // establish connection
if (err) return -1;
- hash_set (&IMON, cmd , get_value(cmd));
+ hash_put (&IMON, cmd , get_value(cmd));
return 0;
}
static void my_imon_version (RESULT *result){
char *val;
// read only ones
- int age=hash_age(&IMON, "version", NULL);
+ int age=hash_age(&IMON, "version");
if (age<0){
char *s;
init();
}
s=s+1;
}
- hash_set (&IMON, "version", s);
+ hash_put (&IMON, "version", s);
}
- val=hash_get(&IMON, "version");
+ val=hash_get(&IMON, "version", NULL);
if (val==NULL) val="";
SetResult(&result, R_STRING, val);
}
qprintf(buf,sizeof(buf),"rate %s in",channel);
// reread every half sec only
- age=hash_age(&IMON, buf, NULL);
+ age=hash_age(&IMON, buf);
if (age>0 && age<=500) return 0;
init(); // establish connection
if (sscanf(s,"%s %s",in, out)!=2) return -1;
qprintf(buf, sizeof(buf), "rate %s in", channel);
- hash_set (&IMON, buf , in);
+ hash_put (&IMON, buf , in);
qprintf(buf, sizeof(buf), "rate %s out", channel);
- hash_set (&IMON, buf , out);
+ hash_put (&IMON, buf , out);
return 0;
}
qprintf(buf,sizeof(buf),"rate %s %s",R2S(arg1),R2S(arg2));
- val=hash_get(&IMON, buf);
+ val=hash_get(&IMON, buf, NULL);
if (val==NULL) val="";
SetResult(&result, R_STRING, val);
}
return;
}
- val=hash_get(&IMON, cmd);
+ val=hash_get(&IMON, cmd, NULL);
if (val==NULL) val="";
SetResult(&result, R_STRING, val);
}
int plugin_init_imon (void){
char telmon='\1',imon='\1';
+ hash_create(&TELMON);
+ hash_create(&IMON);
+
char *s=cfg_get ("Plugin:Telmon", "Host","127.0.0.1");
if (*s=='\0') {
error ("[Telmon] no 'Host' entry in %s", cfg_source());
-/* $Id: plugin_isdn.c,v 1.1 2004/05/19 05:23:25 reinelt Exp $
+/* $Id: plugin_isdn.c,v 1.2 2004/06/17 06:23:43 reinelt Exp $
*
* plugin for ISDN subsystem
*
*
*
* $Log: plugin_isdn.c,v $
+ * Revision 1.2 2004/06/17 06:23:43 reinelt
+ *
+ * hash handling rewritten to solve performance issues
+ *
* Revision 1.1 2004/05/19 05:23:25 reinelt
*
* plugin_isdn.c added (sorry, I forgot...)
} CPS;
-static HASH ISDN_INFO = { 0, };
-static HASH ISDN_CPS = { 0, };
+static HASH ISDN_INFO;
+static HASH ISDN_CPS;
-static void hash_set_info (char *name, int channel, char *val)
+static void hash_put_info (char *name, int channel, char *val)
{
char key[16];
qprintf (key, sizeof(key), "%s[%d]", name, channel);
- hash_set (&ISDN_INFO, key, val);
+ hash_put (&ISDN_INFO, key, val);
}
static int parse_isdninfo (void)
long flags;
// reread every 10 msec only
- age = hash_age(&ISDN_INFO, NULL, NULL);
+ age = hash_age(&ISDN_INFO, NULL);
if (age > 0 && age <= 10) return 0;
// open file
while (*beg && strchr(delim, *beg)) beg++;
while (beg && *beg) {
if ((end = strpbrk(beg, delim))) *end = '\0';
- hash_set_info(buffer, i, beg);
+ hash_put_info(buffer, i, beg);
beg = end ? end+1 : NULL;
while (*beg && strchr(delim, *beg)) beg++;
i++;
}
qprintf(key, sizeof(key), "%s[%d]", R2S(arg1), (int)R2N(arg2));
- val = hash_get(&ISDN_INFO, key);
+ val = hash_get(&ISDN_INFO, key, NULL);
if (val == NULL) val = "";
SetResult(&result, R_STRING, val);
}
#ifdef HAVE_LINUX_ISDN_H
-static void hash_set_cps (int channel, CPS *cps)
+static void hash_put_cps (int channel, CPS *cps)
{
char key[16], val[16];
qprintf (key, sizeof(key), channel < 0 ? "i" : "i%d", channel);
qprintf (val, sizeof(val), "%u", cps->in);
- hash_set_delta (&ISDN_CPS, key, val);
+ hash_put_delta (&ISDN_CPS, key, val);
qprintf (key, sizeof(key), channel < 0 ? "o" : "o%d", channel);
qprintf (val, sizeof(val), "%u", cps->out);
- hash_set_delta (&ISDN_CPS, key, val);
+ hash_put_delta (&ISDN_CPS, key, val);
}
CPS sum;
// reread every 10 msec only
- age = hash_age(&ISDN_CPS, NULL, NULL);
+ age = hash_age(&ISDN_CPS, NULL);
if (age > 0 && age <= 10) return 0;
if (fd == -1) return -1;
for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
sum.in += cps[i].in;
sum.out += cps[i].out;
- hash_set_cps (i, &cps[i]);
+ hash_put_cps (i, &cps[i]);
}
- hash_set_cps (-1, &sum);
+ hash_put_cps (-1, &sum);
return 0;
}
return;
}
- value = hash_get_delta(&ISDN_CPS, R2S(arg1), R2N(arg2));
+ value = hash_get_delta(&ISDN_CPS, R2S(arg1), NULL, R2N(arg2));
SetResult(&result, R_NUMBER, &value);
}
int plugin_init_isdn (void)
{
+ hash_create(&ISDN_INFO);
+ hash_create(&ISDN_CPS);
+
AddFunction ("isdn::info", 2, my_isdn_info);
#ifdef HAVE_LINUX_ISDN_H
-/* $Id: plugin_meminfo.c,v 1.7 2004/03/11 06:39:59 reinelt Exp $
+/* $Id: plugin_meminfo.c,v 1.8 2004/06/17 06:23:43 reinelt Exp $
*
* plugin for /proc/meminfo parsing
*
*
*
* $Log: plugin_meminfo.c,v $
+ * Revision 1.8 2004/06/17 06:23:43 reinelt
+ *
+ * hash handling rewritten to solve performance issues
+ *
* Revision 1.7 2004/03/11 06:39:59 reinelt
* big patch from Martin:
* - reuse filehandles
#include "hash.h"
-static HASH MemInfo = { 0, };
+static HASH MemInfo;
static FILE *stream = NULL;
static int parse_meminfo (void)
int age;
// reread every 10 msec only
- age=hash_age(&MemInfo, NULL, NULL);
+ age=hash_age(&MemInfo, NULL);
if (age>0 && age<=10) return 0;
if (stream==NULL) stream=fopen("/proc/meminfo", "r");
// strip trailing " kB" from value
*(c-2)='\0';
// add entry to hash table
- hash_set (&MemInfo, key, val);
+ hash_put (&MemInfo, key, val);
}
}
return 0;
}
key=R2S(arg1);
- val=hash_get(&MemInfo, key);
+ val=hash_get(&MemInfo, key, NULL);
if (val==NULL) val="";
SetResult(&result, R_STRING, val);
int plugin_init_meminfo (void)
{
+ hash_create(&MemInfo);
AddFunction ("meminfo", 1, my_meminfo);
return 0;
}
-/* $Id: plugin_netdev.c,v 1.8 2004/05/27 03:39:47 reinelt Exp $
+/* $Id: plugin_netdev.c,v 1.9 2004/06/17 06:23:43 reinelt Exp $
*
* plugin for /proc/net/dev parsing
*
*
*
* $Log: plugin_netdev.c,v $
+ * Revision 1.9 2004/06/17 06:23:43 reinelt
+ *
+ * hash handling rewritten to solve performance issues
+ *
* Revision 1.8 2004/05/27 03:39:47 reinelt
*
* changed function naming scheme to plugin::function
#include "hash.h"
-static HASH NetDev = { 0, };
+static HASH NetDev;
static FILE *stream = NULL;
-static void hash_set3 (char *key1, char *key2, char *key3, char *val)
+// Fixme: use new & fast hash code!!!
+
+static void hash_put3 (char *key1, char *key2, char *key3, char *val)
{
char key[32];
qprintf(key, sizeof(key), "%s.%s.%s", key1, key2, key3);
- hash_set_delta (&NetDev, key, val);
+ hash_put_delta (&NetDev, key, val);
}
int RxTx=0; // position of Receive/Transmit switch
// reread every 10 msec only
- age=hash_age(&NetDev, NULL, NULL);
+ age=hash_age(&NetDev, NULL);
if (age>0 && age<=10) return 0;
if (stream==NULL) stream=fopen("/proc/net/dev", "r");
if (col==0) {
iface=h;
} else {
- hash_set3 (iface, (h-buffer) < RxTx ? "Rx" : "Tx", head[col], h);
+ hash_put3 (iface, (h-buffer) < RxTx ? "Rx" : "Tx", head[col], h);
}
h=t?t+1:NULL;
col++;
key = R2S(arg1);
delay = R2N(arg2);
- value = hash_get_regex(&NetDev, key, delay);
+ value = hash_get_regex(&NetDev, key, NULL, delay);
SetResult(&result, R_NUMBER, &value);
}
key = R2S(arg1);
delay = R2N(arg2);
- value = hash_get_delta(&NetDev, key, delay);
+ value = hash_get_delta(&NetDev, key, NULL, delay);
SetResult(&result, R_NUMBER, &value);
}
int plugin_init_netdev (void)
{
+ hash_create(&NetDev);
AddFunction ("netdev", 2, my_netdev);
AddFunction ("netdev::fast", 2, my_netdev_fast);
return 0;
-/* $Id: plugin_ppp.c,v 1.5 2004/05/29 15:53:28 reinelt Exp $
+/* $Id: plugin_ppp.c,v 1.6 2004/06/17 06:23:43 reinelt Exp $
*
* plugin for ppp throughput
*
*
*
* $Log: plugin_ppp.c,v $
+ * Revision 1.6 2004/06/17 06:23:43 reinelt
+ *
+ * hash handling rewritten to solve performance issues
+ *
* Revision 1.5 2004/05/29 15:53:28 reinelt
*
* M50530: reset parport signals on exit
#ifdef HAVE_NET_IF_PPP_H
-static HASH PPP = { 0, };
+static HASH PPP;
static int get_ppp_stats (void)
{
char key[16], val[16];
// reread every 10 msec only
- age=hash_age(&PPP, NULL, NULL);
+ age=hash_age(&PPP, NULL);
if (age>0 && age<=10) return 0;
// open socket only once
}
qprintf(key, sizeof(key), "Rx:%d", unit);
qprintf(val, sizeof(val), "%d", ibytes);
- hash_set_delta (&PPP, key, val);
+ hash_put_delta (&PPP, key, val);
qprintf(key, sizeof(key), "Tx:%d", unit);
qprintf(val, sizeof(val), "%d", obytes);
- hash_set_delta (&PPP, key, val);
+ hash_put_delta (&PPP, key, val);
}
return 0;
SetResult(&result, R_STRING, "");
return;
}
- value=hash_get_delta(&PPP, R2S(arg1), R2N(arg2));
+ value=hash_get_delta(&PPP, R2S(arg1), NULL, R2N(arg2));
SetResult(&result, R_NUMBER, &value);
}
int plugin_init_ppp (void)
{
+ hash_create(&PPP);
#ifdef HAVE_NET_IF_PPP_H
AddFunction ("ppp", 2, my_ppp);
#endif
void plugin_exit_ppp(void)
{
- hash_destroy(&PPP);
+ hash_destroy(&PPP);
}
-/* $Id: plugin_proc_stat.c,v 1.19 2004/05/27 03:39:47 reinelt Exp $
+/* $Id: plugin_proc_stat.c,v 1.20 2004/06/17 06:23:43 reinelt Exp $
*
* plugin for /proc/stat parsing
*
*
*
* $Log: plugin_proc_stat.c,v $
+ * Revision 1.20 2004/06/17 06:23:43 reinelt
+ *
+ * hash handling rewritten to solve performance issues
+ *
* Revision 1.19 2004/05/27 03:39:47 reinelt
*
* changed function naming scheme to plugin::function
#include "hash.h"
-static HASH Stat = { 0, };
+static HASH Stat;
static FILE *stream = NULL;
-static void hash_set1 (char *key1, char *val)
+static void hash_put1 (char *key1, char *val)
{
- hash_set_delta (&Stat, key1, val);
+ hash_put_delta (&Stat, key1, val);
}
-static void hash_set2 (char *key1, char *key2, char *val)
+static void hash_put2 (char *key1, char *key2, char *val)
{
char key[32];
qprintf(key, sizeof(key), "%s.%s", key1, key2);
- hash_set1 (key, val);
+ hash_put1 (key, val);
}
-static void hash_set3 (char *key1, char *key2, char *key3, char *val)
+static void hash_put3 (char *key1, char *key2, char *key3, char *val)
{
char key[32];
qprintf(key, sizeof(key), "%s.%s.%s", key1, key2, key3);
- hash_set1 (key, val);
+ hash_put1 (key, val);
}
int age;
// reread every 10 msec only
- age=hash_age(&Stat, NULL, NULL);
+ age=hash_age(&Stat, NULL);
if (age>0 && age<=10) return 0;
if (stream==NULL) stream=fopen("/proc/stat", "r");
for (i=0; i<4 && beg!=NULL; i++) {
while (strchr(delim, *beg)) beg++;
if ((end=strpbrk(beg, delim))) *end='\0';
- hash_set2 (cpu, key[i], beg);
+ hash_put2 (cpu, key[i], beg);
beg=end?end+1:NULL;
}
}
for (i=0, beg=buffer+5; i<2 && beg!=NULL; i++) {
while (strchr(delim, *beg)) beg++;
if ((end=strpbrk(beg, delim))) *end='\0';
- hash_set2 ("page", key[i], beg);
+ hash_put2 ("page", key[i], beg);
beg=end?end+1:NULL;
}
}
for (i=0, beg=buffer+5; i<2 && beg!=NULL; i++) {
while (strchr(delim, *beg)) beg++;
if ((end=strpbrk(beg, delim))) *end='\0';
- hash_set2 ("swap", key[i], beg);
+ hash_put2 ("swap", key[i], beg);
beg=end?end+1:NULL;
}
}
strcpy(num, "sum");
else
qprintf(num, sizeof(num), "%d", i-1);
- hash_set2 ("intr", num, beg);
+ hash_put2 ("intr", num, beg);
beg=end?end+1:NULL;
}
}
for (i=0; i<5 && beg!=NULL; i++) {
while (strchr(delim, *beg)) beg++;
if ((end=strpbrk(beg, delim))) *end='\0';
- hash_set3 ("disk_io", dev, key[i], beg);
+ hash_put3 ("disk_io", dev, key[i], beg);
beg=end?end+1:NULL;
}
dev=beg;
beg=end?end+1:NULL;
if ((end=strpbrk(beg, delim))) *end='\0';
while (strchr(delim, *beg)) beg++;
- hash_set1 (buffer, beg);
+ hash_put1 (buffer, beg);
}
}
return 0;
switch (argc) {
case 1:
- string=hash_get(&Stat, R2S(argv[0]));
+ string=hash_get(&Stat, R2S(argv[0]), NULL);
if (string==NULL) string="";
SetResult(&result, R_STRING, string);
break;
case 2:
- number=hash_get_delta(&Stat, R2S(argv[0]), R2N(argv[1]));
+ number=hash_get_delta(&Stat, R2S(argv[0]), NULL, R2N(argv[1]));
SetResult(&result, R_NUMBER, &number);
break;
default:
key = R2S(arg1);
delay = R2N(arg2);
- cpu_user = hash_get_delta(&Stat, "cpu.user", delay);
- cpu_nice = hash_get_delta(&Stat, "cpu.nice", delay);
- cpu_system = hash_get_delta(&Stat, "cpu.system", delay);
- cpu_idle = hash_get_delta(&Stat, "cpu.idle", delay);
+ cpu_user = hash_get_delta(&Stat, "cpu.user", NULL, delay);
+ cpu_nice = hash_get_delta(&Stat, "cpu.nice", NULL, delay);
+ cpu_system = hash_get_delta(&Stat, "cpu.system", NULL, delay);
+ cpu_idle = hash_get_delta(&Stat, "cpu.idle", NULL, delay);
cpu_total = cpu_user+cpu_nice+cpu_system+cpu_idle;
delay = R2N(arg3);
qprintf(buffer, sizeof(buffer), "disk_io\\.%s\\.%s", dev, key);
- value = hash_get_regex(&Stat, buffer, delay);
+ value = hash_get_regex(&Stat, buffer, NULL, delay);
SetResult(&result, R_NUMBER, &value);
}
int plugin_init_proc_stat (void)
{
+ hash_create(&Stat);
AddFunction ("proc_stat", -1, my_proc_stat);
AddFunction ("proc_stat::cpu", 2, my_cpu);
AddFunction ("proc_stat::disk", 3, my_disk);
-/* $Id: plugin_seti.c,v 1.2 2004/03/13 19:06:01 reinelt Exp $
+/* $Id: plugin_seti.c,v 1.3 2004/06/17 06:23:43 reinelt Exp $
*
* plugin for seti@home status reporting
*
*
*
* $Log: plugin_seti.c,v $
+ * Revision 1.3 2004/06/17 06:23:43 reinelt
+ *
+ * hash handling rewritten to solve performance issues
+ *
* Revision 1.2 2004/03/13 19:06:01 reinelt
* ChangeLog and Status update; small glitch in plugin_seti fixed.
*
#define DIRKEY "Directory"
#define STATEFILE "state.sah"
-static HASH SETI = { 0, };
+static HASH SETI;
static int fatal = 0;
static int parse_seti (void)
if (fatal != 0) return -1;
// reread every 100 msec only
- age=hash_age(&SETI, NULL, NULL);
+ age=hash_age(&SETI, NULL);
if (age>0 && age<=100) return 0;
if (fn[0] == '\0') {
for (c=val; *c!='\0';c++);
while (isspace(*--c)) *c='\0';
// add entry to hash table
- hash_set (&SETI, key, val);
+ hash_put (&SETI, key, val);
}
fclose (stream);
}
key=R2S(arg1);
- val=hash_get(&SETI, key);
+ val=hash_get(&SETI, key, NULL);
if (val==NULL) val="";
SetResult(&result, R_STRING, val);
int plugin_init_seti (void)
{
+ hash_create(&SETI);
AddFunction ("seti", 1, my_seti);
return 0;
}
-/* $Id: plugin_wireless.c,v 1.3 2004/05/27 03:39:47 reinelt Exp $
+/* $Id: plugin_wireless.c,v 1.4 2004/06/17 06:23:43 reinelt Exp $
*
* Wireless Extension plugin
*
*
*
* $Log: plugin_wireless.c,v $
+ * Revision 1.4 2004/06/17 06:23:43 reinelt
+ *
+ * hash handling rewritten to solve performance issues
+ *
* Revision 1.3 2004/05/27 03:39:47 reinelt
*
* changed function naming scheme to plugin::function
#define MWATT2DBM(in) ((int) (ceil(10.0 * log10((double) in))))
-static HASH wireless = { 0, };
+static HASH wireless;
static int sock=-2;
static char *operation_mode[] = {
return -1;
}
- hash_set(&wireless,key_buffer, preq->u.name);
+ hash_put(&wireless,key_buffer, preq->u.name);
return(0);
}
int age;
qprintf(key_buffer,sizeof(key_buffer), "%s.%s", dev,key);
- age=hash_age(&wireless, key, NULL);
+ age=hash_age(&wireless, key);
/* reread every HASH_TTL msec only */
if (age>0 && age<=HASH_TTL) {
*/
snprintf(qprintf_buffer,sizeof(qprintf_buffer), "%g", freq);
- hash_set(&wireless, key_buffer, qprintf_buffer);
+ hash_put(&wireless, key_buffer, qprintf_buffer);
return(0);
}
qprintf(key_buffer,sizeof(key_buffer), "%s.%s", dev,key);
- age=hash_age(&wireless, key, NULL);
+ age=hash_age(&wireless, key);
/* reread every HASH_TTL msec only */
if (age>0 && age<=HASH_TTL) {
return -1;
}
- hash_set(&wireless,key_buffer, essid_buffer);
+ hash_put(&wireless,key_buffer, essid_buffer);
return(0);
}
int age;
qprintf(key_buffer,sizeof(key_buffer), "%s.%s", dev,key);
- age=hash_age(&wireless, key, NULL);
+ age=hash_age(&wireless, key);
/* reread every HASH_TTL msec only */
if (age>0 && age<=HASH_TTL) {
req.u.mode=7; /* mode not available */
}
- hash_set(&wireless,key_buffer, operation_mode[req.u.mode]);
+ hash_put(&wireless,key_buffer, operation_mode[req.u.mode]);
return(0);
}
double bitrate=0;
qprintf(key_buffer,sizeof(key_buffer), "%s.%s", dev,key);
- age=hash_age(&wireless, key, NULL);
+ age=hash_age(&wireless, key);
/* reread every HASH_TTL msec only */
if (age>0 && age<=HASH_TTL) {
*/
snprintf(bitrate_buffer,sizeof(bitrate_buffer), "%g", bitrate);
- hash_set(&wireless,key_buffer, bitrate_buffer);
+ hash_put(&wireless,key_buffer, bitrate_buffer);
return(0);
}
int has_range =0;
qprintf(key_buffer,sizeof(key_buffer), "%s.%s", dev,key);
- age=hash_age(&wireless, key, NULL);
+ age=hash_age(&wireless, key);
/* reread every HASH_TTL msec only */
if (age>0 && age<=HASH_TTL) {
qprintf(buffer, sizeof(buffer), "%d", req.u.sens.value);
}
- hash_set(&wireless,key_buffer, buffer);
+ hash_put(&wireless,key_buffer, buffer);
return(0);
}
int key_size=0;
qprintf(key_buffer,sizeof(key_buffer), "%s.%s", dev,key);
- age=hash_age(&wireless, key, NULL);
+ age=hash_age(&wireless, key);
/* reread every HASH_TTL msec only */
if (age>0 && age<=HASH_TTL) {
// printf(" [%d]", info->key_flags & IW_ENCODE_INDEX);
if(has_key && (key_flags & IW_ENCODE_RESTRICTED))
- hash_set(&wireless,key_buffer, "restricted");
+ hash_put(&wireless,key_buffer, "restricted");
else if(has_key && (key_flags & IW_ENCODE_OPEN))
- hash_set(&wireless,key_buffer, "open");
+ hash_put(&wireless,key_buffer, "open");
return(0);
}
struct iw_range range;
qprintf(key_buffer,sizeof(key_buffer), "%s.%s", dev,key);
- age=hash_age(&wireless, key, NULL);
+ age=hash_age(&wireless, key);
/* reread every HASH_TTL msec only */
if (age>0 && age<=HASH_TTL) {
if(stats.qual.level > range.max_qual.level) {
qprintf(qprintf_buffer, sizeof(qprintf_buffer), "%d", stats.qual.level-0x100);
qprintf(key_buffer,sizeof(key_buffer), "%s.%s", dev, KEY_LEVEL);
- hash_set(&wireless,key_buffer, qprintf_buffer);
+ hash_put(&wireless,key_buffer, qprintf_buffer);
qprintf(qprintf_buffer, sizeof(qprintf_buffer), "%d", stats.qual.noise-0x100);
qprintf(key_buffer,sizeof(key_buffer), "%s.%s", dev, KEY_NOISE);
- hash_set(&wireless,key_buffer, qprintf_buffer);
+ hash_put(&wireless,key_buffer, qprintf_buffer);
qprintf(qprintf_buffer, sizeof(qprintf_buffer), "%d/%d", stats.qual.qual,range.max_qual.qual);
qprintf(key_buffer,sizeof(key_buffer), "%s.%s", dev, KEY_QUALITY);
- hash_set(&wireless,key_buffer, qprintf_buffer);
+ hash_put(&wireless,key_buffer, qprintf_buffer);
} else {
qprintf(qprintf_buffer, sizeof(qprintf_buffer), "%d/%d", stats.qual.level, range.max_qual.level);
qprintf(key_buffer,sizeof(key_buffer), "%s.%s", dev, KEY_LEVEL);;
- hash_set(&wireless,key_buffer, qprintf_buffer);
+ hash_put(&wireless,key_buffer, qprintf_buffer);
qprintf(qprintf_buffer, sizeof(qprintf_buffer), "%d/%d", stats.qual.noise,range.max_qual.noise);
qprintf(key_buffer,sizeof(key_buffer), "%s.%s", dev, KEY_NOISE);
- hash_set(&wireless,key_buffer, qprintf_buffer);
+ hash_put(&wireless,key_buffer, qprintf_buffer);
qprintf(qprintf_buffer, sizeof(qprintf_buffer), "%d/%d", stats.qual.qual, range.max_qual.qual);
qprintf(key_buffer,sizeof(key_buffer), "%s.%s", dev, KEY_QUALITY);
- hash_set(&wireless,key_buffer, qprintf_buffer);
+ hash_put(&wireless,key_buffer, qprintf_buffer);
}
return 0;
return;
}
- val=hash_get(&wireless,key_buffer);
+ val=hash_get(&wireless,key_buffer, NULL);
if (val) {
SetResult(&result, R_STRING, val);
int plugin_init_wireless(void)
{
+ hash_create(&wireless);
+
AddFunction ("wifi::level", 1, wireless_level);
AddFunction ("wifi::noise", 1, wireless_noise);
AddFunction ("wifi::quality", 1, wireless_quality);
-/* $Id: plugin_xmms.c,v 1.9 2004/03/03 03:47:04 reinelt Exp $
+/* $Id: plugin_xmms.c,v 1.10 2004/06/17 06:23:43 reinelt Exp $
*
* XMMS-Plugin for LCD4Linux
* Copyright 2003 Markus Keil <markus_keil@t-online.de>
*
*
* $Log: plugin_xmms.c,v $
+ * Revision 1.10 2004/06/17 06:23:43 reinelt
+ *
+ * hash handling rewritten to solve performance issues
+ *
* Revision 1.9 2004/03/03 03:47:04 reinelt
* big patch from Martin Hejl:
* - use qprintf() where appropriate
#include "plugin.h"
-static HASH xmms = { 0, };
+static HASH xmms;
static int parse_xmms_info (void)
char zeile[200];
// reread every 100msec only
- age=hash_age(&xmms, NULL, NULL);
+ age=hash_age(&xmms, NULL);
if (age>=0 && age<=200) return 0;
// Open Filestream for '/tmp/xmms-info'
xmms_stream = fopen("/tmp/xmms-info","r");
// strip trailing blanks from value
for (c=val; *c!='\0';c++);
while (isspace(*--c)) *c='\0';
- hash_set (&xmms, key, val);
+ hash_put (&xmms, key, val);
}
fclose(xmms_stream);
}
key=R2S(arg1);
- val=hash_get(&xmms, key);
+ val=hash_get(&xmms, key, NULL);
if (val==NULL) val="";
SetResult(&result, R_STRING, val);
int plugin_init_xmms (void)
{
+ hash_create(&xmms);
// register xmms info
AddFunction ("xmms", 1, my_xmms);
void plugin_exit_xmms(void)
{
- hash_destroy(&xmms);
+ hash_destroy(&xmms);
}