mirror of
https://github.com/systemd/systemd
synced 2025-10-06 00:13:24 +02:00
cgtop: use table to parse --cpu=
This commit is contained in:
@@ -65,6 +65,13 @@ typedef enum {
|
|||||||
_ORDER_INVALID = -EINVAL,
|
_ORDER_INVALID = -EINVAL,
|
||||||
} Order;
|
} Order;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
CPU_PERCENT,
|
||||||
|
CPU_TIME,
|
||||||
|
_CPU_MAX,
|
||||||
|
_CPU_INVALID = -EINVAL,
|
||||||
|
} CPUType;
|
||||||
|
|
||||||
static unsigned arg_depth = 3;
|
static unsigned arg_depth = 3;
|
||||||
static unsigned arg_iterations = UINT_MAX;
|
static unsigned arg_iterations = UINT_MAX;
|
||||||
static bool arg_batch = false;
|
static bool arg_batch = false;
|
||||||
@@ -76,11 +83,7 @@ static bool arg_recursive = true;
|
|||||||
static bool arg_recursive_unset = false;
|
static bool arg_recursive_unset = false;
|
||||||
static PidsCount arg_count = COUNT_PIDS;
|
static PidsCount arg_count = COUNT_PIDS;
|
||||||
static Order arg_order = ORDER_CPU;
|
static Order arg_order = ORDER_CPU;
|
||||||
|
static CPUType arg_cpu_type = CPU_PERCENT;
|
||||||
static enum {
|
|
||||||
CPU_PERCENT,
|
|
||||||
CPU_TIME,
|
|
||||||
} arg_cpu_type = CPU_PERCENT;
|
|
||||||
|
|
||||||
static const char *order_table[_ORDER_MAX] = {
|
static const char *order_table[_ORDER_MAX] = {
|
||||||
[ORDER_PATH] = "path",
|
[ORDER_PATH] = "path",
|
||||||
@@ -92,6 +95,13 @@ static const char *order_table[_ORDER_MAX] = {
|
|||||||
|
|
||||||
DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(order, Order);
|
DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(order, Order);
|
||||||
|
|
||||||
|
static const char *cpu_type_table[_CPU_MAX] = {
|
||||||
|
[CPU_PERCENT] = "percentage",
|
||||||
|
[CPU_TIME] = "time",
|
||||||
|
};
|
||||||
|
|
||||||
|
DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(cpu_type, CPUType);
|
||||||
|
|
||||||
static Group *group_free(Group *g) {
|
static Group *group_free(Group *g) {
|
||||||
if (!g)
|
if (!g)
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -758,12 +768,9 @@ static int parse_argv(int argc, char *argv[]) {
|
|||||||
|
|
||||||
case ARG_CPU_TYPE:
|
case ARG_CPU_TYPE:
|
||||||
if (optarg) {
|
if (optarg) {
|
||||||
if (streq(optarg, "time"))
|
arg_cpu_type = cpu_type_from_string(optarg);
|
||||||
arg_cpu_type = CPU_TIME;
|
if (arg_cpu_type < 0)
|
||||||
else if (streq(optarg, "percentage"))
|
return log_error_errno(arg_cpu_type,
|
||||||
arg_cpu_type = CPU_PERCENT;
|
|
||||||
else
|
|
||||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
|
|
||||||
"Unknown argument to --cpu=: %s",
|
"Unknown argument to --cpu=: %s",
|
||||||
optarg);
|
optarg);
|
||||||
} else
|
} else
|
||||||
|
Reference in New Issue
Block a user