#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"
Group *g;
Group **array;
signed path_columns;
- unsigned rows, n = 0, maxtcpu = 0, maxtpath = 3; /* 3 for ellipsize() to work properly */
+ unsigned rows, n = 0, maxtcpu = 0, maxtpath = 3, /* 3 for ellipsize() to work properly */
+ maxpcpu = 6; /* minimum width for "%CPU" header */
assert(a);
strlen(array[j]->path));
}
+ if (arg_cpu_type == CPU_PERCENTAGE) {
+ unsigned n_cpus;
+ if (cpus_online(&n_cpus) >= 0)
+ maxpcpu = MAX(maxpcpu, DECIMAL_STR_WIDTH(n_cpus) + STRLEN("00.0"));
+ }
+
rows = lines();
if (rows <= 10)
rows = 10;
if (on_tty()) {
const char *on, *off;
- int cpu_len = arg_cpu_type == CPU_PERCENTAGE ? 6 : maxtcpu;
+ int cpu_len = arg_cpu_type == CPU_PERCENTAGE ? (int) maxpcpu : (int) maxtcpu;
path_columns = columns() - 36 - cpu_len;
if (path_columns < 10)
if (arg_cpu_type == CPU_PERCENTAGE) {
if (g->cpu_valid)
- printf(" %6.1f", g->cpu_fraction*100);
+ printf(" %*.1f", (int) maxpcpu, g->cpu_fraction*100);
else
- fputs(" -", stdout);
+ printf(" %*s", (int) maxpcpu, "-");
} else
printf(" %*s",
(int) maxtcpu,