1 /* SPDX-License-Identifier: LGPL-2.1+ */
14 #include "alloc-util.h"
15 #include "bus-error.h"
17 #include "cgroup-show.h"
18 #include "cgroup-util.h"
22 #include "parse-util.h"
23 #include "path-util.h"
24 #include "process-util.h"
25 #include "procfs-util.h"
26 #include "stdio-util.h"
28 #include "terminal-util.h"
29 #include "unit-name.h"
33 typedef struct Group
{
43 unsigned cpu_iteration
;
50 unsigned io_iteration
;
51 uint64_t io_input
, io_output
;
53 uint64_t io_input_bps
, io_output_bps
;
56 static unsigned arg_depth
= 3;
57 static unsigned arg_iterations
= (unsigned) -1;
58 static bool arg_batch
= false;
59 static bool arg_raw
= false;
60 static usec_t arg_delay
= 1*USEC_PER_SEC
;
61 static char* arg_machine
= NULL
;
62 static char* arg_root
= NULL
;
63 static bool arg_recursive
= true;
64 static bool arg_recursive_unset
= false;
68 COUNT_USERSPACE_PROCESSES
,
70 } arg_count
= COUNT_PIDS
;
78 } arg_order
= ORDER_CPU
;
83 } arg_cpu_type
= CPU_PERCENT
;
85 static void group_free(Group
*g
) {
92 static void group_hashmap_clear(Hashmap
*h
) {
93 hashmap_clear_with_destructor(h
, group_free
);
96 static void group_hashmap_free(Hashmap
*h
) {
97 group_hashmap_clear(h
);
101 static const char *maybe_format_bytes(char *buf
, size_t l
, bool is_valid
, uint64_t t
) {
105 snprintf(buf
, l
, "%" PRIu64
, t
);
108 return format_bytes(buf
, l
, t
);
111 static bool is_root_cgroup(const char *path
) {
113 /* Returns true if the specified path belongs to the root cgroup. The root cgroup is special on cgroupsv2 as it
114 * carries only very few attributes in order not to export multiple truth about system state as most
115 * information is available elsewhere in /proc anyway. We need to be able to deal with that, and need to get
116 * our data from different sources in that case.
118 * There's one extra complication in all of this, though 😣: if the path to the cgroup indicates we are in the
119 * root cgroup this might actually not be the case, because cgroup namespacing might be in effect
120 * (CLONE_NEWCGROUP). Since there's no nice way to distuingish a real cgroup root from a fake namespaced one we
121 * do an explicit container check here, under the assumption that CLONE_NEWCGROUP is generally used when
122 * container managers are used too.
124 * Note that checking for a container environment is kinda ugly, since in theory people could use cgtop from
125 * inside a container where cgroup namespacing is turned off to watch the host system. However, that's mostly a
126 * theoretic usecase, and if people actually try all they'll lose is accounting for the top-level cgroup. Which
129 if (detect_container() > 0)
132 return empty_or_root(path
);
136 const char *controller
,
150 all_unified
= cg_all_unified();
154 g
= hashmap_get(a
, path
);
156 g
= hashmap_get(b
, path
);
162 g
->path
= strdup(path
);
168 r
= hashmap_put(a
, g
->path
, g
);
174 r
= hashmap_move_one(a
, b
, path
);
178 g
->cpu_valid
= g
->memory_valid
= g
->io_valid
= g
->n_tasks_valid
= false;
182 if (streq(controller
, SYSTEMD_CGROUP_CONTROLLER
) &&
183 IN_SET(arg_count
, COUNT_ALL_PROCESSES
, COUNT_USERSPACE_PROCESSES
)) {
184 _cleanup_fclose_
FILE *f
= NULL
;
187 r
= cg_enumerate_processes(controller
, path
, &f
);
194 while (cg_read_pid(f
, &pid
) > 0) {
196 if (arg_count
== COUNT_USERSPACE_PROCESSES
&& is_kernel_thread(pid
) > 0)
203 g
->n_tasks_valid
= true;
205 } else if (streq(controller
, "pids") && arg_count
== COUNT_PIDS
) {
207 if (is_root_cgroup(path
)) {
208 r
= procfs_tasks_get_current(&g
->n_tasks
);
212 _cleanup_free_
char *p
= NULL
, *v
= NULL
;
214 r
= cg_get_path(controller
, path
, "pids.current", &p
);
218 r
= read_one_line_file(p
, &v
);
224 r
= safe_atou64(v
, &g
->n_tasks
);
230 g
->n_tasks_valid
= true;
232 } else if (STR_IN_SET(controller
, "cpu", "cpuacct")) {
233 _cleanup_free_
char *p
= NULL
, *v
= NULL
;
237 if (is_root_cgroup(path
)) {
238 r
= procfs_cpu_get_usage(&new_usage
);
241 } else if (all_unified
) {
242 _cleanup_free_
char *val
= NULL
;
244 if (!streq(controller
, "cpu"))
247 r
= cg_get_keyed_attribute("cpu", path
, "cpu.stat", STRV_MAKE("usage_usec"), &val
);
248 if (IN_SET(r
, -ENOENT
, -ENXIO
))
253 r
= safe_atou64(val
, &new_usage
);
257 new_usage
*= NSEC_PER_USEC
;
259 if (!streq(controller
, "cpuacct"))
262 r
= cg_get_path(controller
, path
, "cpuacct.usage", &p
);
266 r
= read_one_line_file(p
, &v
);
272 r
= safe_atou64(v
, &new_usage
);
277 timestamp
= now_nsec(CLOCK_MONOTONIC
);
279 if (g
->cpu_iteration
== iteration
- 1 &&
280 (nsec_t
) new_usage
> g
->cpu_usage
) {
284 x
= timestamp
- g
->cpu_timestamp
;
288 y
= (nsec_t
) new_usage
- g
->cpu_usage
;
289 g
->cpu_fraction
= (double) y
/ (double) x
;
293 g
->cpu_usage
= (nsec_t
) new_usage
;
294 g
->cpu_timestamp
= timestamp
;
295 g
->cpu_iteration
= iteration
;
297 } else if (streq(controller
, "memory")) {
299 if (is_root_cgroup(path
)) {
300 r
= procfs_memory_get_current(&g
->memory
);
304 _cleanup_free_
char *p
= NULL
, *v
= NULL
;
307 r
= cg_get_path(controller
, path
, "memory.current", &p
);
309 r
= cg_get_path(controller
, path
, "memory.usage_in_bytes", &p
);
313 r
= read_one_line_file(p
, &v
);
319 r
= safe_atou64(v
, &g
->memory
);
325 g
->memory_valid
= true;
327 } else if ((streq(controller
, "io") && all_unified
) ||
328 (streq(controller
, "blkio") && !all_unified
)) {
329 _cleanup_fclose_
FILE *f
= NULL
;
330 _cleanup_free_
char *p
= NULL
;
331 uint64_t wr
= 0, rd
= 0;
334 r
= cg_get_path(controller
, path
, all_unified
? "io.stat" : "blkio.io_service_bytes", &p
);
346 char line
[LINE_MAX
], *l
;
349 if (!fgets(line
, sizeof(line
), f
))
352 /* Trim and skip the device */
354 l
+= strcspn(l
, WHITESPACE
);
355 l
+= strspn(l
, WHITESPACE
);
358 while (!isempty(l
)) {
359 if (sscanf(l
, "rbytes=%" SCNu64
, &k
))
361 else if (sscanf(l
, "wbytes=%" SCNu64
, &k
))
364 l
+= strcspn(l
, WHITESPACE
);
365 l
+= strspn(l
, WHITESPACE
);
368 if (first_word(l
, "Read")) {
371 } else if (first_word(l
, "Write")) {
377 l
+= strspn(l
, WHITESPACE
);
378 r
= safe_atou64(l
, &k
);
386 timestamp
= now_nsec(CLOCK_MONOTONIC
);
388 if (g
->io_iteration
== iteration
- 1) {
391 x
= (uint64_t) (timestamp
- g
->io_timestamp
);
395 if (rd
> g
->io_input
)
396 yr
= rd
- g
->io_input
;
400 if (wr
> g
->io_output
)
401 yw
= wr
- g
->io_output
;
405 if (yr
> 0 || yw
> 0) {
406 g
->io_input_bps
= (yr
* 1000000000ULL) / x
;
407 g
->io_output_bps
= (yw
* 1000000000ULL) / x
;
414 g
->io_timestamp
= timestamp
;
415 g
->io_iteration
= iteration
;
424 static int refresh_one(
425 const char *controller
,
433 _cleanup_closedir_
DIR *d
= NULL
;
441 if (depth
> arg_depth
)
444 r
= process(controller
, path
, a
, b
, iteration
, &ours
);
448 r
= cg_enumerate_subgroups(controller
, path
, &d
);
455 _cleanup_free_
char *fn
= NULL
, *p
= NULL
;
458 r
= cg_read_subgroup(d
, &fn
);
464 p
= strjoin(path
, "/", fn
);
468 path_simplify(p
, false);
470 r
= refresh_one(controller
, p
, a
, b
, iteration
, depth
+ 1, &child
);
475 IN_SET(arg_count
, COUNT_ALL_PROCESSES
, COUNT_USERSPACE_PROCESSES
) &&
477 child
->n_tasks_valid
&&
478 streq(controller
, SYSTEMD_CGROUP_CONTROLLER
)) {
480 /* Recursively sum up processes */
482 if (ours
->n_tasks_valid
)
483 ours
->n_tasks
+= child
->n_tasks
;
485 ours
->n_tasks
= child
->n_tasks
;
486 ours
->n_tasks_valid
= true;
497 static int refresh(const char *root
, Hashmap
*a
, Hashmap
*b
, unsigned iteration
) {
502 r
= refresh_one(SYSTEMD_CGROUP_CONTROLLER
, root
, a
, b
, iteration
, 0, NULL
);
505 r
= refresh_one("cpu", root
, a
, b
, iteration
, 0, NULL
);
508 r
= refresh_one("cpuacct", root
, a
, b
, iteration
, 0, NULL
);
511 r
= refresh_one("memory", root
, a
, b
, iteration
, 0, NULL
);
514 r
= refresh_one("io", root
, a
, b
, iteration
, 0, NULL
);
517 r
= refresh_one("blkio", root
, a
, b
, iteration
, 0, NULL
);
520 r
= refresh_one("pids", root
, a
, b
, iteration
, 0, NULL
);
527 static int group_compare(Group
* const *a
, Group
* const *b
) {
528 const Group
*x
= *a
, *y
= *b
;
531 if (arg_order
!= ORDER_TASKS
|| arg_recursive
) {
532 /* Let's make sure that the parent is always before
533 * the child. Except when ordering by tasks and
534 * recursive summing is off, since that is actually
535 * not accumulative for all children. */
537 if (path_startswith(empty_to_root(y
->path
), empty_to_root(x
->path
)))
539 if (path_startswith(empty_to_root(x
->path
), empty_to_root(y
->path
)))
549 if (arg_cpu_type
== CPU_PERCENT
) {
550 if (x
->cpu_valid
&& y
->cpu_valid
) {
551 r
= CMP(y
->cpu_fraction
, x
->cpu_fraction
);
554 } else if (x
->cpu_valid
)
556 else if (y
->cpu_valid
)
559 r
= CMP(y
->cpu_usage
, x
->cpu_usage
);
567 if (x
->n_tasks_valid
&& y
->n_tasks_valid
) {
568 r
= CMP(y
->n_tasks
, x
->n_tasks
);
571 } else if (x
->n_tasks_valid
)
573 else if (y
->n_tasks_valid
)
579 if (x
->memory_valid
&& y
->memory_valid
) {
580 r
= CMP(y
->memory
, x
->memory
);
583 } else if (x
->memory_valid
)
585 else if (y
->memory_valid
)
591 if (x
->io_valid
&& y
->io_valid
) {
592 r
= CMP(y
->io_input_bps
+ y
->io_output_bps
, x
->io_input_bps
+ x
->io_output_bps
);
595 } else if (x
->io_valid
)
597 else if (y
->io_valid
)
601 return path_compare(x
->path
, y
->path
);
604 static void display(Hashmap
*a
) {
609 unsigned rows
, n
= 0, j
, maxtcpu
= 0, maxtpath
= 3; /* 3 for ellipsize() to work properly */
610 char buffer
[MAX3(21, FORMAT_BYTES_MAX
, FORMAT_TIMESPAN_MAX
)];
614 if (!terminal_is_dumb())
615 fputs(ANSI_HOME_CLEAR
, stdout
);
617 array
= newa(Group
*, hashmap_size(a
));
619 HASHMAP_FOREACH(g
, a
, i
)
620 if (g
->n_tasks_valid
|| g
->cpu_valid
|| g
->memory_valid
|| g
->io_valid
)
623 typesafe_qsort(array
, n
, group_compare
);
625 /* Find the longest names in one run */
626 for (j
= 0; j
< n
; j
++) {
627 unsigned cputlen
, pathtlen
;
629 format_timespan(buffer
, sizeof(buffer
), (usec_t
) (array
[j
]->cpu_usage
/ NSEC_PER_USEC
), 0);
630 cputlen
= strlen(buffer
);
631 maxtcpu
= MAX(maxtcpu
, cputlen
);
633 pathtlen
= strlen(array
[j
]->path
);
634 maxtpath
= MAX(maxtpath
, pathtlen
);
637 if (arg_cpu_type
== CPU_PERCENT
)
638 xsprintf(buffer
, "%6s", "%CPU");
640 xsprintf(buffer
, "%*s", maxtcpu
, "CPU Time");
647 const char *on
, *off
;
649 path_columns
= columns() - 36 - strlen(buffer
);
650 if (path_columns
< 10)
653 on
= ansi_highlight_underline();
654 off
= ansi_underline();
656 printf("%s%s%-*s%s %s%7s%s %s%s%s %s%8s%s %s%8s%s %s%8s%s%s\n",
658 arg_order
== ORDER_PATH
? on
: "", path_columns
, "Control Group",
659 arg_order
== ORDER_PATH
? off
: "",
660 arg_order
== ORDER_TASKS
? on
: "", arg_count
== COUNT_PIDS
? "Tasks" : arg_count
== COUNT_USERSPACE_PROCESSES
? "Procs" : "Proc+",
661 arg_order
== ORDER_TASKS
? off
: "",
662 arg_order
== ORDER_CPU
? on
: "", buffer
,
663 arg_order
== ORDER_CPU
? off
: "",
664 arg_order
== ORDER_MEMORY
? on
: "", "Memory",
665 arg_order
== ORDER_MEMORY
? off
: "",
666 arg_order
== ORDER_IO
? on
: "", "Input/s",
667 arg_order
== ORDER_IO
? off
: "",
668 arg_order
== ORDER_IO
? on
: "", "Output/s",
669 arg_order
== ORDER_IO
? off
: "",
672 path_columns
= maxtpath
;
674 for (j
= 0; j
< n
; j
++) {
675 _cleanup_free_
char *ellipsized
= NULL
;
678 if (on_tty() && j
+ 6 > rows
)
683 path
= empty_to_root(g
->path
);
684 ellipsized
= ellipsize(path
, path_columns
, 33);
685 printf("%-*s", path_columns
, ellipsized
?: path
);
687 if (g
->n_tasks_valid
)
688 printf(" %7" PRIu64
, g
->n_tasks
);
692 if (arg_cpu_type
== CPU_PERCENT
) {
694 printf(" %6.1f", g
->cpu_fraction
*100);
698 printf(" %*s", maxtcpu
, format_timespan(buffer
, sizeof(buffer
), (usec_t
) (g
->cpu_usage
/ NSEC_PER_USEC
), 0));
700 printf(" %8s", maybe_format_bytes(buffer
, sizeof(buffer
), g
->memory_valid
, g
->memory
));
701 printf(" %8s", maybe_format_bytes(buffer
, sizeof(buffer
), g
->io_valid
, g
->io_input_bps
));
702 printf(" %8s", maybe_format_bytes(buffer
, sizeof(buffer
), g
->io_valid
, g
->io_output_bps
));
708 static int help(void) {
709 _cleanup_free_
char *link
= NULL
;
712 r
= terminal_urlify_man("systemd-cgtop", "1", &link
);
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 "\nSee the %s for details.\n"
738 , program_invocation_short_name
746 static int parse_argv(int argc
, char *argv
[]) {
756 static const struct option options
[] = {
757 { "help", no_argument
, NULL
, 'h' },
758 { "version", no_argument
, NULL
, ARG_VERSION
},
759 { "delay", required_argument
, NULL
, 'd' },
760 { "iterations", required_argument
, NULL
, 'n' },
761 { "batch", no_argument
, NULL
, 'b' },
762 { "raw", no_argument
, NULL
, 'r' },
763 { "depth", required_argument
, NULL
, ARG_DEPTH
},
764 { "cpu", optional_argument
, NULL
, ARG_CPU_TYPE
},
765 { "order", required_argument
, NULL
, ARG_ORDER
},
766 { "recursive", required_argument
, NULL
, ARG_RECURSIVE
},
767 { "machine", required_argument
, NULL
, 'M' },
776 while ((c
= getopt_long(argc
, argv
, "hptcmin:brd:kPM:1", options
, NULL
)) >= 0)
788 if (streq(optarg
, "time"))
789 arg_cpu_type
= CPU_TIME
;
790 else if (streq(optarg
, "percentage"))
791 arg_cpu_type
= CPU_PERCENT
;
793 log_error("Unknown argument to --cpu=: %s", optarg
);
797 arg_cpu_type
= CPU_TIME
;
802 r
= safe_atou(optarg
, &arg_depth
);
804 return log_error_errno(r
, "Failed to parse depth parameter: %s", optarg
);
809 r
= parse_sec(optarg
, &arg_delay
);
810 if (r
< 0 || arg_delay
<= 0) {
811 log_error("Failed to parse delay parameter: %s", optarg
);
818 r
= safe_atou(optarg
, &arg_iterations
);
820 return log_error_errno(r
, "Failed to parse iterations parameter: %s", optarg
);
837 arg_order
= ORDER_PATH
;
841 arg_order
= ORDER_TASKS
;
845 arg_order
= ORDER_CPU
;
849 arg_order
= ORDER_MEMORY
;
853 arg_order
= ORDER_IO
;
857 if (streq(optarg
, "path"))
858 arg_order
= ORDER_PATH
;
859 else if (streq(optarg
, "tasks"))
860 arg_order
= ORDER_TASKS
;
861 else if (streq(optarg
, "cpu"))
862 arg_order
= ORDER_CPU
;
863 else if (streq(optarg
, "memory"))
864 arg_order
= ORDER_MEMORY
;
865 else if (streq(optarg
, "io"))
866 arg_order
= ORDER_IO
;
868 log_error("Invalid argument to --order=: %s", optarg
);
874 arg_count
= COUNT_ALL_PROCESSES
;
878 arg_count
= COUNT_USERSPACE_PROCESSES
;
882 r
= parse_boolean(optarg
);
884 return log_error_errno(r
, "Failed to parse --recursive= argument: %s", optarg
);
887 arg_recursive_unset
= r
== 0;
891 arg_machine
= optarg
;
898 assert_not_reached("Unhandled option");
901 if (optind
== argc
- 1)
902 arg_root
= argv
[optind
];
903 else if (optind
< argc
) {
904 log_error("Too many arguments.");
911 static const char* counting_what(void) {
912 if (arg_count
== COUNT_PIDS
)
914 else if (arg_count
== COUNT_ALL_PROCESSES
)
915 return "all processes (incl. kernel)";
917 return "userspace processes (excl. kernel)";
920 int main(int argc
, char *argv
[]) {
922 Hashmap
*a
= NULL
, *b
= NULL
;
923 unsigned iteration
= 0;
924 usec_t last_refresh
= 0;
925 bool quit
= false, immediate_refresh
= false;
926 _cleanup_free_
char *root
= NULL
;
929 log_parse_environment();
932 r
= parse_argv(argc
, argv
);
936 r
= cg_mask_supported(&mask
);
938 log_error_errno(r
, "Failed to determine supported controllers: %m");
942 arg_count
= (mask
& CGROUP_MASK_PIDS
) ? COUNT_PIDS
: COUNT_USERSPACE_PROCESSES
;
944 if (arg_recursive_unset
&& arg_count
== COUNT_PIDS
) {
945 log_error("Non-recursive counting is only supported when counting processes, not tasks. Use -P or -k.");
949 r
= show_cgroup_get_path_and_warn(arg_machine
, arg_root
, &root
);
951 log_error_errno(r
, "Failed to get root control group path: %m");
954 log_debug("Cgroup path: %s", root
);
956 a
= hashmap_new(&path_hash_ops
);
957 b
= hashmap_new(&path_hash_ops
);
963 signal(SIGWINCH
, columns_lines_cache_reset
);
965 if (arg_iterations
== (unsigned) -1)
966 arg_iterations
= on_tty() ? 0 : 1;
972 char h
[FORMAT_TIMESPAN_MAX
];
974 t
= now(CLOCK_MONOTONIC
);
976 if (t
>= last_refresh
+ arg_delay
|| immediate_refresh
) {
978 r
= refresh(root
, a
, b
, iteration
++);
980 log_error_errno(r
, "Failed to refresh: %m");
984 group_hashmap_clear(b
);
991 immediate_refresh
= false;
996 if (arg_iterations
&& iteration
>= arg_iterations
)
999 if (!on_tty()) /* non-TTY: Empty newline as delimiter between polls */
1000 fputs("\n", stdout
);
1004 (void) usleep(last_refresh
+ arg_delay
- t
);
1006 r
= read_one_char(stdin
, &key
, last_refresh
+ arg_delay
- t
, NULL
);
1007 if (r
== -ETIMEDOUT
)
1010 log_error_errno(r
, "Couldn't read key: %m");
1015 if (on_tty()) { /* TTY: Clear any user keystroke */
1016 fputs("\r \r", stdout
);
1026 immediate_refresh
= true;
1034 arg_order
= ORDER_PATH
;
1038 arg_order
= ORDER_TASKS
;
1042 arg_order
= ORDER_CPU
;
1046 arg_order
= ORDER_MEMORY
;
1050 arg_order
= ORDER_IO
;
1054 arg_cpu_type
= arg_cpu_type
== CPU_TIME
? CPU_PERCENT
: CPU_TIME
;
1058 arg_count
= arg_count
!= COUNT_ALL_PROCESSES
? COUNT_ALL_PROCESSES
: COUNT_PIDS
;
1059 fprintf(stdout
, "\nCounting: %s.", counting_what());
1065 arg_count
= arg_count
!= COUNT_USERSPACE_PROCESSES
? COUNT_USERSPACE_PROCESSES
: COUNT_PIDS
;
1066 fprintf(stdout
, "\nCounting: %s.", counting_what());
1072 if (arg_count
== COUNT_PIDS
)
1073 fprintf(stdout
, "\n\aCannot toggle recursive counting, not available in task counting mode.");
1075 arg_recursive
= !arg_recursive
;
1076 fprintf(stdout
, "\nRecursive process counting: %s", yes_no(arg_recursive
));
1083 if (arg_delay
< USEC_PER_SEC
)
1084 arg_delay
+= USEC_PER_MSEC
*250;
1086 arg_delay
+= USEC_PER_SEC
;
1088 fprintf(stdout
, "\nIncreased delay to %s.", format_timespan(h
, sizeof(h
), arg_delay
, 0));
1094 if (arg_delay
<= USEC_PER_MSEC
*500)
1095 arg_delay
= USEC_PER_MSEC
*250;
1096 else if (arg_delay
< USEC_PER_MSEC
*1250)
1097 arg_delay
-= USEC_PER_MSEC
*250;
1099 arg_delay
-= USEC_PER_SEC
;
1101 fprintf(stdout
, "\nDecreased delay to %s.", format_timespan(h
, sizeof(h
), arg_delay
, 0));
1109 #define ON ANSI_HIGHLIGHT
1110 #define OFF ANSI_NORMAL
1113 "\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"
1114 "\t<" ON
"+" OFF
"> Inc. delay; <" ON
"-" OFF
"> Dec. delay; <" ON
"%%" OFF
"> Toggle time; <" ON
"SPACE" OFF
"> Refresh\n"
1115 "\t<" ON
"P" OFF
"> Toggle count userspace processes; <" ON
"k" OFF
"> Toggle count all processes\n"
1116 "\t<" ON
"r" OFF
"> Count processes recursively; <" ON
"q" OFF
"> Quit");
1123 fprintf(stdout
, "\nUnknown key '\\x%x'. Ignoring.", key
);
1125 fprintf(stdout
, "\nUnknown key '%c'. Ignoring.", key
);
1135 group_hashmap_free(a
);
1136 group_hashmap_free(b
);
1138 return r
< 0 ? EXIT_FAILURE
: EXIT_SUCCESS
;