[lcd4linux @ 2004-03-03 03:47:04 by reinelt]

big patch from Martin Hejl:
- use qprintf() where appropriate
- save CPU cycles on gettimeofday()
- add quit() functions to free allocated memory
- fixed lots of memory leaks

git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@384 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
This commit is contained in:
reinelt
2004-03-03 03:47:04 +00:00
parent d0b39b590e
commit 9ef4282e9e
46 changed files with 770 additions and 167 deletions

View File

@@ -1,4 +1,4 @@
/* $Id: plugin_proc_stat.c,v 1.15 2004/02/04 19:10:51 reinelt Exp $
/* $Id: plugin_proc_stat.c,v 1.16 2004/03/03 03:47:04 reinelt Exp $
*
* plugin for /proc/stat parsing
*
@@ -23,6 +23,13 @@
*
*
* $Log: plugin_proc_stat.c,v $
* Revision 1.16 2004/03/03 03:47:04 reinelt
* big patch from Martin Hejl:
* - use qprintf() where appropriate
* - save CPU cycles on gettimeofday()
* - add quit() functions to free allocated memory
* - fixed lots of memory leaks
*
* Revision 1.15 2004/02/04 19:10:51 reinelt
* Crystalfontz driver nearly finished
*
@@ -97,6 +104,7 @@
#include "debug.h"
#include "plugin.h"
#include "hash.h"
#include "qprintf.h"
static HASH Stat = { 0, };
@@ -111,7 +119,7 @@ static void hash_set2 (char *key1, char *key2, char *val)
{
char key[32];
snprintf (key, sizeof(key), "%s.%s", key1, key2);
qprintf(key, sizeof(key), "%s.%s", key1, key2);
hash_set1 (key, val);
}
@@ -120,7 +128,7 @@ static void hash_set3 (char *key1, char *key2, char *key3, char *val)
{
char key[32];
snprintf (key, sizeof(key), "%s.%s.%s", key1, key2, key3);
qprintf(key, sizeof(key), "%s.%s.%s", key1, key2, key3);
hash_set1 (key, val);
}
@@ -201,9 +209,9 @@ static int parse_proc_stat (void)
while (strchr(delim, *beg)) beg++;
if ((end=strpbrk(beg, delim))) *end='\0';
if (i==0)
snprintf(num, sizeof(num), "sum");
strncpy(num,"sum",sizeof(num));
else
snprintf(num, sizeof(num), "%d", i-1);
qprintf(num, sizeof(num), "%d", i-1);
hash_set2 ("intr", num, beg);
beg=end?end+1:NULL;
}
@@ -328,7 +336,7 @@ static void my_disk (RESULT *result, RESULT *arg1, RESULT *arg2, RESULT *arg3)
key = R2S(arg2);
delay = R2N(arg3);
snprintf (buffer, sizeof(buffer), "disk_io\\.%s\\.%s", dev, key);
qprintf(buffer, sizeof(buffer), "disk_io\\.%s\\.%s", dev, key);
value = hash_get_regex(&Stat, buffer, delay);
SetResult(&result, R_NUMBER, &value);
@@ -342,3 +350,8 @@ int plugin_init_proc_stat (void)
AddFunction ("disk", 3, my_disk);
return 0;
}
void plugin_exit_proc_stat(void)
{
hash_destroy(&Stat);
}