ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/libstatgrab/src/libstatgrab/process_stats.c
(Generate patch)

Comparing projects/libstatgrab/src/libstatgrab/process_stats.c (file contents):
Revision 1.5 by pajs, Fri Mar 7 15:26:30 2003 UTC vs.
Revision 1.14 by tdb, Mon Nov 10 21:07:04 2003 UTC

# Line 1 | Line 1
1   /*
2   * i-scream central monitoring system
3 < * http://www.i-scream.org.uk
4 < * Copyright (C) 2000-2002 i-scream
3 > * http://www.i-scream.org
4 > * Copyright (C) 2000-2003 i-scream
5   *
6   * This program is free software; you can redistribute it and/or
7   * modify it under the terms of the GNU General Public License
# Line 22 | Line 22
22   #include "config.h"
23   #endif
24  
25 + #include "statgrab.h"
26 + #if defined(SOLARIS) || defined(LINUX)
27   #include <stdio.h>
28   #include <stdlib.h>
27 #include "statgrab.h"
29   #include <sys/types.h>
30   #include <dirent.h>
31   #include <string.h>
32 + #endif
33  
34 + #include "tools.h"
35   #ifdef SOLARIS
36   #include <procfs.h>
37   #include <limits.h>
# Line 36 | Line 39
39   #define MAX_FILE_LENGTH PATH_MAX
40   #endif
41   #ifdef LINUX
42 < #include "tools.h"
42 > #ifdef CYGWIN
43 > #include <limits.h>
44 > #else
45   #include <linux/limits.h>
46 + #endif
47   #define PROC_LOCATION "/proc"
48   #define MAX_FILE_LENGTH PATH_MAX
49   #endif
50 + #ifdef ALLBSD
51 + #include <kvm.h>
52 + #include <sys/param.h>
53 + #include <sys/sysctl.h>
54 + #endif
55 + #ifdef FREEBSD
56 + #include <sys/user.h>
57 + #endif
58  
59   process_stat_t *get_process_stats(){
60  
61          static process_stat_t process_stat;
62  
63 + #if defined(SOLARIS) || defined(LINUX)
64          DIR *proc_dir;
65          struct dirent *dir_entry;
66          char filename[MAX_FILE_LENGTH];
67          FILE *f;
68 + #endif
69   #ifdef LINUX
70          char *line_ptr;
71   #endif
72   #ifdef SOLARIS
73          psinfo_t process_info;
74   #endif
75 + #ifdef ALLBSD
76 +        struct kinfo_proc *kp_stats;    
77 +        kvm_t *kvmd;
78 +        int procs;
79 + #endif
80  
81          process_stat.sleeping=0;
82          process_stat.running=0;
# Line 63 | Line 84 | process_stat_t *get_process_stats(){
84          process_stat.stopped=0;
85          process_stat.total=0;
86  
87 + #if defined(SOLARIS) || defined(LINUX)
88          if((proc_dir=opendir(PROC_LOCATION))==NULL){
89                  return NULL;
90          }
# Line 116 | Line 138 | process_stat_t *get_process_stats(){
138                  fclose(f);
139          }
140          closedir(proc_dir);
141 + #endif
142 + #ifdef ALLBSD
143 +        if((kvmd = get_kvm()) == NULL){
144 +                return NULL;
145 +        }
146  
147 +        kp_stats=kvm_getprocs(kvmd, KERN_PROC_ALL, 0, &procs);
148  
149 +        while(procs--){
150 + #ifdef FREEBSD5
151 +                if (kp_stats[procs].ki_stat == SSLEEP) process_stat.sleeping++;
152 +                if (kp_stats[procs].ki_stat == SWAIT) process_stat.sleeping++;
153 +                if (kp_stats[procs].ki_stat == SLOCK) process_stat.sleeping++;
154 +                if (kp_stats[procs].ki_stat == SRUN) process_stat.running++;
155 +                if (kp_stats[procs].ki_stat == SIDL) process_stat.running++;
156 +                if (kp_stats[procs].ki_stat == SZOMB) process_stat.zombie++;
157 +                if (kp_stats[procs].ki_stat == SSTOP) process_stat.stopped++;
158 +                
159 + #else
160 +                if (kp_stats[procs].kp_proc.p_stat == SSLEEP) process_stat.sleeping++;  
161 +                if (kp_stats[procs].kp_proc.p_stat == SRUN) process_stat.running++;
162 +                if (kp_stats[procs].kp_proc.p_stat == SIDL) process_stat.running++;
163 +                if (kp_stats[procs].kp_proc.p_stat == SZOMB) process_stat.zombie++;
164 +                if (kp_stats[procs].kp_proc.p_stat == SSTOP) process_stat.stopped++;
165 + #endif
166 +        }
167 + #endif
168 +
169          process_stat.total=process_stat.sleeping+process_stat.running+process_stat.zombie+process_stat.stopped;
170 +
171          return &process_stat;
172   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines