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.11 by ats, Sat Oct 18 23:04:23 2003 UTC vs.
Revision 1.12 by ats, Sun Oct 19 02:03:02 2003 UTC

# Line 23 | Line 23
23   #endif
24  
25   #include "statgrab.h"
26 + #include "tools.h"
27   #ifdef SOLARIS
28   #include <unistd.h>
29   #include <kstat.h>
# Line 30 | Line 31
31   #ifdef LINUX
32   #include <stdio.h>
33   #include <string.h>
33 #include "tools.h"
34   #endif
35 + #ifdef ALLBSD
36   #ifdef FREEBSD
37   #include <sys/types.h>
38   #include <sys/sysctl.h>
39 + #else
40 + #include <sys/param.h>
41 + #include <sys/sysctl.h>
42 + #endif
43   #include <unistd.h>
44   #endif
45  
# Line 53 | Line 58 | mem_stat_t *get_memory_stats(){
58          char *line_ptr;
59          FILE *f;
60   #endif
61 + #ifdef ALLBSD
62 +        int mib[2];
63   #ifdef FREEBSD
64          u_int free_count;
65          u_int cache_count;
66          u_int inactive_count;
67 +        int pagesize;
68 + #endif
69 + #ifdef NETBSD
70 +        struct uvmexp *uvm;
71 + #endif
72          u_long physmem;
73          size_t size;
62        int pagesize;
74   #endif
75  
76   #ifdef SOLARIS
# Line 108 | Line 119 | mem_stat_t *get_memory_stats(){
119           * problem for sometime yet :)
120           */
121          if((sscanf(line_ptr,"Mem:  %lld %lld %lld %*d %*d %lld", \
122 +        size = sizeof physmem;
123                  &mem_stat.total, \
124                  &mem_stat.used, \
125                  &mem_stat.free, \
# Line 117 | Line 129 | mem_stat_t *get_memory_stats(){
129  
130   #endif
131  
132 < #ifdef FREEBSD
132 > #ifdef ALLBSD
133          /* Returns bytes */
134 +        mib[0] = CTL_HW;
135 +        mib[1] = HW_PHYSMEM;
136          size = sizeof physmem;
137 <        if (sysctlbyname("hw.physmem", &physmem, &size, NULL, 0) < 0){
137 >        if (sysctl(mib, 2, &physmem, &size, NULL, 0) < 0) {
138                  return NULL;
139 <        }
139 >        }
140 >        mem_stat.total = physmem;
141  
142          /*returns pages*/
143 + #ifdef FREEBSD
144          size = sizeof free_count;
145          if (sysctlbyname("vm.stats.vm.v_free_count", &free_count, &size, NULL, 0) < 0){
146                  return NULL;
# Line 148 | Line 164 | mem_stat_t *get_memory_stats(){
164                  return NULL;
165          }
166  
151        mem_stat.total=physmem;
167          mem_stat.cache=cache_count*pagesize;
168  
169          /* Of couse nothing is ever that simple :) And I have inactive pages to
# Line 156 | Line 171 | mem_stat_t *get_memory_stats(){
171           */
172          mem_stat.free=(free_count*pagesize)+(inactive_count*pagesize);
173          mem_stat.used=physmem-mem_stat.free;
174 + #endif
175 + #ifdef NETBSD
176 +        /* FIXME This is not consistent with the FreeBSD logic above. */
177 +        if ((uvm = get_uvmexp()) == NULL) {
178 +                return NULL;
179 +        }
180 +        mem_stat.cache = uvm->pagesize * (uvm->filepages + uvm->execpages);
181 +        mem_stat.free = uvm->pagesize * uvm->free;
182 +        mem_stat.used = uvm->pagesize * (uvm->npages - uvm->free);
183 + #endif
184   #endif
185  
186          return &mem_stat;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines