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.27 by tdb, Mon Oct 9 13:52:06 2006 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 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