1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright 2012 Lennart Poettering
17 #include "alloc-util.h"
18 #include "bus-error.h"
20 #include "cgroup-show.h"
21 #include "cgroup-util.h"
25 #include "parse-util.h"
26 #include "path-util.h"
27 #include "process-util.h"
28 #include "procfs-util.h"
29 #include "stdio-util.h"
31 #include "terminal-util.h"
32 #include "unit-name.h"
36 typedef struct Group
{
46 unsigned cpu_iteration
;
53 unsigned io_iteration
;
54 uint64_t io_input
, io_output
;
56 uint64_t io_input_bps
, io_output_bps
;
59 static unsigned arg_depth
= 3;
60 static unsigned arg_iterations
= (unsigned) -1;
61 static bool arg_batch
= false;
62 static bool arg_raw
= false;
63 static usec_t arg_delay
= 1*USEC_PER_SEC
;
64 static char* arg_machine
= NULL
;
65 static char* arg_root
= NULL
;
66 static bool arg_recursive
= true;
67 static bool arg_recursive_unset
= false;
71 COUNT_USERSPACE_PROCESSES
,
73 } arg_count
= COUNT_PIDS
;
81 } arg_order
= ORDER_CPU
;
86 } arg_cpu_type
= CPU_PERCENT
;
88 static void group_free(Group
*g
) {
95 static void group_hashmap_clear(Hashmap
*h
) {
96 hashmap_clear_with_destructor(h
, group_free
);
99 static void group_hashmap_free(Hashmap
*h
) {
100 group_hashmap_clear(h
);
104 static const char *maybe_format_bytes(char *buf
, size_t l
, bool is_valid
, uint64_t t
) {
108 snprintf(buf
, l
, "%" PRIu64
, t
);
111 return format_bytes(buf
, l
, t
);
114 static bool is_root_cgroup(const char *path
) {
116 /* Returns true if the specified path belongs to the root cgroup. The root cgroup is special on cgroupsv2 as it
117 * carries only very few attributes in order not to export multiple truth about system state as most
118 * information is available elsewhere in /proc anyway. We need to be able to deal with that, and need to get
119 * our data from different sources in that case.
121 * There's one extra complication in all of this, though 😣: if the path to the cgroup indicates we are in the
122 * root cgroup this might actually not be the case, because cgroup namespacing might be in effect
123 * (CLONE_NEWCGROUP). Since there's no nice way to distuingish a real cgroup root from a fake namespaced one we
124 * do an explicit container check here, under the assumption that CLONE_NEWCGROUP is generally used when
125 * container managers are used too.
127 * Note that checking for a container environment is kinda ugly, since in theory people could use cgtop from
128 * inside a container where cgroup namespacing is turned off to watch the host system. However, that's mostly a
129 * theoretic usecase, and if people actually try all they'll lose is accounting for the top-level cgroup. Which
132 if (detect_container() > 0)
135 return empty_or_root(path
);
139 const char *controller
,
153 all_unified
= cg_all_unified();
157 g
= hashmap_get(a
, path
);
159 g
= hashmap_get(b
, path
);
165 g
->path
= strdup(path
);
171 r
= hashmap_put(a
, g
->path
, g
);
177 r
= hashmap_move_one(a
, b
, path
);
181 g
->cpu_valid
= g
->memory_valid
= g
->io_valid
= g
->n_tasks_valid
= false;
185 if (streq(controller
, SYSTEMD_CGROUP_CONTROLLER
) &&
186 IN_SET(arg_count
, COUNT_ALL_PROCESSES
, COUNT_USERSPACE_PROCESSES
)) {
187 _cleanup_fclose_
FILE *f
= NULL
;
190 r
= cg_enumerate_processes(controller
, path
, &f
);
197 while (cg_read_pid(f
, &pid
) > 0) {
199 if (arg_count
== COUNT_USERSPACE_PROCESSES
&& is_kernel_thread(pid
) > 0)
206 g
->n_tasks_valid
= true;
208 } else if (streq(controller
, "pids") && arg_count
== COUNT_PIDS
) {
210 if (is_root_cgroup(path
)) {
211 r
= procfs_tasks_get_current(&g
->n_tasks
);
215 _cleanup_free_
char *p
= NULL
, *v
= NULL
;
217 r
= cg_get_path(controller
, path
, "pids.current", &p
);
221 r
= read_one_line_file(p
, &v
);
227 r
= safe_atou64(v
, &g
->n_tasks
);
233 g
->n_tasks_valid
= true;
235 } else if (STR_IN_SET(controller
, "cpu", "cpuacct")) {
236 _cleanup_free_
char *p
= NULL
, *v
= NULL
;
240 if (is_root_cgroup(path
)) {
241 r
= procfs_cpu_get_usage(&new_usage
);
244 } else if (all_unified
) {
245 _cleanup_free_
char *val
= NULL
;
247 if (!streq(controller
, "cpu"))
250 r
= cg_get_keyed_attribute("cpu", path
, "cpu.stat", STRV_MAKE("usage_usec"), &val
);
251 if (IN_SET(r
, -ENOENT
, -ENXIO
))
256 r
= safe_atou64(val
, &new_usage
);
260 new_usage
*= NSEC_PER_USEC
;
262 if (!streq(controller
, "cpuacct"))
265 r
= cg_get_path(controller
, path
, "cpuacct.usage", &p
);
269 r
= read_one_line_file(p
, &v
);
275 r
= safe_atou64(v
, &new_usage
);
280 timestamp
= now_nsec(CLOCK_MONOTONIC
);
282 if (g
->cpu_iteration
== iteration
- 1 &&
283 (nsec_t
) new_usage
> g
->cpu_usage
) {
287 x
= timestamp
- g
->cpu_timestamp
;
291 y
= (nsec_t
) new_usage
- g
->cpu_usage
;
292 g
->cpu_fraction
= (double) y
/ (double) x
;
296 g
->cpu_usage
= (nsec_t
) new_usage
;
297 g
->cpu_timestamp
= timestamp
;
298 g
->cpu_iteration
= iteration
;
300 } else if (streq(controller
, "memory")) {
302 if (is_root_cgroup(path
)) {
303 r
= procfs_memory_get_current(&g
->memory
);
307 _cleanup_free_
char *p
= NULL
, *v
= NULL
;
310 r
= cg_get_path(controller
, path
, "memory.current", &p
);
312 r
= cg_get_path(controller
, path
, "memory.usage_in_bytes", &p
);
316 r
= read_one_line_file(p
, &v
);
322 r
= safe_atou64(v
, &g
->memory
);
328 g
->memory_valid
= true;
330 } else if ((streq(controller
, "io") && all_unified
) ||
331 (streq(controller
, "blkio") && !all_unified
)) {
332 _cleanup_fclose_
FILE *f
= NULL
;
333 _cleanup_free_
char *p
= NULL
;
334 uint64_t wr
= 0, rd
= 0;
337 r
= cg_get_path(controller
, path
, all_unified
? "io.stat" : "blkio.io_service_bytes", &p
);
349 char line
[LINE_MAX
], *l
;
352 if (!fgets(line
, sizeof(line
), f
))
355 /* Trim and skip the device */
357 l
+= strcspn(l
, WHITESPACE
);
358 l
+= strspn(l
, WHITESPACE
);
361 while (!isempty(l
)) {
362 if (sscanf(l
, "rbytes=%" SCNu64
, &k
))
364 else if (sscanf(l
, "wbytes=%" SCNu64
, &k
))
367 l
+= strcspn(l
, WHITESPACE
);
368 l
+= strspn(l
, WHITESPACE
);
371 if (first_word(l
, "Read")) {
374 } else if (first_word(l
, "Write")) {
380 l
+= strspn(l
, WHITESPACE
);
381 r
= safe_atou64(l
, &k
);
389 timestamp
= now_nsec(CLOCK_MONOTONIC
);
391 if (g
->io_iteration
== iteration
- 1) {
394 x
= (uint64_t) (timestamp
- g
->io_timestamp
);
398 if (rd
> g
->io_input
)
399 yr
= rd
- g
->io_input
;
403 if (wr
> g
->io_output
)
404 yw
= wr
- g
->io_output
;
408 if (yr
> 0 || yw
> 0) {
409 g
->io_input_bps
= (yr
* 1000000000ULL) / x
;
410 g
->io_output_bps
= (yw
* 1000000000ULL) / x
;
417 g
->io_timestamp
= timestamp
;
418 g
->io_iteration
= iteration
;
427 static int refresh_one(
428 const char *controller
,
436 _cleanup_closedir_
DIR *d
= NULL
;
444 if (depth
> arg_depth
)
447 r
= process(controller
, path
, a
, b
, iteration
, &ours
);
451 r
= cg_enumerate_subgroups(controller
, path
, &d
);
458 _cleanup_free_
char *fn
= NULL
, *p
= NULL
;
461 r
= cg_read_subgroup(d
, &fn
);
467 p
= strjoin(path
, "/", fn
);
471 path_simplify(p
, false);
473 r
= refresh_one(controller
, p
, a
, b
, iteration
, depth
+ 1, &child
);
478 IN_SET(arg_count
, COUNT_ALL_PROCESSES
, COUNT_USERSPACE_PROCESSES
) &&
480 child
->n_tasks_valid
&&
481 streq(controller
, SYSTEMD_CGROUP_CONTROLLER
)) {
483 /* Recursively sum up processes */
485 if (ours
->n_tasks_valid
)
486 ours
->n_tasks
+= child
->n_tasks
;
488 ours
->n_tasks
= child
->n_tasks
;
489 ours
->n_tasks_valid
= true;
500 static int refresh(const char *root
, Hashmap
*a
, Hashmap
*b
, unsigned iteration
) {
505 r
= refresh_one(SYSTEMD_CGROUP_CONTROLLER
, root
, a
, b
, iteration
, 0, NULL
);
508 r
= refresh_one("cpu", root
, a
, b
, iteration
, 0, NULL
);
511 r
= refresh_one("cpuacct", root
, a
, b
, iteration
, 0, NULL
);
514 r
= refresh_one("memory", root
, a
, b
, iteration
, 0, NULL
);
517 r
= refresh_one("io", root
, a
, b
, iteration
, 0, NULL
);
520 r
= refresh_one("blkio", root
, a
, b
, iteration
, 0, NULL
);
523 r
= refresh_one("pids", root
, a
, b
, iteration
, 0, NULL
);
530 static int group_compare(const void*a
, const void *b
) {
531 const Group
*x
= *(Group
**)a
, *y
= *(Group
**)b
;
533 if (arg_order
!= ORDER_TASKS
|| arg_recursive
) {
534 /* Let's make sure that the parent is always before
535 * the child. Except when ordering by tasks and
536 * recursive summing is off, since that is actually
537 * not accumulative for all children. */
539 if (path_startswith(empty_to_root(y
->path
), empty_to_root(x
->path
)))
541 if (path_startswith(empty_to_root(x
->path
), empty_to_root(y
->path
)))
551 if (arg_cpu_type
== CPU_PERCENT
) {
552 if (x
->cpu_valid
&& y
->cpu_valid
) {
553 if (x
->cpu_fraction
> y
->cpu_fraction
)
555 else if (x
->cpu_fraction
< y
->cpu_fraction
)
557 } else if (x
->cpu_valid
)
559 else if (y
->cpu_valid
)
562 if (x
->cpu_usage
> y
->cpu_usage
)
564 else if (x
->cpu_usage
< y
->cpu_usage
)
571 if (x
->n_tasks_valid
&& y
->n_tasks_valid
) {
572 if (x
->n_tasks
> y
->n_tasks
)
574 else if (x
->n_tasks
< y
->n_tasks
)
576 } else if (x
->n_tasks_valid
)
578 else if (y
->n_tasks_valid
)
584 if (x
->memory_valid
&& y
->memory_valid
) {
585 if (x
->memory
> y
->memory
)
587 else if (x
->memory
< y
->memory
)
589 } else if (x
->memory_valid
)
591 else if (y
->memory_valid
)
597 if (x
->io_valid
&& y
->io_valid
) {
598 if (x
->io_input_bps
+ x
->io_output_bps
> y
->io_input_bps
+ y
->io_output_bps
)
600 else if (x
->io_input_bps
+ x
->io_output_bps
< y
->io_input_bps
+ y
->io_output_bps
)
602 } else if (x
->io_valid
)
604 else if (y
->io_valid
)
608 return path_compare(x
->path
, y
->path
);
611 static void display(Hashmap
*a
) {
616 unsigned rows
, n
= 0, j
, maxtcpu
= 0, maxtpath
= 3; /* 3 for ellipsize() to work properly */
617 char buffer
[MAX3(21, FORMAT_BYTES_MAX
, FORMAT_TIMESPAN_MAX
)];
621 if (!terminal_is_dumb())
622 fputs(ANSI_HOME_CLEAR
, stdout
);
624 array
= newa(Group
*, hashmap_size(a
));
626 HASHMAP_FOREACH(g
, a
, i
)
627 if (g
->n_tasks_valid
|| g
->cpu_valid
|| g
->memory_valid
|| g
->io_valid
)
630 qsort_safe(array
, n
, sizeof(Group
*), group_compare
);
632 /* Find the longest names in one run */
633 for (j
= 0; j
< n
; j
++) {
634 unsigned cputlen
, pathtlen
;
636 format_timespan(buffer
, sizeof(buffer
), (usec_t
) (array
[j
]->cpu_usage
/ NSEC_PER_USEC
), 0);
637 cputlen
= strlen(buffer
);
638 maxtcpu
= MAX(maxtcpu
, cputlen
);
640 pathtlen
= strlen(array
[j
]->path
);
641 maxtpath
= MAX(maxtpath
, pathtlen
);
644 if (arg_cpu_type
== CPU_PERCENT
)
645 xsprintf(buffer
, "%6s", "%CPU");
647 xsprintf(buffer
, "%*s", maxtcpu
, "CPU Time");
654 const char *on
, *off
;
656 path_columns
= columns() - 36 - strlen(buffer
);
657 if (path_columns
< 10)
660 on
= ansi_highlight_underline();
661 off
= ansi_underline();
663 printf("%s%s%-*s%s %s%7s%s %s%s%s %s%8s%s %s%8s%s %s%8s%s%s\n",
665 arg_order
== ORDER_PATH
? on
: "", path_columns
, "Control Group",
666 arg_order
== ORDER_PATH
? off
: "",
667 arg_order
== ORDER_TASKS
? on
: "", arg_count
== COUNT_PIDS
? "Tasks" : arg_count
== COUNT_USERSPACE_PROCESSES
? "Procs" : "Proc+",
668 arg_order
== ORDER_TASKS
? off
: "",
669 arg_order
== ORDER_CPU
? on
: "", buffer
,
670 arg_order
== ORDER_CPU
? off
: "",
671 arg_order
== ORDER_MEMORY
? on
: "", "Memory",
672 arg_order
== ORDER_MEMORY
? off
: "",
673 arg_order
== ORDER_IO
? on
: "", "Input/s",
674 arg_order
== ORDER_IO
? off
: "",
675 arg_order
== ORDER_IO
? on
: "", "Output/s",
676 arg_order
== ORDER_IO
? off
: "",
679 path_columns
= maxtpath
;
681 for (j
= 0; j
< n
; j
++) {
682 _cleanup_free_
char *ellipsized
= NULL
;
685 if (on_tty() && j
+ 6 > rows
)
690 path
= empty_to_root(g
->path
);
691 ellipsized
= ellipsize(path
, path_columns
, 33);
692 printf("%-*s", path_columns
, ellipsized
?: path
);
694 if (g
->n_tasks_valid
)
695 printf(" %7" PRIu64
, g
->n_tasks
);
699 if (arg_cpu_type
== CPU_PERCENT
) {
701 printf(" %6.1f", g
->cpu_fraction
*100);
705 printf(" %*s", maxtcpu
, format_timespan(buffer
, sizeof(buffer
), (usec_t
) (g
->cpu_usage
/ NSEC_PER_USEC
), 0));
707 printf(" %8s", maybe_format_bytes(buffer
, sizeof(buffer
), g
->memory_valid
, g
->memory
));
708 printf(" %8s", maybe_format_bytes(buffer
, sizeof(buffer
), g
->io_valid
, g
->io_input_bps
));
709 printf(" %8s", maybe_format_bytes(buffer
, sizeof(buffer
), g
->io_valid
, g
->io_output_bps
));
715 static void help(void) {
716 printf("%s [OPTIONS...] [CGROUP]\n\n"
717 "Show top control groups by their resource usage.\n\n"
718 " -h --help Show this help\n"
719 " --version Show package version\n"
720 " -p --order=path Order by path\n"
721 " -t --order=tasks Order by number of tasks/processes\n"
722 " -c --order=cpu Order by CPU load (default)\n"
723 " -m --order=memory Order by memory load\n"
724 " -i --order=io Order by IO load\n"
725 " -r --raw Provide raw (not human-readable) numbers\n"
726 " --cpu=percentage Show CPU usage as percentage (default)\n"
727 " --cpu=time Show CPU usage as time\n"
728 " -P Count userspace processes instead of tasks (excl. kernel)\n"
729 " -k Count all processes instead of tasks (incl. kernel)\n"
730 " --recursive=BOOL Sum up process count recursively\n"
731 " -d --delay=DELAY Delay between updates\n"
732 " -n --iterations=N Run for N iterations before exiting\n"
733 " -1 Shortcut for --iterations=1\n"
734 " -b --batch Run in batch mode, accepting no input\n"
735 " --depth=DEPTH Maximum traversal depth (default: %u)\n"
736 " -M --machine= Show container\n"
737 , program_invocation_short_name
, arg_depth
);
740 static int parse_argv(int argc
, char *argv
[]) {
750 static const struct option options
[] = {
751 { "help", no_argument
, NULL
, 'h' },
752 { "version", no_argument
, NULL
, ARG_VERSION
},
753 { "delay", required_argument
, NULL
, 'd' },
754 { "iterations", required_argument
, NULL
, 'n' },
755 { "batch", no_argument
, NULL
, 'b' },
756 { "raw", no_argument
, NULL
, 'r' },
757 { "depth", required_argument
, NULL
, ARG_DEPTH
},
758 { "cpu", optional_argument
, NULL
, ARG_CPU_TYPE
},
759 { "order", required_argument
, NULL
, ARG_ORDER
},
760 { "recursive", required_argument
, NULL
, ARG_RECURSIVE
},
761 { "machine", required_argument
, NULL
, 'M' },
770 while ((c
= getopt_long(argc
, argv
, "hptcmin:brd:kPM:1", options
, NULL
)) >= 0)
783 if (streq(optarg
, "time"))
784 arg_cpu_type
= CPU_TIME
;
785 else if (streq(optarg
, "percentage"))
786 arg_cpu_type
= CPU_PERCENT
;
788 log_error("Unknown argument to --cpu=: %s", optarg
);
792 arg_cpu_type
= CPU_TIME
;
797 r
= safe_atou(optarg
, &arg_depth
);
799 return log_error_errno(r
, "Failed to parse depth parameter: %s", optarg
);
804 r
= parse_sec(optarg
, &arg_delay
);
805 if (r
< 0 || arg_delay
<= 0) {
806 log_error("Failed to parse delay parameter: %s", optarg
);
813 r
= safe_atou(optarg
, &arg_iterations
);
815 return log_error_errno(r
, "Failed to parse iterations parameter: %s", optarg
);
832 arg_order
= ORDER_PATH
;
836 arg_order
= ORDER_TASKS
;
840 arg_order
= ORDER_CPU
;
844 arg_order
= ORDER_MEMORY
;
848 arg_order
= ORDER_IO
;
852 if (streq(optarg
, "path"))
853 arg_order
= ORDER_PATH
;
854 else if (streq(optarg
, "tasks"))
855 arg_order
= ORDER_TASKS
;
856 else if (streq(optarg
, "cpu"))
857 arg_order
= ORDER_CPU
;
858 else if (streq(optarg
, "memory"))
859 arg_order
= ORDER_MEMORY
;
860 else if (streq(optarg
, "io"))
861 arg_order
= ORDER_IO
;
863 log_error("Invalid argument to --order=: %s", optarg
);
869 arg_count
= COUNT_ALL_PROCESSES
;
873 arg_count
= COUNT_USERSPACE_PROCESSES
;
877 r
= parse_boolean(optarg
);
879 return log_error_errno(r
, "Failed to parse --recursive= argument: %s", optarg
);
882 arg_recursive_unset
= r
== 0;
886 arg_machine
= optarg
;
893 assert_not_reached("Unhandled option");
896 if (optind
== argc
- 1)
897 arg_root
= argv
[optind
];
898 else if (optind
< argc
) {
899 log_error("Too many arguments.");
906 static const char* counting_what(void) {
907 if (arg_count
== COUNT_PIDS
)
909 else if (arg_count
== COUNT_ALL_PROCESSES
)
910 return "all processes (incl. kernel)";
912 return "userspace processes (excl. kernel)";
915 int main(int argc
, char *argv
[]) {
917 Hashmap
*a
= NULL
, *b
= NULL
;
918 unsigned iteration
= 0;
919 usec_t last_refresh
= 0;
920 bool quit
= false, immediate_refresh
= false;
921 _cleanup_free_
char *root
= NULL
;
924 log_parse_environment();
927 r
= parse_argv(argc
, argv
);
931 r
= cg_mask_supported(&mask
);
933 log_error_errno(r
, "Failed to determine supported controllers: %m");
937 arg_count
= (mask
& CGROUP_MASK_PIDS
) ? COUNT_PIDS
: COUNT_USERSPACE_PROCESSES
;
939 if (arg_recursive_unset
&& arg_count
== COUNT_PIDS
) {
940 log_error("Non-recursive counting is only supported when counting processes, not tasks. Use -P or -k.");
944 r
= show_cgroup_get_path_and_warn(arg_machine
, arg_root
, &root
);
946 log_error_errno(r
, "Failed to get root control group path: %m");
949 log_debug("Cgroup path: %s", root
);
951 a
= hashmap_new(&path_hash_ops
);
952 b
= hashmap_new(&path_hash_ops
);
958 signal(SIGWINCH
, columns_lines_cache_reset
);
960 if (arg_iterations
== (unsigned) -1)
961 arg_iterations
= on_tty() ? 0 : 1;
967 char h
[FORMAT_TIMESPAN_MAX
];
969 t
= now(CLOCK_MONOTONIC
);
971 if (t
>= last_refresh
+ arg_delay
|| immediate_refresh
) {
973 r
= refresh(root
, a
, b
, iteration
++);
975 log_error_errno(r
, "Failed to refresh: %m");
979 group_hashmap_clear(b
);
986 immediate_refresh
= false;
991 if (arg_iterations
&& iteration
>= arg_iterations
)
994 if (!on_tty()) /* non-TTY: Empty newline as delimiter between polls */
999 (void) usleep(last_refresh
+ arg_delay
- t
);
1001 r
= read_one_char(stdin
, &key
, last_refresh
+ arg_delay
- t
, NULL
);
1002 if (r
== -ETIMEDOUT
)
1005 log_error_errno(r
, "Couldn't read key: %m");
1010 if (on_tty()) { /* TTY: Clear any user keystroke */
1011 fputs("\r \r", stdout
);
1021 immediate_refresh
= true;
1029 arg_order
= ORDER_PATH
;
1033 arg_order
= ORDER_TASKS
;
1037 arg_order
= ORDER_CPU
;
1041 arg_order
= ORDER_MEMORY
;
1045 arg_order
= ORDER_IO
;
1049 arg_cpu_type
= arg_cpu_type
== CPU_TIME
? CPU_PERCENT
: CPU_TIME
;
1053 arg_count
= arg_count
!= COUNT_ALL_PROCESSES
? COUNT_ALL_PROCESSES
: COUNT_PIDS
;
1054 fprintf(stdout
, "\nCounting: %s.", counting_what());
1060 arg_count
= arg_count
!= COUNT_USERSPACE_PROCESSES
? COUNT_USERSPACE_PROCESSES
: COUNT_PIDS
;
1061 fprintf(stdout
, "\nCounting: %s.", counting_what());
1067 if (arg_count
== COUNT_PIDS
)
1068 fprintf(stdout
, "\n\aCannot toggle recursive counting, not available in task counting mode.");
1070 arg_recursive
= !arg_recursive
;
1071 fprintf(stdout
, "\nRecursive process counting: %s", yes_no(arg_recursive
));
1078 if (arg_delay
< USEC_PER_SEC
)
1079 arg_delay
+= USEC_PER_MSEC
*250;
1081 arg_delay
+= USEC_PER_SEC
;
1083 fprintf(stdout
, "\nIncreased delay to %s.", format_timespan(h
, sizeof(h
), arg_delay
, 0));
1089 if (arg_delay
<= USEC_PER_MSEC
*500)
1090 arg_delay
= USEC_PER_MSEC
*250;
1091 else if (arg_delay
< USEC_PER_MSEC
*1250)
1092 arg_delay
-= USEC_PER_MSEC
*250;
1094 arg_delay
-= USEC_PER_SEC
;
1096 fprintf(stdout
, "\nDecreased delay to %s.", format_timespan(h
, sizeof(h
), arg_delay
, 0));
1104 #define ON ANSI_HIGHLIGHT
1105 #define OFF ANSI_NORMAL
1108 "\t<" ON
"p" OFF
"> By path; <" ON
"t" OFF
"> By tasks/procs; <" ON
"c" OFF
"> By CPU; <" ON
"m" OFF
"> By memory; <" ON
"i" OFF
"> By I/O\n"
1109 "\t<" ON
"+" OFF
"> Inc. delay; <" ON
"-" OFF
"> Dec. delay; <" ON
"%%" OFF
"> Toggle time; <" ON
"SPACE" OFF
"> Refresh\n"
1110 "\t<" ON
"P" OFF
"> Toggle count userspace processes; <" ON
"k" OFF
"> Toggle count all processes\n"
1111 "\t<" ON
"r" OFF
"> Count processes recursively; <" ON
"q" OFF
"> Quit");
1118 fprintf(stdout
, "\nUnknown key '\\x%x'. Ignoring.", key
);
1120 fprintf(stdout
, "\nUnknown key '%c'. Ignoring.", key
);
1130 group_hashmap_free(a
);
1131 group_hashmap_free(b
);
1133 return r
< 0 ? EXIT_FAILURE
: EXIT_SUCCESS
;