#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 "virt.h"
COUNT_PIDS, /* most, requires pids controller */
} PidsCount;
+typedef enum {
+ ORDER_PATH,
+ ORDER_TASKS,
+ ORDER_CPU,
+ ORDER_MEMORY,
+ ORDER_IO,
+ _ORDER_MAX,
+ _ORDER_INVALID = -EINVAL,
+} Order;
+
static unsigned arg_depth = 3;
static unsigned arg_iterations = UINT_MAX;
static bool arg_batch = false;
static char* arg_root = NULL;
static bool arg_recursive = true;
static bool arg_recursive_unset = false;
-
static PidsCount arg_count = COUNT_PIDS;
-
-static enum {
- ORDER_PATH,
- ORDER_TASKS,
- ORDER_CPU,
- ORDER_MEMORY,
- ORDER_IO,
-} arg_order = ORDER_CPU;
+static Order arg_order = ORDER_CPU;
static enum {
CPU_PERCENT,
CPU_TIME,
} arg_cpu_type = CPU_PERCENT;
+static const char *order_table[_ORDER_MAX] = {
+ [ORDER_PATH] = "path",
+ [ORDER_TASKS] = "tasks",
+ [ORDER_CPU] = "cpu",
+ [ORDER_MEMORY] = "memory",
+ [ORDER_IO] = "io",
+};
+
+DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(order, Order);
+
static Group *group_free(Group *g) {
if (!g)
return NULL;
return -1;
else if (y->io_valid)
return 1;
+
+ break;
+
+ case _ORDER_MAX:
+ case _ORDER_INVALID:
+ assert_not_reached();
}
return path_compare(x->path, y->path);
break;
case ARG_ORDER:
- if (streq(optarg, "path"))
- arg_order = ORDER_PATH;
- else if (streq(optarg, "tasks"))
- arg_order = ORDER_TASKS;
- else if (streq(optarg, "cpu"))
- arg_order = ORDER_CPU;
- else if (streq(optarg, "memory"))
- arg_order = ORDER_MEMORY;
- else if (streq(optarg, "io"))
- arg_order = ORDER_IO;
- else
- return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ arg_order = order_from_string(optarg);
+ if (arg_order < 0)
+ return log_error_errno(arg_order,
"Invalid argument to --order=: %s",
optarg);
break;