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

Comparing projects/libstatgrab/src/libstatgrab/page_stats.c (file contents):
Revision 1.9 by ats, Sun Oct 19 02:03:02 2003 UTC vs.
Revision 1.10 by ats, Fri Oct 24 17:26:43 2003 UTC

# Line 32 | Line 32
32   #endif
33   #ifdef LINUX
34   #include <stdio.h>
35 + #include <string.h>
36   #endif
37   #ifdef FREEBSD
38   #include <sys/types.h>
# Line 79 | Line 80 | page_stat_t *get_page_stats(){
80          kstat_close(kc);
81   #endif
82   #ifdef LINUX
83 <        if((f=fopen("/proc/stat", "r"))==NULL){
84 <                return NULL;
85 <        }
86 <        if((line_ptr=f_read_line(f, "page"))==NULL){
83 >        if ((f = fopen("/proc/vmstat", "r")) != NULL) {
84 >                while ((line_ptr = f_read_line(f, "")) != NULL) {
85 >                        long long value;
86 >
87 >                        if (sscanf(line_ptr, "%*s %lld", &value) != 1) {
88 >                                continue;
89 >                        }
90 >
91 >                        if (strncmp(line_ptr, "pgpgin ", 7) == 0) {
92 >                                page_stats.pages_pagein = value;
93 >                        } else if (strncmp(line_ptr, "pgpgout ", 8) == 0) {
94 >                                page_stats.pages_pageout = value;
95 >                        }
96 >                }
97 >
98                  fclose(f);
99 +        } else if ((f = fopen("/proc/stat", "r")) != NULL) {
100 +                if ((line_ptr = f_read_line(f, "page")) == NULL) {
101 +                        fclose(f);
102 +                        return NULL;
103 +                }
104 +
105 +                if (sscanf(line_ptr, "page %lld %lld", &page_stats.pages_pagein, &page_stats.pages_pageout) != 2) {
106 +                        return NULL;
107 +                }
108 +
109 +                fclose(f);
110 +        } else {
111                  return NULL;
112          }
89        if((sscanf(line_ptr, "page %lld %lld", &page_stats.pages_pagein, &page_stats.pages_pageout))!=2){
90                return NULL;
91        }
92        fclose(f);
93
113   #endif
114   #ifdef FREEBSD
115          size = sizeof page_stats.pages_pagein;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines