2013-08-15 11:02:53 -04:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
|
|
|
#include <sys/sysinfo.h>
|
2014-06-30 14:03:41 -04:00
|
|
|
|
2013-08-15 11:02:53 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2014-06-30 14:03:41 -04:00
|
|
|
|
2013-08-15 11:02:53 -04:00
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
|
|
|
eprintf("usage: %s [-bkmg]\n", argv0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int mem_unit = 1;
|
|
|
|
static unsigned int unit_shift;
|
|
|
|
|
|
|
|
static unsigned long long
|
|
|
|
scale(unsigned long long v)
|
|
|
|
{
|
|
|
|
return (v * mem_unit) >> unit_shift;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
struct sysinfo info;
|
|
|
|
|
2013-08-16 10:51:37 -04:00
|
|
|
if (sysinfo(&info) < 0)
|
|
|
|
eprintf("sysinfo:");
|
2013-08-15 11:02:53 -04:00
|
|
|
mem_unit = info.mem_unit ? info.mem_unit : 1;
|
|
|
|
|
|
|
|
ARGBEGIN {
|
|
|
|
case 'b':
|
|
|
|
unit_shift = 0;
|
|
|
|
break;
|
|
|
|
case 'k':
|
|
|
|
unit_shift = 10;
|
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
unit_shift = 20;
|
|
|
|
break;
|
|
|
|
case 'g':
|
|
|
|
unit_shift = 30;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
} ARGEND;
|
|
|
|
|
|
|
|
printf(" %13s%13s%13s%13s%13s\n",
|
|
|
|
"total",
|
|
|
|
"used",
|
|
|
|
"free",
|
|
|
|
"shared", "buffers");
|
|
|
|
printf("Mem: ");
|
|
|
|
printf("%13llu%13llu%13llu%13llu%13llu\n",
|
|
|
|
scale(info.totalram),
|
|
|
|
scale(info.totalram - info.freeram),
|
|
|
|
scale(info.freeram),
|
|
|
|
scale(info.sharedram),
|
|
|
|
scale(info.bufferram));
|
|
|
|
printf("-/+ buffers/cache:");
|
|
|
|
printf("%13llu%13llu\n",
|
|
|
|
scale(info.totalram - info.freeram - info.bufferram),
|
|
|
|
scale(info.freeram + info.bufferram));
|
|
|
|
printf("Swap:");
|
|
|
|
printf("%13llu%13llu%13llu\n",
|
|
|
|
scale(info.totalswap),
|
|
|
|
scale(info.totalswap - info.freeswap),
|
|
|
|
scale(info.freeswap));
|
2013-10-07 14:11:40 -04:00
|
|
|
return EXIT_SUCCESS;
|
2013-08-15 11:02:53 -04:00
|
|
|
}
|