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.6 by pajs, Thu Apr 3 23:14:57 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 31 | Line 31
31   #include <string.h>
32   #endif
33  
34 + #include "tools.h"
35   #ifdef SOLARIS
36   #include <procfs.h>
37   #include <limits.h>
# Line 38 | 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 FREEBSD
50 > #ifdef ALLBSD
51   #include <kvm.h>
48 #include <fcntl.h>
52   #include <sys/param.h>
53   #include <sys/sysctl.h>
54 + #endif
55 + #ifdef FREEBSD
56   #include <sys/user.h>
57   #endif
58  
# Line 67 | Line 72 | process_stat_t *get_process_stats(){
72   #ifdef SOLARIS
73          psinfo_t process_info;
74   #endif
75 < #ifdef FREEBSD
75 > #ifdef ALLBSD
76          struct kinfo_proc *kp_stats;    
77 <        kvm_t *kvmd = NULL;
77 >        kvm_t *kvmd;
78          int procs;
79   #endif
80  
76 #if defined(SOLARIS) || defined(LINUX)
81          process_stat.sleeping=0;
82          process_stat.running=0;
83          process_stat.zombie=0;
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 134 | Line 139 | process_stat_t *get_process_stats(){
139          }
140          closedir(proc_dir);
141   #endif
142 < #ifdef FREEBSD
143 <        if((kvmd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, NULL)) == NULL){
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          }
151
152        kvm_close(kvmd);
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