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

Comparing projects/libstatgrab/src/libstatgrab/cpu_stats.c (file contents):
Revision 1.26 by tdb, Sat Sep 24 13:29:22 2005 UTC vs.
Revision 1.28 by tdb, Tue Jun 17 15:52:52 2008 UTC

# Line 76 | Line 76 | sg_cpu_stats *sg_get_cpu_stats(){
76   #endif
77   #if defined(LINUX) || defined(CYGWIN)
78          FILE *f;
79 +        int proc_stat_cpu;
80   #endif
81   #ifdef ALLBSD
82   #if defined(NETBSD) || defined(OPENBSD)
# Line 125 | Line 126 | sg_cpu_stats *sg_get_cpu_stats(){
126                          continue;
127                  }
128                  cpu_now.user+=(long long)cs.cpu_sysinfo.cpu[CPU_USER];
128                cpu_now.iowait+=(long long)cs.cpu_sysinfo.cpu[CPU_WAIT];
129                  cpu_now.kernel+=(long long)cs.cpu_sysinfo.cpu[CPU_KERNEL];
130                  cpu_now.idle+=(long long)cs.cpu_sysinfo.cpu[CPU_IDLE];
131 <                cpu_now.swap+=(long long)cs.cpu_sysinfo.cpu[CPU_STATES];
131 >                cpu_now.iowait+=(long long)cs.cpu_sysinfo.wait[W_IO]+(long long)cs.cpu_sysinfo.wait[W_PIO];
132 >                cpu_now.swap+=(long long)cs.cpu_sysinfo.wait[W_SWAP];
133          }
134  
135          cpu_now.total=cpu_now.user+cpu_now.iowait+cpu_now.kernel+cpu_now.idle+cpu_now.swap;
# Line 140 | Line 141 | sg_cpu_stats *sg_get_cpu_stats(){
141                  sg_set_error_with_errno(SG_ERROR_OPEN, "/proc/stat");
142                  return NULL;
143          }
144 +
145          /* The very first line should be cpu */
146 <        if((fscanf(f, "cpu %lld %lld %lld %lld", \
146 >        proc_stat_cpu = fscanf(f, "cpu %lld %lld %lld %lld %lld", \
147                  &cpu_now.user, \
148                  &cpu_now.nice, \
149                  &cpu_now.kernel, \
150 <                &cpu_now.idle)) != 4){
150 >                &cpu_now.idle, \
151 >                &cpu_now.iowait);
152 >
153 >        fclose(f);
154 >
155 >        if (proc_stat_cpu < 4 || proc_stat_cpu > 5) {
156                  sg_set_error(SG_ERROR_PARSE, "cpu");
150                fclose(f);
157                  return NULL;
158          }
159  
160 <        fclose(f);
160 >        /* older linux doesn't give iowait */
161 >        if (proc_stat_cpu == 4) {
162 >                cpu_now.iowait = 0;
163 >        }
164  
165          cpu_now.total=cpu_now.user+cpu_now.nice+cpu_now.kernel+cpu_now.idle;
166   #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines