summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessandro Puccetti <alessandro@kinvolk.io>2016-06-05 19:42:37 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-06-05 13:42:37 -0400
commit308253c5a2b146fc18e3789725c092ac55b10ce7 (patch)
treea502c97b93a226b425c1e273479df1de7152ba73
parent0a62f81045dd810c8f1223cccbac4d706ea2cb45 (diff)
cgtop: add option to show a single cgroup subtree (#3413)
When many services are running, it was difficult to see only the interesting ones. This patch allows to show only the subtree of interest.
-rw-r--r--man/systemd-cgtop.xml8
-rw-r--r--src/cgtop/cgtop.c18
2 files changed, 22 insertions, 4 deletions
diff --git a/man/systemd-cgtop.xml b/man/systemd-cgtop.xml
index c76f646984..be13631239 100644
--- a/man/systemd-cgtop.xml
+++ b/man/systemd-cgtop.xml
@@ -52,6 +52,7 @@
<cmdsynopsis>
<command>systemd-cgtop</command>
<arg choice="opt" rep="repeat">OPTIONS</arg>
+ <arg choice="opt">GROUP</arg>
</cmdsynopsis>
</refsynopsisdiv>
@@ -62,7 +63,9 @@
groups of the local Linux control group hierarchy, ordered by
their CPU, memory, or disk I/O load. The display is refreshed in
regular intervals (by default every 1s), similar in style to
- <citerefentry project='man-pages'><refentrytitle>top</refentrytitle><manvolnum>1</manvolnum></citerefentry>.</para>
+ <citerefentry project='man-pages'><refentrytitle>top</refentrytitle><manvolnum>1</manvolnum></citerefentry>.
+ If a control group path is specified, shows only the services of
+ the specified control group.</para>
<para>If <command>systemd-cgtop</command> is not connected to a
tty, no column headers are printed and the default is to only run
@@ -252,7 +255,8 @@
<listitem><para>Limit control groups shown to the part
corresponding to the container
- <replaceable>MACHINE</replaceable>.</para></listitem>
+ <replaceable>MACHINE</replaceable>.
+ This option may not be used when a control group path is specified.</para></listitem>
</varlistentry>
<xi:include href="standard-options.xml" xpointer="help" />
diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c
index 33379eb9bd..b4a982ce38 100644
--- a/src/cgtop/cgtop.c
+++ b/src/cgtop/cgtop.c
@@ -72,6 +72,7 @@ static bool arg_batch = false;
static bool arg_raw = false;
static usec_t arg_delay = 1*USEC_PER_SEC;
static char* arg_machine = NULL;
+static char* arg_root = NULL;
static bool arg_recursive = true;
static enum {
@@ -653,7 +654,7 @@ static void display(Hashmap *a) {
}
static void help(void) {
- printf("%s [OPTIONS...]\n\n"
+ printf("%s [OPTIONS...] [CGROUP]\n\n"
"Show top control groups by their resource usage.\n\n"
" -h --help Show this help\n"
" --version Show package version\n"
@@ -835,7 +836,13 @@ static int parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option");
}
- if (optind < argc) {
+ if (optind == argc-1) {
+ if (arg_machine) {
+ log_error("Specifying a control group path together with the -M option is not allowed");
+ return -EINVAL;
+ }
+ arg_root = argv[optind];
+ } else if (optind < argc) {
log_error("Too many arguments.");
return -EINVAL;
}
@@ -864,6 +871,13 @@ static int get_cgroup_root(char **ret) {
const char *m;
int r;
+ if (arg_root) {
+ *ret = strdup(arg_root);
+ if (!*ret)
+ return log_oom();
+ return 0;
+ }
+
if (!arg_machine) {
r = cg_get_root_path(ret);
if (r < 0)