[Sysfence-commit] sysfence datastruct.c,1.5,1.6 datastruct.h,1.5,1.6 getstats.c,1.15,1.16
Status: Alpha
Brought to you by:
emes
|
From: Michal S. <em...@us...> - 2004-05-30 18:23:42
|
Update of /cvsroot/sysfence/sysfence In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13186 Modified Files: datastruct.c datastruct.h getstats.c Log Message: + functions handling process database Index: datastruct.h =================================================================== RCS file: /cvsroot/sysfence/sysfence/datastruct.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- datastruct.h 29 May 2004 17:31:05 -0000 1.5 +++ datastruct.h 30 May 2004 18:23:33 -0000 1.6 @@ -86,7 +86,7 @@ // Selector or option describing stat int laminutes; // load sf_res_state resstat; // resources - int procstates; // processes + char procstates; // processes sf_list *uids; // processes char *path; // filesystem } sf_stat_arg; @@ -177,11 +177,12 @@ typedef struct { // Main statistics database - double load[3]; - long int mem[ VA_LAST ]; - long int swap[ VA_LAST ]; - sf_list *fs; - void *proc; // NIY + double load[3]; + long int mem[ VA_LAST ]; + long int swap[ VA_LAST ]; + sf_list *fs; // list of filesystems being watched + int nr_proc; // number of process entries in array + sf_proc_stat *proc; // array of processes } sf_database; /*************************************************************************** @@ -192,7 +193,9 @@ int equal_defs (sf_stat_def *d1, sf_stat_def *d2); int uid_in_list (sf_list *hd, uid_t uid); void add_fs_entry_to_list (sf_list **hd, char *path); +void add_proc_entry_to_array (sf_database *db, sf_proc_stat *proc); sf_fs_stat * get_fs_entry_from_list (sf_list *hd, char *path); +int get_proc_num (sf_database *db, char statemask, uid_t *uid); char * def_2_string (sf_stat_def *def); /* $Id$ */ Index: getstats.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/getstats.c,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- getstats.c 29 May 2004 17:29:28 -0000 1.15 +++ getstats.c 30 May 2004 18:23:33 -0000 1.16 @@ -14,16 +14,17 @@ /* $Id$ */ -#include "sys/exit.h" -#include "parseopt/lex.h" -#include "datastruct.h" -#include "getstats.h" #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <fcntl.h> #include <string.h> #include <sys/vfs.h> +#include "sys/xalloc.h" +#include "sys/exit.h" +#include "parseopt/lex.h" +#include "datastruct.h" +#include "getstats.h" #ifdef DEBUG #include <syslog.h> @@ -33,7 +34,7 @@ sf_value get_stat_fs (sf_stat_def *def, sf_list *fslist) { sf_value res; - sf_fs_stat *fs = get_fs_entry_from_list (fslist, def->arg[1].path); + sf_fs_stat *fs = get_fs_entry_from_list (fslist, def->arg[1].path); sf_res_state slctr = def->arg[0].resstat; #ifdef DEBUG @@ -52,11 +53,20 @@ return res; } -sf_value get_stat_proc (sf_stat_def *def, void *proctab) +sf_value get_nproc (sf_stat_def *def, sf_database *db) { - sf_value res; + long int *nproc = (long int *) xalloc (NULL, sizeof (long int)); + sf_value res = { INTEGER, nproc }; + sf_list *uids = def->arg[0].uids; + char statemask = def->arg[1].procstates; + + if (! uids) *nproc = get_proc_num (db, statemask, NULL); + + while (uids) { + *nproc += get_proc_num (db, statemask, (uid_t *) uids->el); + uids = uids->next; + } - bail_out (EXIT_BUG, "get_stat_proc(): NIY"); return res; } @@ -71,7 +81,7 @@ switch (def->label) { case ST_PROC: - res = get_stat_proc (def, main_db->proc); + res = get_nproc (def, main_db); break; case ST_FS: res = get_stat_fs (def, main_db->fs); Index: datastruct.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/datastruct.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- datastruct.c 29 May 2004 17:29:28 -0000 1.5 +++ datastruct.c 30 May 2004 18:23:33 -0000 1.6 @@ -24,6 +24,38 @@ #include <syslog.h> #endif +void add_proc_entry_to_array (sf_database *db, sf_proc_stat *proc) +{ + sf_proc_stat *arr = db->proc; + + // go to end of array + arr += db->nr_proc; + memcpy (arr, proc, sizeof (sf_proc_stat)); + db->nr_proc ++; +} + +int get_proc_num (sf_database *db, char statemask, uid_t *uid) +{ + /* returns number of processes selecting by uid and state mask */ + + int count = 0; + sf_proc_stat *cur = db->proc; + + for (cur = db->proc; + cur - db->proc < db->nr_proc; + cur ++) { + + if (uid) + if (cur->uid != *uid) continue; + + if (! (cur->state & statemask)) continue; + + count ++; + } + + return count; +} + void add_def_to_list (sf_list **hd, sf_stat_def *def) { /* adds stat def to list, discarding duplicates */ |