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.1 by pajs, Tue Feb 18 19:28:30 2003 UTC vs.
Revision 1.8 by ats, Sat Oct 18 23:04:23 2003 UTC

# Line 1 | Line 1
1   /*
2   * i-scream central monitoring system
3 < * http://www.i-scream.org.uk
4 < * Copyright (C) 2000-2002 i-scream
3 > * http://www.i-scream.org
4 > * Copyright (C) 2000-2003 i-scream
5   *
6   * This program is free software; you can redistribute it and/or
7   * modify it under the terms of the GNU General Public License
# Line 22 | Line 22
22   #include "config.h"
23   #endif
24  
25 < #include <stdio.h>
26 < #include <statgrab.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 + #ifdef FREEBSD
37 + #include <sys/types.h>
38 + #include <sys/sysctl.h>
39 + #endif
40  
41 + static page_stat_t page_stats;
42 + static int page_stats_uninit=1;
43 +
44   page_stat_t *get_page_stats(){
45 <        static page_stat_t page_stats;
45 > #ifdef SOLARIS
46          kstat_ctl_t *kc;
47          kstat_t *ksp;
48          cpu_stat_t cs;
49 <        uint_t swapin, swapout;
49 > #endif
50 > #ifdef LINUX
51 >        FILE *f;
52 >        char *line_ptr;
53 > #endif
54 > #ifdef FREEBSD
55 >        size_t size;
56 > #endif
57  
58 +        page_stats.pages_pagein=0;
59 +        page_stats.pages_pageout=0;
60 +
61 + #ifdef SOLARIS
62          if ((kc = kstat_open()) == NULL) {
40                errf("kstat_open failure (%m)");
63                  return NULL;
64          }
65          for (ksp = kc->kc_chain; ksp!=NULL; ksp = ksp->ks_next) {
# Line 46 | Line 68 | page_stat_t *get_page_stats(){
68                          continue;
69                  }
70  
71 <                page_stats+=cs.cpu_vminfo.pgswapin;
72 <                page_stats+=cs.cpu_vminfo.pgswapout;
71 >                page_stats.pages_pagein+=(long long)cs.cpu_vminfo.pgpgin;
72 >                page_stats.pages_pageout+=(long long)cs.cpu_vminfo.pgpgout;
73 >        }
74  
75 +        page_stats.systime=time(NULL);
76 +
77 +        kstat_close(kc);
78 + #endif
79 + #ifdef LINUX
80 +        if((f=fopen("/proc/stat", "r"))==NULL){
81 +                return NULL;
82 +        }
83 +        if((line_ptr=f_read_line(f, "page"))==NULL){
84 +                fclose(f);
85 +                return NULL;
86 +        }
87 +        if((sscanf(line_ptr, "page %lld %lld", &page_stats.pages_pagein, &page_stats.pages_pageout))!=2){
88 +                return NULL;
89 +        }
90 +        page_stats.systime=time(NULL);
91 +        fclose(f);
92 +
93 + #endif
94 + #ifdef FREEBSD
95 +        size = sizeof page_stats.pages_pagein;
96 +        if (sysctlbyname("vm.stats.vm.v_swappgsin", &page_stats.pages_pagein, &size, NULL, 0) < 0){
97 +                return NULL;
98 +        }
99 +        size = sizeof page_stats.pages_pageout;
100 +        if (sysctlbyname("vm.stats.vm.v_swappgsout", &page_stats.pages_pageout, &size, NULL, 0) < 0){
101 +                return NULL;
102 +        }
103 +
104 + #endif
105 +
106 +        return &page_stats;
107 + }
108 +
109 + page_stat_t *get_page_stats_diff(){
110 +        page_stat_t *page_ptr;
111 +        static page_stat_t page_stats_diff;
112 +
113 +        if(page_stats_uninit){
114 +                page_ptr=get_page_stats();
115 +                if(page_ptr==NULL){
116 +                        return NULL;
117 +                }
118 +                page_stats_uninit=0;
119 +                return page_ptr;
120 +        }
121 +
122 +        page_stats_diff.pages_pagein=page_stats.pages_pagein;
123 +        page_stats_diff.pages_pageout=page_stats.pages_pageout;
124 +        page_stats_diff.systime=page_stats.systime;
125 +
126 +        page_ptr=get_page_stats();
127 +        if(page_ptr==NULL){
128 +                return NULL;
129 +        }
130 +
131 +        page_stats_diff.pages_pagein=page_stats.pages_pagein-page_stats_diff.pages_pagein;
132 +        page_stats_diff.pages_pageout=page_stats.pages_pageout-page_stats_diff.pages_pageout;
133 +        page_stats_diff.systime=page_stats.systime-page_stats_diff.systime;
134 +        
135 +        return &page_stats_diff;
136   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines