cgtop: convert to VERB_COMMAND and add --introspect-cli

The custom help() is replaced by a COMMAND() description, and
--introspect-cli is added.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2026-08-15 15:30:02 +02:00
parent d768cdcceb
commit cab5a18abb
2 changed files with 16 additions and 31 deletions
+15 -31
View File
@@ -3,28 +3,29 @@
#include <signal.h>
#include <unistd.h>
#include "sd-json.h"
#include "alloc-util.h"
#include "ansi-color.h"
#include "build.h"
#include "cgroup-show.h"
#include "cgroup-util.h"
#include "cpu-set-util.h"
#include "fd-util.h"
#include "fileio.h"
#include "format-table.h"
#include "hashmap.h"
#include "log.h"
#include "main-func.h"
#include "options.h"
#include "parse-argument.h"
#include "parse-util.h"
#include "path-util.h"
#include "pretty-print.h"
#include "process-util.h"
#include "procfs-util.h"
#include "sort-util.h"
#include "string-table.h"
#include "terminal-util.h"
#include "time-util.h"
#include "verbs.h"
#include "virt.h"
typedef struct Group {
@@ -89,6 +90,13 @@ static PidsCount arg_count = COUNT_PIDS;
static Order arg_order = ORDER_CPU;
static CPUType arg_cpu_type = CPU_PERCENTAGE;
COMMAND(
"systemd-cgtop\0",
"Show top control groups by their resource usage.",
.argspec = "[CGROUP]\0",
.man_pages = "systemd-cgtop.1\0",
);
static const char *order_table[_ORDER_MAX] = {
[ORDER_PATH] = "path",
[ORDER_TASKS] = "tasks",
@@ -684,33 +692,6 @@ static void display(Hashmap *a) {
}
}
static int help(void) {
_cleanup_free_ char *link = NULL;
_cleanup_(table_unrefp) Table *options = NULL;
int r;
r = terminal_urlify_man("systemd-cgtop", "1", &link);
if (r < 0)
return log_oom();
r = option_parser_get_help_table(&options);
if (r < 0)
return r;
printf("%s [OPTIONS...] [CGROUP]\n\n"
"%sShow top control groups by their resource usage.%s\n\n",
program_invocation_short_name,
ansi_highlight(),
ansi_normal());
r = table_print_or_warn(options);
if (r < 0)
return r;
printf("\nSee the %s for details.\n", link);
return 0;
}
static int parse_argv(int argc, char *argv[]) {
assert(argc >= 1);
assert(argv);
@@ -722,7 +703,7 @@ static int parse_argv(int argc, char *argv[]) {
switch (c) {
OPTION_COMMON_HELP:
return help();
return command_print_help("systemd-cgtop");
OPTION_COMMON_VERSION:
return version();
@@ -822,6 +803,9 @@ static int parse_argv(int argc, char *argv[]) {
OPTION_COMMON_MACHINE:
arg_machine = opts.arg;
break;
OPTION_COMMON_INTROSPECT_CLI:
return introspect_cli(SD_JSON_FORMAT_OFF);
}
size_t n_args = option_parser_get_n_args(&opts);
@@ -20,6 +20,7 @@ INTROSPECTABLE=(
systemd-bsod
systemd-cat
systemd-cgls
systemd-cgtop
systemd-dissect
systemd-firstboot
systemd-hwdb