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.2 by pajs, Tue Feb 18 23:12:08 2003 UTC vs.
Revision 1.4 by pajs, Fri Mar 7 14:44:38 2003 UTC

# Line 22 | Line 22
22   #include "config.h"
23   #endif
24  
25 #include <stdio.h>
25   #include "statgrab.h"
26 + #include <time.h>
27   #ifdef SOLARIS
28   #include <kstat.h>
29   #include <sys/sysinfo.h>
30   #include <string.h>
31   #endif
32 + #ifdef LINUX
33 + #include <stdio.h>
34 + #include "tools.h"
35 + #endif
36  
37 +
38 + static page_stat_t page_stats;
39 + static int page_stats_uninit=1;
40 +
41   page_stat_t *get_page_stats(){
42 <        static page_stat_t page_stats;
42 > #ifdef SOLARIS
43          kstat_ctl_t *kc;
44          kstat_t *ksp;
45          cpu_stat_t cs;
46 + #endif
47 + #ifdef LINUX
48 +        FILE *f;
49 +        char *line_ptr;
50 + #endif
51  
39        page_stats.num_pagein=0;
40        page_stats.num_pageout=0;
52          page_stats.pages_pagein=0;
53          page_stats.pages_pageout=0;
54  
55 + #ifdef SOLARIS
56          if ((kc = kstat_open()) == NULL) {
57                  return NULL;
58          }
# Line 50 | Line 62 | page_stat_t *get_page_stats(){
62                          continue;
63                  }
64  
53                page_stats.num_pagein+=(long long)cs.cpu_vminfo.pgin;
54                page_stats.num_pageout+=(long long)cs.cpu_vminfo.pgout;
65                  page_stats.pages_pagein+=(long long)cs.cpu_vminfo.pgpgin;
66                  page_stats.pages_pageout+=(long long)cs.cpu_vminfo.pgpgout;
67          }
# Line 59 | Line 69 | page_stat_t *get_page_stats(){
69          page_stats.systime=time(NULL);
70  
71          kstat_close(kc);
72 + #endif
73 + #ifdef LINUX
74 +        if((f=fopen("/proc/stat", "r"))==NULL){
75 +                return NULL;
76 +        }
77 +        if((line_ptr=f_read_line(f, "page"))==NULL){
78 +                fclose(f);
79 +                return NULL;
80 +        }
81 +        if((sscanf(line_ptr, "page %lld %lld", &page_stats.pages_pagein, &page_stats.pages_pageout))!=2){
82 +                return NULL;
83 +        }
84 +        page_stats.systime=time(NULL);
85 +        fclose(f);
86  
87 + #endif
88 +
89          return &page_stats;
90 + }
91 +
92 + page_stat_t *get_page_stats_diff(){
93 +        page_stat_t *page_ptr;
94 +        static page_stat_t page_stats_diff;
95 +
96 +        if(page_stats_uninit){
97 +                page_ptr=get_page_stats();
98 +                if(page_ptr==NULL){
99 +                        return NULL;
100 +                }
101 +                page_stats_uninit=0;
102 +                return page_ptr;
103 +        }
104 +
105 +        page_stats_diff.pages_pagein=page_stats.pages_pagein;
106 +        page_stats_diff.pages_pageout=page_stats.pages_pageout;
107 +        page_stats_diff.systime=page_stats.systime;
108 +
109 +        page_ptr=get_page_stats();
110 +        if(page_ptr==NULL){
111 +                return NULL;
112 +        }
113 +
114 +        page_stats_diff.pages_pagein=page_stats.pages_pagein-page_stats_diff.pages_pagein;
115 +        page_stats_diff.pages_pageout=page_stats.pages_pageout-page_stats_diff.pages_pageout;
116 +        page_stats_diff.systime=page_stats.systime-page_stats_diff.systime;
117 +        
118 +        return &page_stats_diff;
119   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines