Mercurial > archived > louis > perso > liblxcstats
annotate probes/memory.c @ 10:3a1977ecccc7
Add a configure script and fix various things
author | Louis Opter <kalessin@kalessin.fr> |
---|---|
date | Thu, 06 Jan 2011 00:59:06 +0100 |
parents | 6f2e13f5fcfd |
children |
rev | line source |
---|---|
9 | 1 #include <sys/types.h> |
2 | |
3 #include <assert.h> | |
4 #include <errno.h> | |
5 #include <limits.h> | |
6 #include <stdlib.h> | |
7 #include <string.h> | |
8 | |
9 #include "lxcstats.h" | |
10 #include "_lxcstats.h" | |
11 | |
12 static int | |
13 read_stat(struct lxcst *c) | |
14 { | |
15 char path[PATH_MAX]; | |
16 char *values; | |
17 char *fields[12]; | |
18 int ret; | |
19 | |
20 _lxcst_join_path(path, sizeof(path), c->cgroup_dir, "memory.stat"); | |
21 ret = _lxcst_read_file(path, &values); | |
22 if (ret > 0) { | |
23 values[ret - 1] = '\0'; /* Replace the last \n by a \0 */ | |
24 if (_lxcst_strsplit(values, fields, ARRAY_SIZE(fields)) == ARRAY_SIZE(fields)) { | |
25 errno = 0; | |
26 c->memory.cached = strtoull(fields[1], NULL, 10); | |
27 c->memory.used = strtoull(fields[3], NULL, 10); | |
28 c->memory.mapped = strtoull(fields[5], NULL, 10); | |
29 c->memory.swapped = strtoull(fields[11], NULL, 10); | |
30 if (!errno) { | |
31 free(values); | |
32 return (0); | |
33 } | |
34 } | |
35 free(values); | |
36 } | |
37 | |
38 memset(&c->memory, 0, sizeof(c->memory)); | |
39 return (-1); | |
40 } | |
41 | |
42 int | |
43 _lxcst_probe_memory(struct lxcst *c) | |
44 { | |
45 assert(c); | |
46 | |
10
3a1977ecccc7
Add a configure script and fix various things
Louis Opter <kalessin@kalessin.fr>
parents:
9
diff
changeset
|
47 if (read_stat(c)) |
3a1977ecccc7
Add a configure script and fix various things
Louis Opter <kalessin@kalessin.fr>
parents:
9
diff
changeset
|
48 return (-1); |
3a1977ecccc7
Add a configure script and fix various things
Louis Opter <kalessin@kalessin.fr>
parents:
9
diff
changeset
|
49 return (0); |
9 | 50 } |