Check-in [648d0caff0]
Overview
SHA1:648d0caff03015796423dbef2275e72c5f7b76b4
Date: 2016-01-26 01:08:27
User: rkeene
Comment:Updated to use fixed-width types and use the "mem_units" member if it is available
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | folders | manifest
Tags And Properties
Context
2016-01-26
01:14
[2b82884fdb] Leaf: Freecolor 0.9.3 (user: rkeene, tags: trunk, 0.9.3)
01:08
[648d0caff0] Updated to use fixed-width types and use the "mem_units" member if it is available (user: rkeene, tags: trunk)
2014-01-21
10:11
[a92cdd8448] Freecolor 0.9.2 (user: rkeene, tags: trunk, 0.9.2)
Changes

Modified config.h.in from [c1a33a19d5] to [9f77e0467a].

    28     28   #undef HAVE_STDLIB_H
    29     29   
    30     30   /* Define to 1 if you have the <strings.h> header file. */
    31     31   #undef HAVE_STRINGS_H
    32     32   
    33     33   /* Define to 1 if you have the <string.h> header file. */
    34     34   #undef HAVE_STRING_H
           35  +
           36  +/* Define if your sysinfo structure has a mem_info unit */
           37  +#undef HAVE_SYSINFO_MEM_UNIT
    35     38   
    36     39   /* Define to 1 if you have the <sys/stat.h> header file. */
    37     40   #undef HAVE_SYS_STAT_H
    38     41   
    39     42   /* Define to 1 if you have the <sys/types.h> header file. */
    40     43   #undef HAVE_SYS_TYPES_H
    41     44   

Modified configure from [4328da1660] to [289a97c934].

  1418   1418   
  1419   1419   	ac_retval=1
  1420   1420   fi
  1421   1421     eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
  1422   1422     as_fn_set_status $ac_retval
  1423   1423   
  1424   1424   } # ac_fn_c_try_compile
         1425  +
         1426  +# ac_fn_c_check_member LINENO AGGR MEMBER VAR INCLUDES
         1427  +# ----------------------------------------------------
         1428  +# Tries to find if the field MEMBER exists in type AGGR, after including
         1429  +# INCLUDES, setting cache variable VAR accordingly.
         1430  +ac_fn_c_check_member ()
         1431  +{
         1432  +  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
         1433  +  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2.$3" >&5
         1434  +$as_echo_n "checking for $2.$3... " >&6; }
         1435  +if eval \${$4+:} false; then :
         1436  +  $as_echo_n "(cached) " >&6
         1437  +else
         1438  +  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
         1439  +/* end confdefs.h.  */
         1440  +$5
         1441  +int
         1442  +main ()
         1443  +{
         1444  +static $2 ac_aggr;
         1445  +if (ac_aggr.$3)
         1446  +return 0;
         1447  +  ;
         1448  +  return 0;
         1449  +}
         1450  +_ACEOF
         1451  +if ac_fn_c_try_compile "$LINENO"; then :
         1452  +  eval "$4=yes"
         1453  +else
         1454  +  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
         1455  +/* end confdefs.h.  */
         1456  +$5
         1457  +int
         1458  +main ()
         1459  +{
         1460  +static $2 ac_aggr;
         1461  +if (sizeof ac_aggr.$3)
         1462  +return 0;
         1463  +  ;
         1464  +  return 0;
         1465  +}
         1466  +_ACEOF
         1467  +if ac_fn_c_try_compile "$LINENO"; then :
         1468  +  eval "$4=yes"
         1469  +else
         1470  +  eval "$4=no"
         1471  +fi
         1472  +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
         1473  +fi
         1474  +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
         1475  +fi
         1476  +eval ac_res=\$$4
         1477  +	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
         1478  +$as_echo "$ac_res" >&6; }
         1479  +  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
         1480  +
         1481  +} # ac_fn_c_check_member
  1425   1482   
  1426   1483   # ac_fn_c_try_link LINENO
  1427   1484   # -----------------------
  1428   1485   # Try to link conftest.$ac_ext, and return whether this succeeded.
  1429   1486   ac_fn_c_try_link ()
  1430   1487   {
  1431   1488     as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
................................................................................
  2959   3016   test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}'
  2960   3017   
  2961   3018   test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}'
  2962   3019   
  2963   3020   test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'
  2964   3021   
  2965   3022   
         3023  +
         3024  +ac_fn_c_check_member "$LINENO" "struct sysinfo" "mem_unit" "ac_cv_member_struct_sysinfo_mem_unit" "#include <sys/sysinfo.h>
         3025  +"
         3026  +if test "x$ac_cv_member_struct_sysinfo_mem_unit" = xyes; then :
         3027  +
         3028  +
         3029  +$as_echo "#define HAVE_SYSINFO_MEM_UNIT 1" >>confdefs.h
         3030  +
         3031  +
         3032  +fi
         3033  +
  2966   3034   
  2967   3035   ac_ext=c
  2968   3036   ac_cpp='$CPP $CPPFLAGS'
  2969   3037   ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
  2970   3038   ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
  2971   3039   ac_compiler_gnu=$ac_cv_c_compiler_gnu
  2972   3040   { $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5

Modified configure.in from [0d44529302] to [785706c4c3].

     2      2   AC_INIT
     3      3   AC_CONFIG_HEADER(config.h)
     4      4   
     5      5   dnl Checks for programs.
     6      6   AC_PROG_CC
     7      7   AC_PROG_MAKE_SET
     8      8   AC_PROG_INSTALL
            9  +
           10  +AC_CHECK_MEMBER([struct sysinfo.mem_unit], [
           11  +	AC_DEFINE([HAVE_SYSINFO_MEM_UNIT], [1], [Define if your sysinfo structure has a mem_info unit])
           12  +],, [[#include <sys/sysinfo.h>]])
     9     13   
    10     14   DC_ASK_STATGRAB
    11     15   
    12     16   AC_OUTPUT(Makefile)

Modified freecolor.c from [bb0b5f3d15] to [5a5dbca4b4].

    27     27   
    28     28   #ifdef HAVE_CONFIG_H
    29     29   #include "config.h"
    30     30   #endif
    31     31   #if defined(HAVE_LIBSTATGRAB) && !defined(HAVE_LIBSTATGRAB_H)
    32     32   #undef HAVE_LIBSTATGRAB
    33     33   #endif
           34  +#include <assert.h>
           35  +#include <stdint.h>
    34     36   
    35     37   #ifndef HAVE_LIBSTATGRAB
    36     38   #include <linux/kernel.h>
    37     39   #include <sys/sysinfo.h>
    38     40   #ifndef PROC_MEMINFO
    39     41   #define PROC_MEMINFO "/proc/meminfo"
    40     42   #endif
................................................................................
    52     54   #define HEADERLEN 14
    53     55   #define VERSION "0.9.2"
    54     56   
    55     57   extern char *optarg;
    56     58   extern int optind, opterr, optopt;
    57     59   
    58     60   struct freecolor_meminfo {
    59         -	unsigned long totalram;  /* Total usable main memory size */
    60         -	unsigned long freeram;   /* Available memory size */
    61         -	unsigned long sharedram; /* Amount of shared memory */
    62         -	unsigned long bufferram; /* Memory used by buffers */
    63         -	unsigned long cachedram; /* Memory used for I/O cache */
    64         -	unsigned long totalswap; /* Total swap space size */
    65         -	unsigned long freeswap;  /* swap space still available */
           61  +	uint64_t totalram;  /* Total usable main memory size */
           62  +	uint64_t freeram;   /* Available memory size */
           63  +	uint64_t sharedram; /* Amount of shared memory */
           64  +	uint64_t bufferram; /* Memory used by buffers */
           65  +	uint64_t cachedram; /* Memory used for I/O cache */
           66  +	uint64_t totalswap; /* Total swap space size */
           67  +	uint64_t freeswap;  /* swap space still available */
    66     68   };
    67     69   
    68         -void bargraph(float percent, float secondper, char marks[BARLEN + HEADERLEN + 1], int usefull) {
           70  +void bargraph(double percent, double secondper, char marks[BARLEN + HEADERLEN + 1], int usefull) {
    69     71   	char percentone[BARLEN + 1], percenttwo[BARLEN + 1], remain[BARLEN + 1];
    70     72   	unsigned int numberofmarks, numofmarkstwo, remainnum;
    71     73   
    72         -	numberofmarks=(int) ((float) (BARLEN * (percent / 100)));
           74  +	numberofmarks=(int) ((double) (BARLEN * (percent / 100)));
           75  +
           76  +	assert(numberofmarks <= BARLEN);
    73     77   
    74     78   	if (!usefull) {
    75         -		numofmarkstwo = (int) ((float) (BARLEN * (secondper / 100)));
           79  +		numofmarkstwo = (int) ((double) (BARLEN * (secondper / 100)));
    76     80   	} else {
    77     81   		numofmarkstwo = (BARLEN - numberofmarks);
    78     82   	}
           83  +
           84  +	assert(numofmarkstwo <= BARLEN);
    79     85   
    80     86   	remainnum = BARLEN - (numberofmarks + numofmarkstwo);
           87  +
           88  +	assert(remainnum <= BARLEN);
           89  +
    81     90   	memset(percentone, '#', numberofmarks);
    82     91   	memset(percenttwo, '%', numofmarkstwo);
    83     92   	memset(remain, '.', remainnum);
    84     93   
    85     94   	percentone[numberofmarks] = 0;
    86     95   	percenttwo[numofmarkstwo] = 0;
    87     96   
................................................................................
   119    128   	fclose(fd);
   120    129   
   121    130   	return(results);
   122    131   }
   123    132   
   124    133   int get_all_meminfo(struct freecolor_meminfo *retval) {
   125    134   	struct sysinfo sinfo;
   126         -	unsigned long meminfo_cached;
          135  +	uint64_t meminfo_cached;
          136  +	uint64_t multiplier;
   127    137   
   128    138   	meminfo_cached = get_meminfo("Cached:");
   129    139   	sysinfo(&sinfo);
   130    140   
   131         -	retval->totalram  = sinfo.totalram;
   132         -	retval->freeram   = sinfo.freeram;
   133         -	retval->sharedram = sinfo.sharedram;
   134         -	retval->bufferram = sinfo.bufferram;
   135         -	retval->totalswap = sinfo.totalswap;
   136         -	retval->freeswap  = sinfo.freeswap;
          141  +#ifdef HAVE_SYSINFO_MEM_UNIT
          142  +	multiplier = sinfo.mem_unit;
          143  +#else
          144  +	multiplier = 1;
          145  +#endif
          146  +
          147  +	retval->totalram  = sinfo.totalram * multiplier;
          148  +	retval->freeram   = sinfo.freeram * multiplier;
          149  +	retval->sharedram = sinfo.sharedram * multiplier;
          150  +	retval->bufferram = sinfo.bufferram * multiplier;
          151  +	retval->totalswap = sinfo.totalswap * multiplier;
          152  +	retval->freeswap  = sinfo.freeswap * multiplier;
   137    153   
   138    154   	retval->cachedram = meminfo_cached;
   139    155   
   140    156   	return(0);
   141    157   }
   142    158   #else
   143    159   int get_all_meminfo(struct freecolor_meminfo *retval) {
................................................................................
   183    199   
   184    200   	return(0);
   185    201   }
   186    202   #endif
   187    203   
   188    204   int main(int argc, char **argv) {
   189    205   	struct freecolor_meminfo sinfo;
   190         -	unsigned long cachedbuffer, divisor;
   191         -	float percentram, percentswap, percentbuffer, percentused, percentfree;
   192         -	float ramfree, ramtotal, swapfree, swaptotal, doloop, totaltotal;
          206  +	uint64_t cachedbuffer, divisor;
          207  +	double percentram, percentswap, percentbuffer, percentused, percentfree;
          208  +	double ramfree, ramtotal, swapfree, swaptotal, doloop, totaltotal;
   193    209   	char realbarchart[BARLEN  +HEADERLEN + 1], swapbarchart[BARLEN + HEADERLEN + 1], totalbarchart[BARLEN + HEADERLEN + 1];
   194    210   	int i, dototals, doold, linestoup;
   195    211   	int gam_ret;
   196    212   
   197    213   	/* Set defaults */
   198    214   	divisor = 1024;
   199    215   	doold = 0;
................................................................................
   245    261   		ramfree   = sinfo.freeram;
   246    262   		swapfree  = sinfo.freeswap;
   247    263   		swaptotal = sinfo.totalswap;
   248    264   
   249    265   		totaltotal   = sinfo.totalram + sinfo.totalswap;
   250    266   		cachedbuffer = sinfo.bufferram + sinfo.cachedram;
   251    267   
   252         -		percentram    = (float) ((ramfree / ramtotal) * 100);
   253         -		percentbuffer = (float) ((cachedbuffer / ramtotal) * 100);
   254         -		percentfree   = (float) (((sinfo.freeram + sinfo.freeswap + cachedbuffer) / totaltotal) * 100);
          268  +		percentram    = (double) ((ramfree / ramtotal) * 100);
          269  +		percentbuffer = (double) ((cachedbuffer / ramtotal) * 100);
          270  +		percentfree   = (double) (((sinfo.freeram + sinfo.freeswap + cachedbuffer) / totaltotal) * 100);
   255    271   		percentused   = (int) (100 - ((int) percentfree));
   256    272   
   257    273   		if (swaptotal!=0) {
   258         -			percentswap = (float) (( swapfree / swaptotal) * 100);
          274  +			percentswap = (double) (( swapfree / swaptotal) * 100);
   259    275   		} else {
   260    276   			percentswap = 0;
   261    277   		}
   262    278   
   263    279   		bargraph(percentswap, 0, swapbarchart, 0);
   264    280   		bargraph(percentram, percentbuffer, realbarchart, 0);
   265    281   		bargraph((int) percentfree,(int) percentused, totalbarchart,1);
   266    282   
   267    283   		if (!doold) {
   268    284   			printf("Physical  : \033[1;30m[\033[1;32m%s\033[1;30m]\033[1;37m %i\033[0;31m%%\033[0m\t(%lu/%lu)\n",
   269    285   			    realbarchart,
   270    286   			    (int) (percentram + percentbuffer),
   271         -			    (unsigned long) (ramfree + cachedbuffer) / divisor,
   272         -			    (unsigned long) ramtotal/divisor
          287  +			    (unsigned long) ((ramfree + cachedbuffer) / divisor),
          288  +			    (unsigned long) (ramtotal / divisor)
   273    289   			);
   274    290   
   275    291   			printf("Swap      : \033[1;30m[\033[1;32m%s\033[1;30m]\033[1;37m %i\033[0;31m%%\033[0m\t(%lu/%lu)\n",
   276    292   			    swapbarchart,
   277    293   			     (int) percentswap,
   278         -			     (unsigned long) swapfree / divisor,
   279         -			     (unsigned long) swaptotal/divisor
          294  +			     (unsigned long) (swapfree / divisor),
          295  +			     (unsigned long) (swaptotal/divisor)
   280    296   			);
   281    297   
   282    298   			if (dototals) {
   283    299   				printf("Total     : \033[1;30m[\033[1;32m%s\033[1;30m]\033[1;37m \033[0m(%lu=%lu+%lu)\n",
   284    300   				    totalbarchart,
   285         -				    (unsigned long) (sinfo.totalram + sinfo.totalswap) / divisor,
          301  +				    (unsigned long) ((sinfo.totalram + sinfo.totalswap) / divisor),
   286    302   				    (unsigned long) ((sinfo.freeram + sinfo.freeswap) / divisor),
   287    303   				    (unsigned long) ((totaltotal - ((sinfo.freeram + sinfo.freeswap + cachedbuffer))) / divisor)
   288    304   				);
   289    305   			}
   290    306   		} else {
   291    307   			printf("             total       used       free     shared    buffers     cached\n");
   292    308   			printf("Mem:  %12lu %10lu %10lu %10lu %10lu %10lu\n",
................................................................................
   303    319   			    (unsigned long) ((sinfo.totalswap - sinfo.freeswap) / divisor),
   304    320   			    (unsigned long) (sinfo.freeswap / divisor)
   305    321   			);
   306    322   
   307    323   			if (dototals) {
   308    324   				printf("Total: %11lu = (%8lu (used) + %8lu (free))\n",
   309    325   				    (unsigned long) (totaltotal / divisor),
   310         -				    (((long) totaltotal) - ((sinfo.freeram+sinfo.freeswap))) / divisor,
   311         -				    (sinfo.freeram+sinfo.freeswap+((unsigned long) cachedbuffer)) / divisor
          326  +				    (unsigned long) ((((long) totaltotal) - ((sinfo.freeram+sinfo.freeswap))) / divisor),
          327  +				    (unsigned long) ((sinfo.freeram+sinfo.freeswap+((unsigned long) cachedbuffer)) / divisor)
   312    328   				);
   313    329   			}
   314    330   		}
   315    331   
   316    332   		if (doloop==0) {
   317    333   			break;
   318    334   		}