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.17 by tdb, Fri Jan 16 15:54:54 2004 UTC

# Line 1 | Line 1
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-2004 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
8 < * as published by the Free Software Foundation; either version 2
9 < * of the License, or (at your option) any later version.
6 > * This library is free software; you can redistribute it and/or
7 > * modify it under the terms of the GNU Lesser General Public
8 > * License as published by the Free Software Foundation; either
9 > * version 2.1 of the License, or (at your option) any later version.
10   *
11 < * This program is distributed in the hope that it will be useful,
11 > * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 < * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 < * GNU General Public License for more details.
13 > * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 > * Lesser General Public License for more details.
15   *
16 < * You should have received a copy of the GNU General Public License
17 < * along with this program; if not, write to the Free Software
18 < * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16 > * You should have received a copy of the GNU Lesser General Public
17 > * License along with this library; if not, write to the Free Software
18 > * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 > * 02111-1307 USA
20   */
21  
22   #ifdef HAVE_CONFIG_H
23   #include "config.h"
24   #endif
25  
26 + #include "statgrab.h"
27 + #if defined(SOLARIS) || defined(LINUX)
28   #include <stdio.h>
29   #include <stdlib.h>
27 #include "statgrab.h"
30   #include <sys/types.h>
31   #include <dirent.h>
32   #include <string.h>
33 + #endif
34  
35 + #include "tools.h"
36   #ifdef SOLARIS
37   #include <procfs.h>
38   #include <limits.h>
# Line 36 | Line 40
40   #define MAX_FILE_LENGTH PATH_MAX
41   #endif
42   #ifdef LINUX
43 < #include "tools.h"
40 < #include <linux/limits.h>
43 > #include <limits.h>
44   #define PROC_LOCATION "/proc"
45   #define MAX_FILE_LENGTH PATH_MAX
46   #endif
47 + #ifdef ALLBSD
48 + #include <kvm.h>
49 + #include <sys/param.h>
50 + #include <sys/sysctl.h>
51 + #endif
52 + #ifdef FREEBSD
53 + #include <sys/user.h>
54 + #endif
55  
56   process_stat_t *get_process_stats(){
57  
58          static process_stat_t process_stat;
59  
60 + #if defined(SOLARIS) || defined(LINUX)
61          DIR *proc_dir;
62          struct dirent *dir_entry;
63          char filename[MAX_FILE_LENGTH];
64          FILE *f;
65 + #endif
66   #ifdef LINUX
67          char *line_ptr;
68   #endif
69   #ifdef SOLARIS
70          psinfo_t process_info;
71   #endif
72 + #ifdef ALLBSD
73 +        struct kinfo_proc *kp_stats;    
74 +        kvm_t *kvmd;
75 +        int procs;
76 + #endif
77  
78          process_stat.sleeping=0;
79          process_stat.running=0;
# Line 63 | Line 81 | process_stat_t *get_process_stats(){
81          process_stat.stopped=0;
82          process_stat.total=0;
83  
84 + #if defined(SOLARIS) || defined(LINUX)
85          if((proc_dir=opendir(PROC_LOCATION))==NULL){
86                  return NULL;
87          }
# Line 116 | Line 135 | process_stat_t *get_process_stats(){
135                  fclose(f);
136          }
137          closedir(proc_dir);
138 + #endif
139 + #ifdef ALLBSD
140 +        if((kvmd = get_kvm()) == NULL){
141 +                return NULL;
142 +        }
143  
144 +        kp_stats=kvm_getprocs(kvmd, KERN_PROC_ALL, 0, &procs);
145  
146 +        while(procs--){
147 + #ifdef FREEBSD5
148 +                if (kp_stats[procs].ki_stat == SSLEEP) process_stat.sleeping++;
149 +                if (kp_stats[procs].ki_stat == SWAIT) process_stat.sleeping++;
150 +                if (kp_stats[procs].ki_stat == SLOCK) process_stat.sleeping++;
151 +                if (kp_stats[procs].ki_stat == SRUN) process_stat.running++;
152 +                if (kp_stats[procs].ki_stat == SIDL) process_stat.running++;
153 +                if (kp_stats[procs].ki_stat == SZOMB) process_stat.zombie++;
154 +                if (kp_stats[procs].ki_stat == SSTOP) process_stat.stopped++;
155 +                
156 + #else
157 +                if (kp_stats[procs].kp_proc.p_stat == SSLEEP) process_stat.sleeping++;  
158 +                if (kp_stats[procs].kp_proc.p_stat == SRUN) process_stat.running++;
159 +                if (kp_stats[procs].kp_proc.p_stat == SIDL) process_stat.running++;
160 +                if (kp_stats[procs].kp_proc.p_stat == SZOMB) process_stat.zombie++;
161 +                if (kp_stats[procs].kp_proc.p_stat == SSTOP) process_stat.stopped++;
162 + #endif
163 +        }
164 + #endif
165 +
166 + #ifdef CYGWIN
167 +        return NULL;
168 + #endif
169 +
170          process_stat.total=process_stat.sleeping+process_stat.running+process_stat.zombie+process_stat.stopped;
171 +
172          return &process_stat;
173   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines