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.12 by ats, Sun Oct 19 00:25:30 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 45 | Line 45
45   #endif
46   #ifdef FREEBSD
47   #include <kvm.h>
48 #include <fcntl.h>
48   #include <sys/param.h>
49   #include <sys/sysctl.h>
50   #include <sys/user.h>
# Line 69 | Line 68 | process_stat_t *get_process_stats(){
68   #endif
69   #ifdef FREEBSD
70          struct kinfo_proc *kp_stats;    
71 <        kvm_t *kvmd = NULL;
71 >        kvm_t *kvmd;
72          int procs;
73   #endif
74  
76 #if defined(SOLARIS) || defined(LINUX)
75          process_stat.sleeping=0;
76          process_stat.running=0;
77          process_stat.zombie=0;
78          process_stat.stopped=0;
79          process_stat.total=0;
80  
81 + #if defined(SOLARIS) || defined(LINUX)
82          if((proc_dir=opendir(PROC_LOCATION))==NULL){
83                  return NULL;
84          }
# Line 135 | Line 134 | process_stat_t *get_process_stats(){
134          closedir(proc_dir);
135   #endif
136   #ifdef FREEBSD
137 <        if((kvmd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, NULL)) == NULL){
137 >        if((kvmd = get_kvm()) == NULL){
138                  return NULL;
139          }
140  
141          kp_stats=kvm_getprocs(kvmd, KERN_PROC_ALL, 0, &procs);
142  
143          while(procs--){
144 + #ifdef FREEBSD5
145 +                if (kp_stats[procs].ki_stat == SSLEEP) process_stat.sleeping++;
146 +                if (kp_stats[procs].ki_stat == SWAIT) process_stat.sleeping++;
147 +                if (kp_stats[procs].ki_stat == SLOCK) process_stat.sleeping++;
148 +                if (kp_stats[procs].ki_stat == SRUN) process_stat.running++;
149 +                if (kp_stats[procs].ki_stat == SIDL) process_stat.running++;
150 +                if (kp_stats[procs].ki_stat == SZOMB) process_stat.zombie++;
151 +                if (kp_stats[procs].ki_stat == SSTOP) process_stat.stopped++;
152 +                
153 + #else
154                  if (kp_stats[procs].kp_proc.p_stat == SSLEEP) process_stat.sleeping++;  
155                  if (kp_stats[procs].kp_proc.p_stat == SRUN) process_stat.running++;
156                  if (kp_stats[procs].kp_proc.p_stat == SIDL) process_stat.running++;
157                  if (kp_stats[procs].kp_proc.p_stat == SZOMB) process_stat.zombie++;
158                  if (kp_stats[procs].kp_proc.p_stat == SSTOP) process_stat.stopped++;
159 + #endif
160          }
151
152        kvm_close(kvmd);
161   #endif
162  
163          process_stat.total=process_stat.sleeping+process_stat.running+process_stat.zombie+process_stat.stopped;
164 +
165          return &process_stat;
166   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines