summaryrefslogtreecommitdiff
path: root/src/cgtop/cgtop.c
diff options
context:
space:
mode:
authorDavid Strauss <david@davidstrauss.net>2012-07-25 16:33:07 -0700
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2012-07-26 20:25:51 +0200
commite66bb58bed3fe5ef152268ac257b2801a7679549 (patch)
treef7f1c19f2a8787bfa38a9b9c461a70b4d5343f6e /src/cgtop/cgtop.c
parenta152771af17da095fc58302de5ea330f394f89c9 (diff)
Add a 'b' option to cgtop, equivalent to the same option in top
[zj: use static]
Diffstat (limited to 'src/cgtop/cgtop.c')
-rw-r--r--src/cgtop/cgtop.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c
index c439d09fd6..3009589597 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 ' ':