From 1d354fd87d4c07906e82d104ba8614d30ae9cbbe Mon Sep 17 00:00:00 2001 From: reinelt Date: Thu, 17 Jun 2004 06:23:43 +0000 Subject: [lcd4linux @ 2004-06-17 06:23:39 by reinelt] hash handling rewritten to solve performance issues git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@473 3ae390bd-cb1e-0410-b409-cd5a39f66f1f --- drv_T6963.c | 7 +- hash.c | 441 ++++++++++++++++++++++++++++++++------------------ hash.h | 61 ++++--- lcd4linux.conf.sample | 16 +- plugin_apm.c | 21 ++- plugin_cpuinfo.c | 41 ++--- plugin_diskstats.c | 84 +++++----- plugin_dvb.c | 47 +++--- plugin_exec.c | 17 +- plugin_i2c_sensors.c | 23 ++- plugin_imon.c | 49 +++--- plugin_isdn.c | 37 +++-- plugin_meminfo.c | 15 +- plugin_netdev.c | 23 ++- plugin_ppp.c | 19 ++- plugin_proc_stat.c | 49 +++--- plugin_seti.c | 15 +- plugin_wireless.c | 54 ++++--- plugin_xmms.c | 17 +- 19 files changed, 633 insertions(+), 403 deletions(-) diff --git a/drv_T6963.c b/drv_T6963.c index b010d45..870d274 100644 --- a/drv_T6963.c +++ b/drv_T6963.c @@ -1,4 +1,4 @@ -/* $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 * @@ -23,6 +23,10 @@ * * * $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 @@ -80,6 +84,7 @@ #include "debug.h" #include "cfg.h" +#include "qprintf.h" #include "udelay.h" #include "plugin.h" #include "widget.h" diff --git a/hash.c b/hash.c index f66d6e1..bd3f73c 100644 --- a/hash.c +++ b/hash.c @@ -1,4 +1,4 @@ -/* $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) * @@ -23,6 +23,10 @@ * * * $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) @@ -114,15 +118,18 @@ /* * 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 * @@ -159,55 +166,125 @@ #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;inItems; 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; } } @@ -218,176 +295,134 @@ static HASH_ITEM* hash_lookup (HASH *Hash, char *key, int sortit) } -// 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; iSlot[(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; @@ -397,27 +432,28 @@ double hash_get_delta (HASH *Hash, char *key, int delay) // 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;inItems; 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); @@ -425,24 +461,113 @@ double hash_get_regex (HASH *Hash, char *key, int delay) } +// 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;inItems; 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; } diff --git a/hash.h b/hash.h index 6c3870d..a5b8c0a 100644 --- a/hash.h +++ b/hash.h @@ -1,4 +1,4 @@ -/* $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) * @@ -23,6 +23,10 @@ * * * $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) @@ -87,40 +91,57 @@ #ifndef _HASH_H_ #define _HASH_H_ - +// struct timeval #include -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 diff --git a/lcd4linux.conf.sample b/lcd4linux.conf.sample index 774c451..8028435 100644 --- a/lcd4linux.conf.sample +++ b/lcd4linux.conf.sample @@ -230,10 +230,10 @@ Widget Disk { 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 @@ -244,11 +244,11 @@ Widget Disk { 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 @@ -609,9 +609,9 @@ Layout testMySQL { #Display 'CF631' #Display 'CF632' #Display 'CF633' -#Display 'Curses' +Display 'Curses' #Display 'USBLCD' -Display 'T6963-240x64' +#Display 'T6963-240x64' #Display 'XWindow' #Display 'Image' diff --git a/plugin_apm.c b/plugin_apm.c index 6c58009..feebb41 100644 --- a/plugin_apm.c +++ b/plugin_apm.c @@ -1,4 +1,4 @@ -/* $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) * @@ -26,6 +26,10 @@ * * * $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 @@ -129,7 +133,7 @@ static int parse_proc_apm (void) 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) { @@ -156,10 +160,9 @@ static int parse_proc_apm (void) 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; } @@ -169,20 +172,23 @@ static void my_apm (RESULT *result, RESULT *arg1) { 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; } @@ -192,5 +198,6 @@ void plugin_exit_apm (void) close (fd); } fd = -2; + hash_destroy(&APM); } diff --git a/plugin_cpuinfo.c b/plugin_cpuinfo.c index 2fcb98d..f5923cc 100644 --- a/plugin_cpuinfo.c +++ b/plugin_cpuinfo.c @@ -1,4 +1,4 @@ -/* $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 * @@ -23,6 +23,10 @@ * * * $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 @@ -91,7 +95,7 @@ #include "hash.h" -static HASH CPUinfo = { 0, }; +static HASH CPUinfo; static FILE *stream = NULL; static int parse_cpuinfo (void) @@ -99,10 +103,10 @@ 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; @@ -112,21 +116,21 @@ static int parse_cpuinfo (void) 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; @@ -137,14 +141,14 @@ static void my_cpuinfo (RESULT *result, RESULT *arg1) { 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); } @@ -152,6 +156,7 @@ static void my_cpuinfo (RESULT *result, RESULT *arg1) int plugin_init_cpuinfo (void) { + hash_create (&CPUinfo); AddFunction ("cpuinfo", 1, my_cpuinfo); return 0; } diff --git a/plugin_diskstats.c b/plugin_diskstats.c index 2e5b5fe..8ca519d 100644 --- a/plugin_diskstats.c +++ b/plugin_diskstats.c @@ -1,4 +1,4 @@ -/* $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 * @@ -23,6 +23,10 @@ * * * $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 * @@ -51,29 +55,19 @@ #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"); @@ -86,42 +80,31 @@ static int parse_diskstats (void) 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; } @@ -129,7 +112,7 @@ static int parse_diskstats (void) static void my_diskstats (RESULT *result, RESULT *arg1, RESULT *arg2, RESULT *arg3) { - char *dev, *key, buffer[32]; + char *dev, *key; int delay; double value; @@ -142,8 +125,7 @@ static void my_diskstats (RESULT *result, RESULT *arg1, RESULT *arg2, RESULT *ar 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); } @@ -151,6 +133,18 @@ static void my_diskstats (RESULT *result, RESULT *arg1, RESULT *arg2, RESULT *ar 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; } diff --git a/plugin_dvb.c b/plugin_dvb.c index 9bfa5f3..90db55e 100644 --- a/plugin_dvb.c +++ b/plugin_dvb.c @@ -1,4 +1,4 @@ -/* $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 * @@ -23,6 +23,10 @@ * * * $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 @@ -78,7 +82,7 @@ static char *frontend="/dev/dvb/adapter0/frontend0"; -static HASH DVB = { 0, }; +static HASH DVB; static int get_dvb_stats (void) { @@ -89,49 +93,49 @@ 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; } @@ -146,19 +150,22 @@ static void my_dvb (RESULT *result, RESULT *arg1) 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); } diff --git a/plugin_exec.c b/plugin_exec.c index 565ace1..a9a37c8 100644 --- a/plugin_exec.c +++ b/plugin_exec.c @@ -1,4 +1,4 @@ -/* $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 * @@ -27,6 +27,10 @@ * * * $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 @@ -78,7 +82,7 @@ typedef struct { static EXEC_THREAD Thread[NUM_THREADS]; static int max_thread = -1; -static HASH EXEC = { 0, }; +static HASH EXEC; // x^0 + x^5 + x^12 @@ -208,10 +212,10 @@ static int do_exec (char *cmd, char *key, int delay) { 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); @@ -232,7 +236,7 @@ static int do_exec (char *cmd, char *key, int 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; @@ -258,7 +262,7 @@ static void my_exec (RESULT *result, RESULT *arg1, RESULT *arg2) return; } - val = hash_get(&EXEC, key); + val = hash_get(&EXEC, key, NULL); if (val == NULL) val = ""; SetResult(&result, R_STRING, val); @@ -267,6 +271,7 @@ static void my_exec (RESULT *result, RESULT *arg1, RESULT *arg2) int plugin_init_exec (void) { + hash_create(&EXEC); AddFunction ("exec", 2, my_exec); return 0; } diff --git a/plugin_i2c_sensors.c b/plugin_i2c_sensors.c index 4f1e569..14ef61e 100644 --- a/plugin_i2c_sensors.c +++ b/plugin_i2c_sensors.c @@ -1,4 +1,4 @@ -/* $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 * @@ -23,6 +23,10 @@ * * * $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 @@ -155,7 +159,7 @@ #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# @@ -207,7 +211,7 @@ static int parse_i2c_sensors_sysfs(char *key) val[strlen(val)-1]='\0'; } - hash_set (&I2Csensors, key, val); + hash_put (&I2Csensors, key, val); return 0; @@ -276,7 +280,7 @@ static int parse_i2c_sensors_procfs(char *key) } 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++; } } @@ -293,11 +297,11 @@ void my_i2c_sensors(RESULT *result, RESULT *arg) 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 { @@ -363,8 +367,11 @@ void my_i2c_sensors_path(char *method) 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"); @@ -401,6 +408,8 @@ int plugin_init_i2c_sensors (void) error("i2c_sensors: unknown path %s, should start with /sys or /proc"); } } + + hash_create(&I2Csensors); return 0; } diff --git a/plugin_imon.c b/plugin_imon.c index 377bddd..7566f01 100755 --- a/plugin_imon.c +++ b/plugin_imon.c @@ -1,4 +1,4 @@ -/* $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 * @@ -22,6 +22,10 @@ * * * $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 * @@ -79,8 +83,8 @@ #include -static HASH TELMON = { 0, }; -static HASH IMON = { 0, }; +static HASH TELMON; +static HASH IMON; static char thost[256]; static int tport; @@ -251,7 +255,7 @@ static int parse_telmon(){ 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){ @@ -266,17 +270,17 @@ static int parse_telmon(){ 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); @@ -292,7 +296,7 @@ static void my_telmon (RESULT *result, RESULT *arg1){ return; } - val=hash_get(&TELMON, R2S(arg1)); + val=hash_get(&TELMON, R2S(arg1), NULL); if (val==NULL) val=""; SetResult(&result, R_STRING, val); } @@ -314,14 +318,14 @@ void init(){ 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; } @@ -329,7 +333,7 @@ static int parse_imon(char *cmd){ 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(); @@ -345,10 +349,10 @@ static void my_imon_version (RESULT *result){ } 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); } @@ -361,7 +365,7 @@ static int parse_imon_rates(char *channel){ 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 @@ -374,9 +378,9 @@ static int parse_imon_rates(char *channel){ 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; } @@ -393,7 +397,7 @@ static void my_imon_rates (RESULT *result, RESULT *arg1, RESULT *arg2){ 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); } @@ -406,7 +410,7 @@ static void my_imon (RESULT *result, RESULT *arg1){ return; } - val=hash_get(&IMON, cmd); + val=hash_get(&IMON, cmd, NULL); if (val==NULL) val=""; SetResult(&result, R_STRING, val); } @@ -414,6 +418,9 @@ static void my_imon (RESULT *result, RESULT *arg1){ 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()); diff --git a/plugin_isdn.c b/plugin_isdn.c index d616efc..4298d94 100644 --- a/plugin_isdn.c +++ b/plugin_isdn.c @@ -1,4 +1,4 @@ -/* $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 * @@ -26,6 +26,10 @@ * * * $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...) @@ -70,16 +74,16 @@ typedef struct { } 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) @@ -89,7 +93,7 @@ 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 @@ -124,7 +128,7 @@ static int parse_isdninfo (void) 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++; @@ -150,7 +154,7 @@ static void my_isdn_info (RESULT *result, RESULT *arg1, RESULT *arg2) } 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); } @@ -158,17 +162,17 @@ static void my_isdn_info (RESULT *result, RESULT *arg1, RESULT *arg2) #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); } @@ -180,7 +184,7 @@ static int get_cps(void) 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; @@ -204,9 +208,9 @@ static int get_cps(void) 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; } @@ -221,7 +225,7 @@ static void my_isdn_cps (RESULT *result, RESULT *arg1, RESULT *arg2) 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); } @@ -231,6 +235,9 @@ static void my_isdn_cps (RESULT *result, RESULT *arg1, RESULT *arg2) 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 diff --git a/plugin_meminfo.c b/plugin_meminfo.c index d9203de..a15565e 100644 --- a/plugin_meminfo.c +++ b/plugin_meminfo.c @@ -1,4 +1,4 @@ -/* $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 * @@ -23,6 +23,10 @@ * * * $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 @@ -82,7 +86,7 @@ #include "hash.h" -static HASH MemInfo = { 0, }; +static HASH MemInfo; static FILE *stream = NULL; static int parse_meminfo (void) @@ -90,7 +94,7 @@ 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"); @@ -121,7 +125,7 @@ static int parse_meminfo (void) // 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; @@ -137,7 +141,7 @@ static void my_meminfo (RESULT *result, RESULT *arg1) } key=R2S(arg1); - val=hash_get(&MemInfo, key); + val=hash_get(&MemInfo, key, NULL); if (val==NULL) val=""; SetResult(&result, R_STRING, val); @@ -146,6 +150,7 @@ static void my_meminfo (RESULT *result, RESULT *arg1) int plugin_init_meminfo (void) { + hash_create(&MemInfo); AddFunction ("meminfo", 1, my_meminfo); return 0; } diff --git a/plugin_netdev.c b/plugin_netdev.c index be2b411..c679ae1 100644 --- a/plugin_netdev.c +++ b/plugin_netdev.c @@ -1,4 +1,4 @@ -/* $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 * @@ -23,6 +23,10 @@ * * * $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 @@ -83,15 +87,17 @@ #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); } @@ -102,7 +108,7 @@ static int parse_netdev (void) 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"); @@ -148,7 +154,7 @@ static int parse_netdev (void) 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++; @@ -173,7 +179,7 @@ static void my_netdev (RESULT *result, RESULT *arg1, RESULT *arg2) 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); } @@ -192,7 +198,7 @@ static void my_netdev_fast(RESULT *result, RESULT *arg1, RESULT *arg2) 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); } @@ -200,6 +206,7 @@ static void my_netdev_fast(RESULT *result, RESULT *arg1, RESULT *arg2) int plugin_init_netdev (void) { + hash_create(&NetDev); AddFunction ("netdev", 2, my_netdev); AddFunction ("netdev::fast", 2, my_netdev_fast); return 0; diff --git a/plugin_ppp.c b/plugin_ppp.c index be51ff7..e77ed74 100644 --- a/plugin_ppp.c +++ b/plugin_ppp.c @@ -1,4 +1,4 @@ -/* $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 * @@ -23,6 +23,10 @@ * * * $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 @@ -77,7 +81,7 @@ #ifdef HAVE_NET_IF_PPP_H -static HASH PPP = { 0, }; +static HASH PPP; static int get_ppp_stats (void) { @@ -89,7 +93,7 @@ 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 @@ -114,10 +118,10 @@ static int get_ppp_stats (void) } 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; @@ -132,7 +136,7 @@ static void my_ppp (RESULT *result, RESULT *arg1, RESULT *arg2) 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); } @@ -141,6 +145,7 @@ static void my_ppp (RESULT *result, RESULT *arg1, RESULT *arg2) int plugin_init_ppp (void) { + hash_create(&PPP); #ifdef HAVE_NET_IF_PPP_H AddFunction ("ppp", 2, my_ppp); #endif @@ -149,5 +154,5 @@ int plugin_init_ppp (void) void plugin_exit_ppp(void) { - hash_destroy(&PPP); + hash_destroy(&PPP); } diff --git a/plugin_proc_stat.c b/plugin_proc_stat.c index af79a0c..6c20755 100644 --- a/plugin_proc_stat.c +++ b/plugin_proc_stat.c @@ -1,4 +1,4 @@ -/* $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 * @@ -23,6 +23,10 @@ * * * $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 @@ -123,31 +127,31 @@ #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); } @@ -156,7 +160,7 @@ static int parse_proc_stat (void) 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"); @@ -186,7 +190,7 @@ static int parse_proc_stat (void) 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; } } @@ -199,7 +203,7 @@ static int parse_proc_stat (void) 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; } } @@ -213,7 +217,7 @@ static int parse_proc_stat (void) 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; } } @@ -230,7 +234,7 @@ static int parse_proc_stat (void) 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; } } @@ -249,7 +253,7 @@ static int parse_proc_stat (void) 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; @@ -265,7 +269,7 @@ static int parse_proc_stat (void) 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; @@ -284,12 +288,12 @@ static void my_proc_stat (RESULT *result, int argc, RESULT *argv[]) 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: @@ -314,10 +318,10 @@ static void my_cpu (RESULT *result, RESULT *arg1, RESULT *arg2) 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; @@ -352,7 +356,7 @@ static void my_disk (RESULT *result, RESULT *arg1, RESULT *arg2, RESULT *arg3) 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); } @@ -360,6 +364,7 @@ static void my_disk (RESULT *result, RESULT *arg1, RESULT *arg2, RESULT *arg3) 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); diff --git a/plugin_seti.c b/plugin_seti.c index 9d3a82e..645d142 100644 --- a/plugin_seti.c +++ b/plugin_seti.c @@ -1,4 +1,4 @@ -/* $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 * @@ -27,6 +27,10 @@ * * * $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. * @@ -61,7 +65,7 @@ #define DIRKEY "Directory" #define STATEFILE "state.sah" -static HASH SETI = { 0, }; +static HASH SETI; static int fatal = 0; static int parse_seti (void) @@ -74,7 +78,7 @@ 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') { @@ -120,7 +124,7 @@ static int parse_seti (void) 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); @@ -139,7 +143,7 @@ static void my_seti (RESULT *result, RESULT *arg1) } key=R2S(arg1); - val=hash_get(&SETI, key); + val=hash_get(&SETI, key, NULL); if (val==NULL) val=""; SetResult(&result, R_STRING, val); @@ -148,6 +152,7 @@ static void my_seti (RESULT *result, RESULT *arg1) int plugin_init_seti (void) { + hash_create(&SETI); AddFunction ("seti", 1, my_seti); return 0; } diff --git a/plugin_wireless.c b/plugin_wireless.c index df626e8..23385fa 100755 --- a/plugin_wireless.c +++ b/plugin_wireless.c @@ -1,4 +1,4 @@ -/* $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 * @@ -28,6 +28,10 @@ * * * $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 @@ -104,7 +108,7 @@ #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[] = { @@ -181,7 +185,7 @@ static int get_ifname(struct iwreq *preq, char *dev) { return -1; } - hash_set(&wireless,key_buffer, preq->u.name); + hash_put(&wireless,key_buffer, preq->u.name); return(0); } @@ -195,7 +199,7 @@ static int get_frequency(char* dev,char* key) { 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) { @@ -226,7 +230,7 @@ static int get_frequency(char* dev,char* key) { */ snprintf(qprintf_buffer,sizeof(qprintf_buffer), "%g", freq); - hash_set(&wireless, key_buffer, qprintf_buffer); + hash_put(&wireless, key_buffer, qprintf_buffer); return(0); } @@ -240,7 +244,7 @@ static int get_essid(char* dev,char* key) { 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) { @@ -261,7 +265,7 @@ static int get_essid(char* dev,char* key) { return -1; } - hash_set(&wireless,key_buffer, essid_buffer); + hash_put(&wireless,key_buffer, essid_buffer); return(0); } @@ -273,7 +277,7 @@ static int get_op_mode(char* dev,char* key) { 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) { @@ -293,7 +297,7 @@ static int get_op_mode(char* dev,char* key) { 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); } @@ -307,7 +311,7 @@ static int get_bitrate(char* dev,char* key) { 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) { @@ -335,7 +339,7 @@ static int get_bitrate(char* dev,char* key) { */ snprintf(bitrate_buffer,sizeof(bitrate_buffer), "%g", bitrate); - hash_set(&wireless,key_buffer, bitrate_buffer); + hash_put(&wireless,key_buffer, bitrate_buffer); return(0); } @@ -351,7 +355,7 @@ static int get_sens(char* dev,char* key) { 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) { @@ -385,7 +389,7 @@ static int get_sens(char* dev,char* key) { qprintf(buffer, sizeof(buffer), "%d", req.u.sens.value); } - hash_set(&wireless,key_buffer, buffer); + hash_put(&wireless,key_buffer, buffer); return(0); } @@ -401,7 +405,7 @@ static int get_sec_mode(char* dev,char* key) { 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) { @@ -430,9 +434,9 @@ static int get_sec_mode(char* dev,char* key) { // 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); } @@ -447,7 +451,7 @@ static int get_stats(char *dev, char *key) 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) { @@ -473,28 +477,28 @@ static int get_stats(char *dev, char *key) 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; @@ -529,7 +533,7 @@ static void save_result(RESULT *result, char* dev, char* key, int res) { return; } - val=hash_get(&wireless,key_buffer); + val=hash_get(&wireless,key_buffer, NULL); if (val) { SetResult(&result, R_STRING, val); @@ -622,6 +626,8 @@ init and cleanup 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); diff --git a/plugin_xmms.c b/plugin_xmms.c index 25d3add..e38ef6e 100644 --- a/plugin_xmms.c +++ b/plugin_xmms.c @@ -1,4 +1,4 @@ -/* $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 @@ -21,6 +21,10 @@ * * * $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 @@ -95,7 +99,7 @@ #include "plugin.h" -static HASH xmms = { 0, }; +static HASH xmms; static int parse_xmms_info (void) @@ -105,7 +109,7 @@ 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"); @@ -131,7 +135,7 @@ static int parse_xmms_info (void) // 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); @@ -149,7 +153,7 @@ static void my_xmms (RESULT *result, RESULT *arg1) } key=R2S(arg1); - val=hash_get(&xmms, key); + val=hash_get(&xmms, key, NULL); if (val==NULL) val=""; SetResult(&result, R_STRING, val); @@ -158,6 +162,7 @@ static void my_xmms (RESULT *result, RESULT *arg1) int plugin_init_xmms (void) { + hash_create(&xmms); // register xmms info AddFunction ("xmms", 1, my_xmms); @@ -167,5 +172,5 @@ int plugin_init_xmms (void) void plugin_exit_xmms(void) { - hash_destroy(&xmms); + hash_destroy(&xmms); } -- cgit v1.2.3