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.6 by pajs, Tue May 21 16:16:41 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
# Line 17 | Line 18
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 41 | Line 46 | char *get_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 67 | 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 80 | 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 173 | 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          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines