summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorArian van Putten <arian.vanputten@gmail.com>2020-10-14 13:47:17 +0200
committerLennart Poettering <lennart@poettering.net>2020-10-21 14:29:48 +0200
commit429495163cbc1eb331a15d16fb26c829aa43ff0d (patch)
tree4a080ce14b6b8ed166be267208d6f33305662780 /src
parentMerge pull request #17395 from keszybz/hwdb-drop-quotes (diff)
downloadsystemd-429495163cbc1eb331a15d16fb26c829aa43ff0d.tar.xz
systemd-429495163cbc1eb331a15d16fb26c829aa43ff0d.zip
cgtop: Display cpu time in microseonds with --raw
this makes the CPU time easily parseable; which was the goal of --raw in the first place. This only triggers if --raw is combined with --cpu=time
Diffstat (limited to 'src')
-rw-r--r--src/basic/macro.h6
-rw-r--r--src/cgtop/cgtop.c15
2 files changed, 18 insertions, 3 deletions
diff --git a/src/basic/macro.h b/src/basic/macro.h
index e0fe990bef..7aa51fe939 100644
--- a/src/basic/macro.h
+++ b/src/basic/macro.h
@@ -281,6 +281,12 @@ static inline size_t GREEDY_ALLOC_ROUND_UP(size_t l) {
MAX(_c, z); \
})
+#define MAX4(x, y, z, a) \
+ ({ \
+ const typeof(x) _d = MAX3(x, y, z); \
+ MAX(_d, a); \
+ })
+
#undef MIN
#define MIN(a, b) __MIN(UNIQ, (a), UNIQ, (b))
#define __MIN(aq, a, bq, b) \
diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c
index 0b6c2f88ed..0efaf3873e 100644
--- a/src/cgtop/cgtop.c
+++ b/src/cgtop/cgtop.c
@@ -91,6 +91,15 @@ static Group *group_free(Group *g) {
return mfree(g);
}
+
+static const char *maybe_format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy) {
+ if (arg_raw) {
+ snprintf(buf, l, USEC_FMT, t);
+ return buf;
+ }
+ return format_timespan(buf, l, t, accuracy);
+}
+
static const char *maybe_format_bytes(char *buf, size_t l, bool is_valid, uint64_t t) {
if (!is_valid)
return "-";
@@ -586,7 +595,7 @@ static void display(Hashmap *a) {
Group **array;
signed path_columns;
unsigned rows, n = 0, j, maxtcpu = 0, maxtpath = 3; /* 3 for ellipsize() to work properly */
- char buffer[MAX3(21U, FORMAT_BYTES_MAX, FORMAT_TIMESPAN_MAX)];
+ char buffer[MAX4(21U, FORMAT_BYTES_MAX, FORMAT_TIMESPAN_MAX, DECIMAL_STR_MAX(usec_t))];
assert(a);
@@ -605,7 +614,7 @@ static void display(Hashmap *a) {
for (j = 0; j < n; j++) {
unsigned cputlen, pathtlen;
- format_timespan(buffer, sizeof(buffer), (usec_t) (array[j]->cpu_usage / NSEC_PER_USEC), 0);
+ maybe_format_timespan(buffer, sizeof(buffer), (usec_t) (array[j]->cpu_usage / NSEC_PER_USEC), 0);
cputlen = strlen(buffer);
maxtcpu = MAX(maxtcpu, cputlen);
@@ -674,7 +683,7 @@ static void display(Hashmap *a) {
else
fputs(" -", stdout);
} else
- printf(" %*s", maxtcpu, format_timespan(buffer, sizeof(buffer), (usec_t) (g->cpu_usage / NSEC_PER_USEC), 0));
+ printf(" %*s", maxtcpu, maybe_format_timespan(buffer, sizeof(buffer), (usec_t) (g->cpu_usage / NSEC_PER_USEC), 0));
printf(" %8s", maybe_format_bytes(buffer, sizeof(buffer), g->memory_valid, g->memory));
printf(" %8s", maybe_format_bytes(buffer, sizeof(buffer), g->io_valid, g->io_input_bps));