]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
cgtop: allow user to force looping behavior even in non-TTY mode
authorCharles Duffy <chaduffy@cisco.com>
Sat, 23 May 2015 03:18:15 +0000 (22:18 -0500)
committerCharles Duffy <chaduffy@cisco.com>
Wed, 10 Jun 2015 00:39:16 +0000 (19:39 -0500)
man/systemd-cgtop.xml
src/cgtop/cgtop.c

index b3298b64f338aa1cac084b797e60bdd5112c59eb..d14564480daa1bd06cc96934749635e6fa831771 100644 (file)
     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>.
-    If <command>systemd-cgtop</command> is not connected to a tty,
-    only one iteration is performed and no columns headers are
-    printed. This mode is suitable for scripting.</para>
+    <citerefentry project='man-pages'><refentrytitle>top</refentrytitle><manvolnum>1</manvolnum></citerefentry>.</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 one iteration.
+    The <varname>--iterations</varname> argument, if given, is still honored.
+    This mode is suitable for scripting.</para>
 
     <para>Resource usage is only accounted for control groups in the
     relevant hierarchy, i.e. CPU usage is only accounted for control
         <term><option>-n</option></term>
         <term><option>--iterations=</option></term>
 
-        <listitem><para>Perform only this many iterations.
-        </para></listitem>
+        <listitem><para>Perform only this many iterations. A value of 0
+        indicates that the program should run indefinitely.</para></listitem>
       </varlistentry>
 
       <varlistentry>
index 8c58cd2c04bfb48e83383adc271a613c5c49c327..d04d6f225ccac3be22b1363c74df99598b223061 100644 (file)
@@ -60,7 +60,7 @@ typedef struct Group {
 } Group;
 
 static unsigned arg_depth = 3;
-static unsigned arg_iterations = 0;
+static unsigned arg_iterations = (unsigned)-1;
 static bool arg_batch = false;
 static bool arg_raw = false;
 static usec_t arg_delay = 1*USEC_PER_SEC;
@@ -715,8 +715,8 @@ int main(int argc, char *argv[]) {
 
         signal(SIGWINCH, columns_lines_cache_reset);
 
-        if (!on_tty())
-                arg_iterations = 1;
+        if (arg_iterations == (unsigned)-1)
+                arg_iterations = on_tty() ? 0 : 1;
 
         while (!quit) {
                 Hashmap *c;