ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/ihost/libstatgrab/memory_stats.c
(Generate patch)

Comparing projects/cms/source/ihost/libstatgrab/memory_stats.c (file contents):
Revision 1.2 by pajs, Thu May 16 10:34:23 2002 UTC vs.
Revision 1.10 by tdb, Wed May 29 19:41:59 2002 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
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
8 + * as published by the Free Software Foundation; either version 2
9 + * of the License, or (at your option) any later version.
10 + *
11 + * This program is distributed in the hope that it will be useful,
12 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 + * GNU General Public License for more details.
15 + *
16 + * You should have received a copy of the GNU General Public License
17 + * along with this program; if not, write to the Free Software
18 + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 + */
20 +
21 + #ifdef HAVE_CONFIG_H
22 + #include "config.h"
23 + #endif
24 +
25   #include <stdio.h>
26   #ifdef LINUX
27   #include <string.h>
# Line 11 | Line 35
35   #include <sys/sysctl.h>
36   #include <unistd.h>
37   #endif
38 < #include <ukcprog.h>
38 > #include "ukcprog.h"
39  
40   char *get_memory_stats(){
41 <        long total=0;
42 <        long free=0;
43 <        long used=0;
44 <        long cache=0;
41 >        long long total=0;
42 >        long long free=0;
43 >        long long used=0;
44 >        long long cache=0;
45          char *xml_memory_stats;
46   #ifdef LINUX
47          FILE *f;
48          char *line;
49 <        long buffers;
49 >        long long buffers;
50   #endif
51   #ifdef SOLARIS
52          kstat_ctl_t *kc;
# Line 48 | Line 72 | char *get_memory_stats(){
72          }
73          while((line=fpgetline(f)) != NULL){
74                  if (((strncmp(line,"Mem:",4)) == 0)) {
75 <                        if((sscanf(line, "%*s %ld %ld %ld %*s %ld %ld", &total, &used, &free, &buffers, &cache)) != 5){
75 >                        if((sscanf(line, "%*s %lld %lld %lld %*s %lld %lld", &total, &used, &free, &buffers, &cache)) != 5){
76                                  errf("Failed to read memory details (%m)");
77                                  return NULL;
78                          }
# Line 61 | Line 85 | char *get_memory_stats(){
85          }
86  
87          cache=cache+buffers;
88 <        used=total-(free+cache);
88 >        used=total-free;
89  
90          total=(total/1024)/1024;
91          used=(used/1024)/1024;
92          free=(free/1024)/1024;
93 <        cache=(free/1024)/1024;
93 >        cache=(cache/1024)/1024;
94   #endif
95   #ifdef SOLARIS
96          if((pagesize=sysconf(_SC_PAGESIZE)) == -1){
# Line 95 | Line 119 | char *get_memory_stats(){
119                  errf("Failed to get free memory (%m)");
120                  return NULL;
121          }
122 +        if((kstat_close(kc)) != 0){
123 +                errf("Failed to close kstat control structure (%m)");
124 +                return NULL;
125 +        }      
126          total=((totalmem*pagesize)/1024)/1024;
127          free=(((kn->value.ul)*pagesize)/1024)/1024;
128          used=total-free;
# Line 150 | Line 178 | char *get_memory_stats(){
178            
179   #endif
180  
181 <        
182 <        if((xml_memory_stats=strf("<memory><total>%ld</total><free>%ld</free><used>%ld</used><cache>%ld</cache></memory>", total, free, used, cache)) == NULL){
181 >        /* casting these from a long long to a long is a KLUDGE! please fix it :) */    
182 >        if((xml_memory_stats=strf("<memory><total>%ld</total><free>%ld</free><used>%ld</used><cache>%ld</cache></memory>", (long)total, (long)free, (long)used, (long)cache)) == NULL){
183                  errf("strf failed (%m)");
184                  return NULL;
185          }
186          return xml_memory_stats;
159 }
160
161 int main(){
162        printf("%s\n", get_memory_stats());
163        exit(0);
187   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines