summaryrefslogtreecommitdiff
path: root/examples/free.c
blob: db0645eb5ee22a8caddf12fee2e5e2818a833104 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <glibtop.h>
#include <glibtop/mem.h>
#include <glibtop/swap.h>

#include <glib.h>
#include <unistd.h>

static unsigned mb(guint64 n)
{
        return n >> 20;
}

int main(int argc, char **argv)
{
        glibtop_mem mem;
        glibtop_swap swap;

	glibtop_init();

        glibtop_get_mem(&mem);
        glibtop_get_swap(&swap);

        printf("              total        used        free      shared  buff/cache   available\n");

        printf("%-7s %11u %11u %11u %11u %11u %11u\n",
               "Mem:",
                mb(mem.total),
                mb(mem.used - mem.buffer - mem.cached),
                mb(mem.free),
                mb(mem.shared),
                mb(mem.buffer + mem.cached),
                mb(mem.total - mem.user));

        printf("%-7s %11u %11u %11u\n",
               "Swap:",
                mb(swap.total),
                mb(swap.used),
                mb(swap.free));

	glibtop_close();

	return 0;
}