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

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

28
29
30
31
32
33
34



35
36
37
38
39
40
41
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44







+
+
+







#undef HAVE_STDLIB_H

/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H

/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H

/* Define if your sysinfo structure has a mem_info unit */
#undef HAVE_SYSINFO_MEM_UNIT

/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H

/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H

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

1418
1419
1420
1421
1422
1423
1424

























































1425
1426
1427
1428
1429
1430
1431
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+








	ac_retval=1
fi
  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
  as_fn_set_status $ac_retval

} # ac_fn_c_try_compile

# ac_fn_c_check_member LINENO AGGR MEMBER VAR INCLUDES
# ----------------------------------------------------
# Tries to find if the field MEMBER exists in type AGGR, after including
# INCLUDES, setting cache variable VAR accordingly.
ac_fn_c_check_member ()
{
  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2.$3" >&5
$as_echo_n "checking for $2.$3... " >&6; }
if eval \${$4+:} false; then :
  $as_echo_n "(cached) " >&6
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
$5
int
main ()
{
static $2 ac_aggr;
if (ac_aggr.$3)
return 0;
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
  eval "$4=yes"
else
  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h.  */
$5
int
main ()
{
static $2 ac_aggr;
if (sizeof ac_aggr.$3)
return 0;
  ;
  return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
  eval "$4=yes"
else
  eval "$4=no"
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
eval ac_res=\$$4
	       { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5
$as_echo "$ac_res" >&6; }
  eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno

} # ac_fn_c_check_member

# ac_fn_c_try_link LINENO
# -----------------------
# Try to link conftest.$ac_ext, and return whether this succeeded.
ac_fn_c_try_link ()
{
  as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
2959
2960
2961
2962
2963
2964
2965











2966
2967
2968
2969
2970
2971
2972
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040







+
+
+
+
+
+
+
+
+
+
+







test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}'

test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}'

test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'



ac_fn_c_check_member "$LINENO" "struct sysinfo" "mem_unit" "ac_cv_member_struct_sysinfo_mem_unit" "#include <sys/sysinfo.h>
"
if test "x$ac_cv_member_struct_sysinfo_mem_unit" = xyes; then :


$as_echo "#define HAVE_SYSINFO_MEM_UNIT 1" >>confdefs.h


fi


ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking how to run the C preprocessor" >&5

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

1
2
3
4
5
6
7
8




9
10
11
12
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16








+
+
+
+




AC_REVISION($Revision $)
AC_INIT
AC_CONFIG_HEADER(config.h)

dnl Checks for programs.
AC_PROG_CC
AC_PROG_MAKE_SET
AC_PROG_INSTALL

AC_CHECK_MEMBER([struct sysinfo.mem_unit], [
	AC_DEFINE([HAVE_SYSINFO_MEM_UNIT], [1], [Define if your sysinfo structure has a mem_info unit])
],, [[#include <sys/sysinfo.h>]])

DC_ASK_STATGRAB

AC_OUTPUT(Makefile)

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

27
28
29
30
31
32
33


34
35
36
37
38
39
40
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42







+
+








#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#if defined(HAVE_LIBSTATGRAB) && !defined(HAVE_LIBSTATGRAB_H)
#undef HAVE_LIBSTATGRAB
#endif
#include <assert.h>
#include <stdint.h>

#ifndef HAVE_LIBSTATGRAB
#include <linux/kernel.h>
#include <sys/sysinfo.h>
#ifndef PROC_MEMINFO
#define PROC_MEMINFO "/proc/meminfo"
#endif
52
53
54
55
56
57
58
59
60
61
62
63
64
65







66
67
68

69
70
71
72

73


74
75

76
77
78
79


80



81
82
83
84
85
86
87
54
55
56
57
58
59
60







61
62
63
64
65
66
67
68
69

70
71
72
73

74
75
76
77
78

79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96







-
-
-
-
-
-
-
+
+
+
+
+
+
+


-
+



-
+

+
+

-
+




+
+

+
+
+







#define HEADERLEN 14
#define VERSION "0.9.2"

extern char *optarg;
extern int optind, opterr, optopt;

struct freecolor_meminfo {
	unsigned long totalram;  /* Total usable main memory size */
	unsigned long freeram;   /* Available memory size */
	unsigned long sharedram; /* Amount of shared memory */
	unsigned long bufferram; /* Memory used by buffers */
	unsigned long cachedram; /* Memory used for I/O cache */
	unsigned long totalswap; /* Total swap space size */
	unsigned long freeswap;  /* swap space still available */
	uint64_t totalram;  /* Total usable main memory size */
	uint64_t freeram;   /* Available memory size */
	uint64_t sharedram; /* Amount of shared memory */
	uint64_t bufferram; /* Memory used by buffers */
	uint64_t cachedram; /* Memory used for I/O cache */
	uint64_t totalswap; /* Total swap space size */
	uint64_t freeswap;  /* swap space still available */
};

void bargraph(float percent, float secondper, char marks[BARLEN + HEADERLEN + 1], int usefull) {
void bargraph(double percent, double secondper, char marks[BARLEN + HEADERLEN + 1], int usefull) {
	char percentone[BARLEN + 1], percenttwo[BARLEN + 1], remain[BARLEN + 1];
	unsigned int numberofmarks, numofmarkstwo, remainnum;

	numberofmarks=(int) ((float) (BARLEN * (percent / 100)));
	numberofmarks=(int) ((double) (BARLEN * (percent / 100)));

	assert(numberofmarks <= BARLEN);

	if (!usefull) {
		numofmarkstwo = (int) ((float) (BARLEN * (secondper / 100)));
		numofmarkstwo = (int) ((double) (BARLEN * (secondper / 100)));
	} else {
		numofmarkstwo = (BARLEN - numberofmarks);
	}

	assert(numofmarkstwo <= BARLEN);

	remainnum = BARLEN - (numberofmarks + numofmarkstwo);

	assert(remainnum <= BARLEN);

	memset(percentone, '#', numberofmarks);
	memset(percenttwo, '%', numofmarkstwo);
	memset(remain, '.', remainnum);

	percentone[numberofmarks] = 0;
	percenttwo[numofmarkstwo] = 0;

119
120
121
122
123
124
125
126


127
128
129
130






131
132
133
134
135
136






137
138
139
140
141
142
143
128
129
130
131
132
133
134

135
136
137
138
139
140
141
142
143
144
145
146






147
148
149
150
151
152
153
154
155
156
157
158
159







-
+
+




+
+
+
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+







	fclose(fd);

	return(results);
}

int get_all_meminfo(struct freecolor_meminfo *retval) {
	struct sysinfo sinfo;
	unsigned long meminfo_cached;
	uint64_t meminfo_cached;
	uint64_t multiplier;

	meminfo_cached = get_meminfo("Cached:");
	sysinfo(&sinfo);

#ifdef HAVE_SYSINFO_MEM_UNIT
	multiplier = sinfo.mem_unit;
#else
	multiplier = 1;
#endif

	retval->totalram  = sinfo.totalram;
	retval->freeram   = sinfo.freeram;
	retval->sharedram = sinfo.sharedram;
	retval->bufferram = sinfo.bufferram;
	retval->totalswap = sinfo.totalswap;
	retval->freeswap  = sinfo.freeswap;
	retval->totalram  = sinfo.totalram * multiplier;
	retval->freeram   = sinfo.freeram * multiplier;
	retval->sharedram = sinfo.sharedram * multiplier;
	retval->bufferram = sinfo.bufferram * multiplier;
	retval->totalswap = sinfo.totalswap * multiplier;
	retval->freeswap  = sinfo.freeswap * multiplier;

	retval->cachedram = meminfo_cached;

	return(0);
}
#else
int get_all_meminfo(struct freecolor_meminfo *retval) {
183
184
185
186
187
188
189
190
191
192



193
194
195
196
197
198
199
199
200
201
202
203
204
205



206
207
208
209
210
211
212
213
214
215







-
-
-
+
+
+








	return(0);
}
#endif

int main(int argc, char **argv) {
	struct freecolor_meminfo sinfo;
	unsigned long cachedbuffer, divisor;
	float percentram, percentswap, percentbuffer, percentused, percentfree;
	float ramfree, ramtotal, swapfree, swaptotal, doloop, totaltotal;
	uint64_t cachedbuffer, divisor;
	double percentram, percentswap, percentbuffer, percentused, percentfree;
	double ramfree, ramtotal, swapfree, swaptotal, doloop, totaltotal;
	char realbarchart[BARLEN  +HEADERLEN + 1], swapbarchart[BARLEN + HEADERLEN + 1], totalbarchart[BARLEN + HEADERLEN + 1];
	int i, dototals, doold, linestoup;
	int gam_ret;

	/* Set defaults */
	divisor = 1024;
	doold = 0;
245
246
247
248
249
250
251
252
253
254



255
256
257
258

259
260
261
262
263
264
265
266
267
268
269
270
271
272


273
274
275
276
277
278
279


280
281
282
283
284
285

286
287
288
289
290
291
292
261
262
263
264
265
266
267



268
269
270
271
272
273

274
275
276
277
278
279
280
281
282
283
284
285
286


287
288
289
290
291
292
293


294
295
296
297
298
299
300

301
302
303
304
305
306
307
308







-
-
-
+
+
+



-
+












-
-
+
+





-
-
+
+





-
+







		ramfree   = sinfo.freeram;
		swapfree  = sinfo.freeswap;
		swaptotal = sinfo.totalswap;

		totaltotal   = sinfo.totalram + sinfo.totalswap;
		cachedbuffer = sinfo.bufferram + sinfo.cachedram;

		percentram    = (float) ((ramfree / ramtotal) * 100);
		percentbuffer = (float) ((cachedbuffer / ramtotal) * 100);
		percentfree   = (float) (((sinfo.freeram + sinfo.freeswap + cachedbuffer) / totaltotal) * 100);
		percentram    = (double) ((ramfree / ramtotal) * 100);
		percentbuffer = (double) ((cachedbuffer / ramtotal) * 100);
		percentfree   = (double) (((sinfo.freeram + sinfo.freeswap + cachedbuffer) / totaltotal) * 100);
		percentused   = (int) (100 - ((int) percentfree));

		if (swaptotal!=0) {
			percentswap = (float) (( swapfree / swaptotal) * 100);
			percentswap = (double) (( swapfree / swaptotal) * 100);
		} else {
			percentswap = 0;
		}

		bargraph(percentswap, 0, swapbarchart, 0);
		bargraph(percentram, percentbuffer, realbarchart, 0);
		bargraph((int) percentfree,(int) percentused, totalbarchart,1);

		if (!doold) {
			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",
			    realbarchart,
			    (int) (percentram + percentbuffer),
			    (unsigned long) (ramfree + cachedbuffer) / divisor,
			    (unsigned long) ramtotal/divisor
			    (unsigned long) ((ramfree + cachedbuffer) / divisor),
			    (unsigned long) (ramtotal / divisor)
			);

			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",
			    swapbarchart,
			     (int) percentswap,
			     (unsigned long) swapfree / divisor,
			     (unsigned long) swaptotal/divisor
			     (unsigned long) (swapfree / divisor),
			     (unsigned long) (swaptotal/divisor)
			);

			if (dototals) {
				printf("Total     : \033[1;30m[\033[1;32m%s\033[1;30m]\033[1;37m \033[0m(%lu=%lu+%lu)\n",
				    totalbarchart,
				    (unsigned long) (sinfo.totalram + sinfo.totalswap) / divisor,
				    (unsigned long) ((sinfo.totalram + sinfo.totalswap) / divisor),
				    (unsigned long) ((sinfo.freeram + sinfo.freeswap) / divisor),
				    (unsigned long) ((totaltotal - ((sinfo.freeram + sinfo.freeswap + cachedbuffer))) / divisor)
				);
			}
		} else {
			printf("             total       used       free     shared    buffers     cached\n");
			printf("Mem:  %12lu %10lu %10lu %10lu %10lu %10lu\n",
303
304
305
306
307
308
309
310
311


312
313
314
315
316
317
318
319
320
321
322
323
324
325


326
327
328
329
330
331
332
333
334







-
-
+
+







			    (unsigned long) ((sinfo.totalswap - sinfo.freeswap) / divisor),
			    (unsigned long) (sinfo.freeswap / divisor)
			);

			if (dototals) {
				printf("Total: %11lu = (%8lu (used) + %8lu (free))\n",
				    (unsigned long) (totaltotal / divisor),
				    (((long) totaltotal) - ((sinfo.freeram+sinfo.freeswap))) / divisor,
				    (sinfo.freeram+sinfo.freeswap+((unsigned long) cachedbuffer)) / divisor
				    (unsigned long) ((((long) totaltotal) - ((sinfo.freeram+sinfo.freeswap))) / divisor),
				    (unsigned long) ((sinfo.freeram+sinfo.freeswap+((unsigned long) cachedbuffer)) / divisor)
				);
			}
		}

		if (doloop==0) {
			break;
		}