diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-08-28 19:17:47 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-08-31 13:20:43 +0200 |
commit | 03af6492f071eb202a91eb154a7fc12edcac9087 (patch) | |
tree | 2d864ea8b5b53cbdc3ba95bb62de063ca71a68b8 /src/cgtop/cgtop.c | |
parent | 52f448c3fff64752649af4b8be5260c1a8a105ea (diff) |
cgtop: show resource usage relative to cgroup root only
This way the output is restricted to cgroups from a container when run
in one.
Diffstat (limited to 'src/cgtop/cgtop.c')
-rw-r--r-- | src/cgtop/cgtop.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c index 26b104f111..9e771d821b 100644 --- a/src/cgtop/cgtop.c +++ b/src/cgtop/cgtop.c @@ -348,21 +348,21 @@ static int refresh_one( return r; } -static int refresh(Hashmap *a, Hashmap *b, unsigned iteration) { +static int refresh(const char *root, Hashmap *a, Hashmap *b, unsigned iteration) { int r; assert(a); - r = refresh_one(SYSTEMD_CGROUP_CONTROLLER, "/", a, b, iteration, 0); + r = refresh_one(SYSTEMD_CGROUP_CONTROLLER, root, a, b, iteration, 0); if (r < 0) return r; - r = refresh_one("cpuacct", "/", a, b, iteration, 0); + r = refresh_one("cpuacct", root, a, b, iteration, 0); if (r < 0) return r; - r = refresh_one("memory", "/", a, b, iteration, 0); + r = refresh_one("memory", root, a, b, iteration, 0); if (r < 0) return r; - r = refresh_one("blkio", "/", a, b, iteration, 0); + r = refresh_one("blkio", root, a, b, iteration, 0); if (r < 0) return r; @@ -721,6 +721,7 @@ int main(int argc, char *argv[]) { unsigned iteration = 0; usec_t last_refresh = 0; bool quit = false, immediate_refresh = false; + _cleanup_free_ char *root = NULL; log_parse_environment(); log_open(); @@ -729,6 +730,12 @@ int main(int argc, char *argv[]) { if (r <= 0) goto finish; + r = cg_get_root_path(&root); + if (r < 0) { + log_error_errno(r, "Failed to get root control group path: %m"); + goto finish; + } + a = hashmap_new(&string_hash_ops); b = hashmap_new(&string_hash_ops); if (!a || !b) { @@ -751,7 +758,7 @@ int main(int argc, char *argv[]) { if (t >= last_refresh + arg_delay || immediate_refresh) { - r = refresh(a, b, iteration++); + r = refresh(root, a, b, iteration++); if (r < 0) goto finish; |