mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-11 05:17:44 +03:00
Add an 'n' option to cgtop (equivalent to top)
This commit is contained in:
parent
c51742d029
commit
a152771af1
@ -55,6 +55,7 @@ typedef struct Group {
|
|||||||
} Group;
|
} Group;
|
||||||
|
|
||||||
static unsigned arg_depth = 3;
|
static unsigned arg_depth = 3;
|
||||||
|
static unsigned arg_iterations = 0;
|
||||||
static usec_t arg_delay = 1*USEC_PER_SEC;
|
static usec_t arg_delay = 1*USEC_PER_SEC;
|
||||||
|
|
||||||
static enum {
|
static enum {
|
||||||
@ -505,6 +506,7 @@ static void help(void) {
|
|||||||
" -m Order by memory load\n"
|
" -m Order by memory load\n"
|
||||||
" -i Order by IO load\n"
|
" -i Order by IO load\n"
|
||||||
" -d --delay=DELAY Specify delay\n"
|
" -d --delay=DELAY Specify delay\n"
|
||||||
|
" -n --iterations=N Run for N iterations before exiting\n"
|
||||||
" --depth=DEPTH Maximum traversal depth (default: 2)\n",
|
" --depth=DEPTH Maximum traversal depth (default: 2)\n",
|
||||||
program_invocation_short_name);
|
program_invocation_short_name);
|
||||||
}
|
}
|
||||||
@ -516,10 +518,11 @@ static int parse_argv(int argc, char *argv[]) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static const struct option options[] = {
|
static const struct option options[] = {
|
||||||
{ "help", no_argument, NULL, 'h' },
|
{ "help", no_argument, NULL, 'h' },
|
||||||
{ "delay", required_argument, NULL, 'd' },
|
{ "delay", required_argument, NULL, 'd' },
|
||||||
{ "depth", required_argument, NULL, ARG_DEPTH },
|
{ "iterations", required_argument, NULL, 'n' },
|
||||||
{ NULL, 0, NULL, 0 }
|
{ "depth", required_argument, NULL, ARG_DEPTH },
|
||||||
|
{ NULL, 0, NULL, 0 }
|
||||||
};
|
};
|
||||||
|
|
||||||
int c;
|
int c;
|
||||||
@ -528,7 +531,7 @@ static int parse_argv(int argc, char *argv[]) {
|
|||||||
assert(argc >= 1);
|
assert(argc >= 1);
|
||||||
assert(argv);
|
assert(argv);
|
||||||
|
|
||||||
while ((c = getopt_long(argc, argv, "hptcmid:", options, NULL)) >= 0) {
|
while ((c = getopt_long(argc, argv, "hptcmin:d:", options, NULL)) >= 0) {
|
||||||
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
|
|
||||||
@ -554,6 +557,15 @@ static int parse_argv(int argc, char *argv[]) {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'n':
|
||||||
|
r = safe_atou(optarg, &arg_iterations);
|
||||||
|
if (r < 0) {
|
||||||
|
log_error("Failed to parse iterations parameter.");
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
case 'p':
|
case 'p':
|
||||||
arg_order = ORDER_PATH;
|
arg_order = ORDER_PATH;
|
||||||
break;
|
break;
|
||||||
@ -640,6 +652,9 @@ int main(int argc, char *argv[]) {
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
goto finish;
|
goto finish;
|
||||||
|
|
||||||
|
if (arg_iterations && iteration >= arg_iterations)
|
||||||
|
break;
|
||||||
|
|
||||||
r = read_one_char(stdin, &key, last_refresh + arg_delay - t, NULL);
|
r = read_one_char(stdin, &key, last_refresh + arg_delay - t, NULL);
|
||||||
if (r == -ETIMEDOUT)
|
if (r == -ETIMEDOUT)
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
Reference in New Issue
Block a user