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.3 by pajs, Wed Feb 19 00:25:36 2003 UTC vs.
Revision 1.10 by ats, Fri Oct 24 17:26:43 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>
25   #include "statgrab.h"
26 + #include "tools.h"
27 + #include <time.h>
28   #ifdef SOLARIS
29   #include <kstat.h>
30   #include <sys/sysinfo.h>
31   #include <string.h>
32   #endif
33 + #ifdef LINUX
34 + #include <stdio.h>
35 + #include <string.h>
36 + #endif
37 + #ifdef FREEBSD
38 + #include <sys/types.h>
39 + #include <sys/sysctl.h>
40 + #endif
41  
33
42   static page_stat_t page_stats;
43   static int page_stats_uninit=1;
44  
45   page_stat_t *get_page_stats(){
46 + #ifdef SOLARIS
47          kstat_ctl_t *kc;
48          kstat_t *ksp;
49          cpu_stat_t cs;
50 + #endif
51 + #ifdef LINUX
52 +        FILE *f;
53 +        char *line_ptr;
54 + #endif
55 + #ifdef FREEBSD
56 +        size_t size;
57 + #endif
58 + #ifdef NETBSD
59 +        struct uvmexp *uvm;
60 + #endif
61  
62 <        page_stats.num_pagein=0;
43 <        page_stats.num_pageout=0;
62 >        page_stats.systime = time(NULL);
63          page_stats.pages_pagein=0;
64          page_stats.pages_pageout=0;
65  
66 + #ifdef SOLARIS
67          if ((kc = kstat_open()) == NULL) {
68                  return NULL;
69          }
# Line 53 | Line 73 | page_stat_t *get_page_stats(){
73                          continue;
74                  }
75  
56                page_stats.num_pagein+=(long long)cs.cpu_vminfo.pgin;
57                page_stats.num_pageout+=(long long)cs.cpu_vminfo.pgout;
76                  page_stats.pages_pagein+=(long long)cs.cpu_vminfo.pgpgin;
77                  page_stats.pages_pageout+=(long long)cs.cpu_vminfo.pgpgout;
78          }
79  
62        page_stats.systime=time(NULL);
63
80          kstat_close(kc);
81 + #endif
82 + #ifdef LINUX
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 +        }
113 + #endif
114 + #ifdef FREEBSD
115 +        size = sizeof page_stats.pages_pagein;
116 +        if (sysctlbyname("vm.stats.vm.v_swappgsin", &page_stats.pages_pagein, &size, NULL, 0) < 0){
117 +                return NULL;
118 +        }
119 +        size = sizeof page_stats.pages_pageout;
120 +        if (sysctlbyname("vm.stats.vm.v_swappgsout", &page_stats.pages_pageout, &size, NULL, 0) < 0){
121 +                return NULL;
122 +        }
123 + #endif
124 + #ifdef NETBSD
125 +        if ((uvm = get_uvmexp()) == NULL) {
126 +                return NULL;
127 +        }
128 +        page_stats.pages_pagein = uvm->pgswapin;
129 +        page_stats.pages_pageout = uvm->pgswapout;
130 + #endif
131 +
132          return &page_stats;
133   }
134  
# Line 79 | Line 145 | page_stat_t *get_page_stats_diff(){
145                  return page_ptr;
146          }
147  
82        page_stats_diff.num_pagein=page_stats.num_pagein;
83        page_stats_diff.num_pageout=page_stats.num_pageout;
148          page_stats_diff.pages_pagein=page_stats.pages_pagein;
149          page_stats_diff.pages_pageout=page_stats.pages_pageout;
150          page_stats_diff.systime=page_stats.systime;
# Line 90 | Line 154 | page_stat_t *get_page_stats_diff(){
154                  return NULL;
155          }
156  
93        page_stats_diff.num_pagein=page_stats.num_pagein-page_stats_diff.num_pagein;
94        page_stats_diff.num_pageout=page_stats.num_pageout-page_stats_diff.num_pageout;
157          page_stats_diff.pages_pagein=page_stats.pages_pagein-page_stats_diff.pages_pagein;
158          page_stats_diff.pages_pageout=page_stats.pages_pageout-page_stats_diff.pages_pageout;
159          page_stats_diff.systime=page_stats.systime-page_stats_diff.systime;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines