[Sysfence-commit] sysfence datastruct.c,1.6,1.7 datastruct.h,1.7,1.8 getstats.c,1.17,1.18 getstats.h
Status: Alpha
Brought to you by:
emes
|
From: Michal S. <em...@us...> - 2004-05-31 11:59:41
|
Update of /cvsroot/sysfence/sysfence In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17725 Modified Files: datastruct.c datastruct.h getstats.c getstats.h sysfence.c Log Message: + debugging info Index: getstats.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/getstats.c,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- getstats.c 31 May 2004 10:30:33 -0000 1.17 +++ getstats.c 31 May 2004 11:59:29 -0000 1.18 @@ -22,17 +22,13 @@ #include <sys/vfs.h> #include <dirent.h> #include <sys/stat.h> +#include <syslog.h> #include "sys/xalloc.h" #include "sys/exit.h" #include "parseopt/lex.h" #include "datastruct.h" #include "getstats.h" -#ifdef DEBUG -#include <syslog.h> -#include "sys/log.h" -#endif - sf_value get_stat_fs (sf_stat_def *def, sf_list *fslist) { sf_value res; @@ -119,6 +115,7 @@ } const char *procdir = "/proc"; +const char *maxtfile = "/proc/sys/kernel/threads-max"; const char *lafile = "/proc/loadavg"; int lafha; const char *memfile = "/proc/meminfo"; @@ -208,21 +205,29 @@ void fetch_pathspace (sf_fs_stat *fs) { struct statfs buf; - long int bsizeKB; statfs (fs->path, &buf); /* block size in KB */ bsizeKB = buf.f_bsize / 1024; - + + /* sizes are in kilobytes */ fs->val[VA_TOTAL] = buf.f_blocks * bsizeKB; fs->val[VA_AVAIL] = buf.f_bavail * bsizeKB; fs->val[VA_FREE] = buf.f_bfree * bsizeKB; fs->val[VA_USED] = (buf.f_blocks - buf.f_bfree) * bsizeKB; - + #ifdef DEBUG syslog (LOG_DEBUG, - "fetch_pathspace(): path %s total=%d used=%d free=%d available=%d\n", + "fetch_pathspace(): path %s bsize=%ld btotal=%ld bfree=%ld bavail=%ld", + fs->path, + buf.f_bsize, + buf.f_blocks, + buf.f_bfree, + buf.f_bavail + ); + syslog (LOG_DEBUG, + "fetch_pathspace(): path %s total=%luk used=%luk free=%luk avail=%luk", fs->path, fs->val[VA_TOTAL], fs->val[VA_USED], @@ -340,6 +345,24 @@ if (memfha < 0) bail_out (EXIT_IO, memfile); } +long int get_max_threads () +{ + int fh = open (maxtfile, O_RDONLY); + int mt; + + if (fh < 0) bail_out (EXIT_IO, maxtfile); + read (fh, &fbuf[0], BUFSIZE); + + mt = atol (&fbuf[0]); + + close (fh); + + syslog (LOG_NOTICE, "maximum number of threads in system: %ld", mt); + + return mt; +} + + /* fast text parsing helpers */ char * fto_newline (char *b) Index: datastruct.h =================================================================== RCS file: /cvsroot/sysfence/sysfence/datastruct.h,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- datastruct.h 31 May 2004 10:30:32 -0000 1.7 +++ datastruct.h 31 May 2004 11:59:29 -0000 1.8 @@ -166,8 +166,8 @@ typedef struct { // Statistics of underlying filesystem in path - char *path; - long int val[ VA_LAST ]; + char *path; + unsigned long int val[ VA_LAST ]; } sf_fs_stat; typedef struct { Index: getstats.h =================================================================== RCS file: /cvsroot/sysfence/sysfence/getstats.h,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- getstats.h 31 May 2004 10:30:33 -0000 1.10 +++ getstats.h 31 May 2004 11:59:29 -0000 1.11 @@ -17,8 +17,6 @@ #define BUFSIZE 512 #define PROCDIRNAMELEN 25 -#define PROC_DATA_SIZE 524288 // 512k - /* shared memory segments */ int db_shmid, fs_shmid, proc_shmid, rules_shmid; void *db_shm, *fs_shm, *proc_shm, *rules_shm; @@ -36,6 +34,8 @@ void fetch_fs (sf_database *db); void fetch_proc (sf_database *db); +long int get_max_threads (); + void open_files (); char * fto_newline (char *b); Index: datastruct.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/datastruct.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- datastruct.c 30 May 2004 18:23:33 -0000 1.6 +++ datastruct.c 31 May 2004 11:59:29 -0000 1.7 @@ -27,6 +27,13 @@ void add_proc_entry_to_array (sf_database *db, sf_proc_stat *proc) { sf_proc_stat *arr = db->proc; + +#ifdef DEBUG + syslog (LOG_DEBUG, + "add_proc_entry_to_array: uid=%d, state=%d", + proc->uid, + proc->state); +#endif // go to end of array arr += db->nr_proc; Index: sysfence.c =================================================================== RCS file: /cvsroot/sysfence/sysfence/sysfence.c,v retrieving revision 1.23 retrieving revision 1.24 diff -u -d -r1.23 -r1.24 --- sysfence.c 29 May 2004 08:26:20 -0000 1.23 +++ sysfence.c 31 May 2004 11:59:29 -0000 1.24 @@ -112,7 +112,7 @@ } /* initialize shared memory for proc database */ - proc_shmid = shared_mem_init (PROC_DATA_SIZE); + proc_shmid = shared_mem_init (get_max_threads () * sizeof (sf_proc_stat)); if (proc_shmid < 0) bail_out (EXIT_SHM, NULL); proc_shm = shared_mem_attach (proc_shmid); |