diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-08-28 02:04:33 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-08-28 02:27:29 +0200 |
commit | 45d7a8bb6c0e0caa4dd2a1cf1108b7ba2c0ebac4 (patch) | |
tree | 8c92582e73bdc41702382c59dbff752ee2742ce5 /src/basic | |
parent | 21b735e798c580e7af8c33ace9f8565860b7f8df (diff) |
cgtop: major modernizations
In preparation of the unified cgroup support, let's clean up cgtop:
a) rework time code to be based on "nsec_t" rather than "struct timespec"
b) Introduce long option --order= for selecting ordering
c) count number of processes only in the main hierarchy, don't bother
with the controller hierarchies. We don't allow orthogonal
hierarchies in systemd anymore, hence there's no point to check the
other hierarchies.
d) Deal with non-monotonic cpuacct values (see #749)
e) When sorting groups, don't do prefix compare when ordering by number
of tasks, since this is not accumulative for all children.
f) Actually make --cpu without parameter work
g) Don't output control characters when we get them as input.
Fixes #749.
Diffstat (limited to 'src/basic')
-rw-r--r-- | src/basic/time-util.c | 20 | ||||
-rw-r--r-- | src/basic/time-util.h | 3 |
2 files changed, 23 insertions, 0 deletions
diff --git a/src/basic/time-util.c b/src/basic/time-util.c index e278196c90..b0e5883b87 100644 --- a/src/basic/time-util.c +++ b/src/basic/time-util.c @@ -36,6 +36,14 @@ usec_t now(clockid_t clock_id) { return timespec_load(&ts); } +nsec_t now_nsec(clockid_t clock_id) { + struct timespec ts; + + assert_se(clock_gettime(clock_id, &ts) == 0); + + return timespec_load_nsec(&ts); +} + dual_timestamp* dual_timestamp_get(dual_timestamp *ts) { assert(ts); @@ -129,6 +137,18 @@ usec_t timespec_load(const struct timespec *ts) { (usec_t) ts->tv_nsec / NSEC_PER_USEC; } +nsec_t timespec_load_nsec(const struct timespec *ts) { + assert(ts); + + if (ts->tv_sec == (time_t) -1 && + ts->tv_nsec == (long) -1) + return NSEC_INFINITY; + + return + (nsec_t) ts->tv_sec * NSEC_PER_SEC + + (nsec_t) ts->tv_nsec; +} + struct timespec *timespec_store(struct timespec *ts, usec_t u) { assert(ts); diff --git a/src/basic/time-util.h b/src/basic/time-util.h index 2aba042217..ebafefa0ee 100644 --- a/src/basic/time-util.h +++ b/src/basic/time-util.h @@ -70,6 +70,7 @@ typedef struct dual_timestamp { #define DUAL_TIMESTAMP_NULL ((struct dual_timestamp) { 0ULL, 0ULL }) usec_t now(clockid_t clock); +nsec_t now_nsec(clockid_t clock); dual_timestamp* dual_timestamp_get(dual_timestamp *ts); dual_timestamp* dual_timestamp_from_realtime(dual_timestamp *ts, usec_t u); @@ -87,6 +88,8 @@ struct timespec *timespec_store(struct timespec *ts, usec_t u); usec_t timeval_load(const struct timeval *tv) _pure_; struct timeval *timeval_store(struct timeval *tv, usec_t u); +nsec_t timespec_load_nsec(const struct timespec *ts) _pure_; + char *format_timestamp(char *buf, size_t l, usec_t t); char *format_timestamp_utc(char *buf, size_t l, usec_t t); char *format_timestamp_us(char *buf, size_t l, usec_t t); |