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.5 by pajs, Wed Mar 5 21:00:59 2003 UTC vs.
Revision 1.6 by pajs, Thu Apr 3 20:05:10 2003 UTC

# Line 32 | Line 32
32   #include <string.h>
33   #include "tools.h"
34   #endif
35 + #ifdef FREEBSD
36 + #include <sys/types.h>
37 + #include <sys/sysctl.h>
38 + #include <unistd.h>
39 + #endif
40  
41   mem_stat_t *get_memory_stats(){
42  
# Line 48 | Line 53 | mem_stat_t *get_memory_stats(){
53          char *line_ptr;
54          FILE *f;
55   #endif
56 + #ifdef FREEBSD
57 +        long inactive;
58 +        size_t size;
59 +        int pagesize;
60 + #endif
61  
62   #ifdef SOLARIS
63          if((pagesize=sysconf(_SC_PAGESIZE)) == -1){
# Line 101 | Line 111 | mem_stat_t *get_memory_stats(){
111                  &mem_stat.cache))!=4){
112                          return NULL;
113          }
114 +
115 + #endif
116 +
117 + #ifdef FREEBSD
118 +        /* Returns byes */
119 +        if (sysctlbyname("hw.physmem", NULL, &size, NULL, NULL) < 0){
120 +                return NULL;
121 +        }
122 +        if (sysctlbyname("hw.physmem", &mem_stat.total, &size, NULL, NULL) < 0){
123 +                return NULL;
124 +        }
125 +
126 +        /*returns pages*/
127 +        if (sysctlbyname("vm.stats.vm.v_free_count", NULL, &size, NULL, NULL) < 0){
128 +                return NULL;
129 +        }
130 +        if (sysctlbyname("vm.stats.vm.v_free_count", &mem_stat.free, &size, NULL, NULL) < 0){
131 +                return NULL;
132 +        }
133 +
134 +        if (sysctlbyname("vm.stats.vm.v_inactive_count", NULL, &size, NULL, NULL) < 0){
135 +                return NULL;
136 +        }
137 +        if (sysctlbyname("vm.stats.vm.v_inactive_count", &inactive , &size, NULL, NULL) < 0){
138 +                return NULL;
139 +        }
140 +
141 +        if (sysctlbyname("vm.stats.vm.v_cache_count", NULL, &size, NULL, NULL) < 0){
142 +                return NULL;
143 +        }
144 +        if (sysctlbyname("vm.stats.vm.v_cache_count", &mem_stat.cache, &size, NULL, NULL) < 0){
145 +                return NULL;
146 +        }
147 +
148 +        /* Because all the vm.stats returns pages, i need to get the page size.
149 +         * After that i then need to multiple the anything that used vm.stats to get
150 +         * the system statistics by pagesize
151 +         */
152 +        if ((pagesize=getpagesize()) == -1){
153 +                return NULL;
154 +        }
155 +
156 +        mem_stat.cache=mem_stat.cache*pagesize;
157 +        /* Of couse nothing is ever that simple :) And i have inactive pages to deal
158 +         * with too. So im goingto add them to free memory :)
159 +         */
160 +        mem_stat.free=(mem_stat.free*pagesize)+(inactive*pagesize);
161 +        
162 +        mem_stat.used=mem_stat.total-mem_stat.free;
163  
164   #endif
165  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines