From: David Strauss Date: Wed, 25 Jul 2012 23:33:07 +0000 (-0700) Subject: Add a 'b' option to cgtop, equivalent to the same option in top X-Git-Tag: v188~66 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=commitdiff_plain;h=e66bb58bed3fe5ef152268ac257b2801a7679549 Add a 'b' option to cgtop, equivalent to the same option in top [zj: use static] --- diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c index c439d09fd..300958959 100644 --- a/src/cgtop/cgtop.c +++ b/src/cgtop/cgtop.c @@ -56,6 +56,7 @@ typedef struct Group { static unsigned arg_depth = 3; static unsigned arg_iterations = 0; +static bool arg_batch = false; static usec_t arg_delay = 1*USEC_PER_SEC; static enum { @@ -507,6 +508,7 @@ static void help(void) { " -i Order by IO load\n" " -d --delay=DELAY Specify delay\n" " -n --iterations=N Run for N iterations before exiting\n" + " -b --batch Run in batch mode, accepting no input\n" " --depth=DEPTH Maximum traversal depth (default: 2)\n", program_invocation_short_name); } @@ -521,6 +523,7 @@ static int parse_argv(int argc, char *argv[]) { { "help", no_argument, NULL, 'h' }, { "delay", required_argument, NULL, 'd' }, { "iterations", required_argument, NULL, 'n' }, + { "batch", no_argument, NULL, 'b' }, { "depth", required_argument, NULL, ARG_DEPTH }, { NULL, 0, NULL, 0 } }; @@ -531,7 +534,7 @@ static int parse_argv(int argc, char *argv[]) { assert(argc >= 1); assert(argv); - while ((c = getopt_long(argc, argv, "hptcmin:d:", options, NULL)) >= 0) { + while ((c = getopt_long(argc, argv, "hptcmin:bd:", options, NULL)) >= 0) { switch (c) { @@ -566,6 +569,10 @@ static int parse_argv(int argc, char *argv[]) { break; + case 'b': + arg_batch = true; + break; + case 'p': arg_order = ORDER_PATH; break; @@ -655,17 +662,25 @@ int main(int argc, char *argv[]) { if (arg_iterations && iteration >= arg_iterations) break; - r = read_one_char(stdin, &key, last_refresh + arg_delay - t, NULL); - if (r == -ETIMEDOUT) - continue; - if (r < 0) { - log_error("Couldn't read key: %s", strerror(-r)); - goto finish; + if (arg_batch) { + usleep(last_refresh + arg_delay - t); + } else { + r = read_one_char(stdin, &key, + last_refresh + arg_delay - t, NULL); + if (r == -ETIMEDOUT) + continue; + if (r < 0) { + log_error("Couldn't read key: %s", strerror(-r)); + goto finish; + } } fputs("\r \r", stdout); fflush(stdout); + if (arg_batch) + continue; + switch (key) { case ' ':