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

Comparing projects/libstatgrab/src/libstatgrab/memory_stats.c (file contents):
Revision 1.14 by ats, Mon Oct 20 18:13:35 2003 UTC vs.
Revision 1.15 by ats, Fri Oct 24 17:03:20 2003 UTC

# Line 51 | Line 51 | mem_stat_t *get_memory_stats(){
51   #endif
52   #ifdef LINUX
53          char *line_ptr;
54 +        unsigned long long value;
55          FILE *f;
56   #endif
57   #ifdef FREEBSD
# Line 95 | Line 96 | mem_stat_t *get_memory_stats(){
96   #endif
97  
98   #ifdef LINUX
99 <        f=fopen("/proc/meminfo", "r");
100 <        if(f==NULL){
99 >        f = fopen("/proc/meminfo", "r");
100 >        if (f == NULL) {
101                  return NULL;
102          }
103  
104 <        if((line_ptr=f_read_line(f, "Mem:"))==NULL){
105 <                fclose(f);
106 <                return NULL;
107 <        }
104 >        while ((line_ptr = f_read_line(f, "")) != NULL) {
105 >                if (sscanf(line_ptr, "%*s %lld kB", &value) != 2) {
106 >                        continue;
107 >                }
108 >                value *= 1024;
109  
110 <        fclose(f);
111 <
112 <        /* Linux actually stores this as a unsigned long long, but
113 <         * our structures are just long longs. This shouldn't be a
114 <         * problem for sometime yet :)
115 <         */
116 <        if((sscanf(line_ptr,"Mem:  %lld %lld %lld %*d %*d %lld", \
115 <                &mem_stat.total, \
116 <                &mem_stat.used, \
117 <                &mem_stat.free, \
118 <                &mem_stat.cache))!=4){
119 <                        return NULL;
110 >                if (strncmp(line_ptr, "MemTotal:", 9) == 0) {
111 >                        mem_stat.total = value;
112 >                } else if (strncmp(line_ptr, "MemFree:", 8) == 0) {
113 >                        mem_stat.free = value;
114 >                } else if (strncmp(line_ptr, "Cached:", 7) == 0) {
115 >                        mem_stat.cache = value;
116 >                }
117          }
118  
119 +        fclose(f);
120 +        mem_stat.used = mem_stat.total - mem_stat.free;
121   #endif
122  
123   #ifdef FREEBSD

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines