From 30997b967ad11da7815775aedd9683e9e77e4f13 Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Wed, 30 Sep 2015 00:00:00 -0500 Subject: [PATCH] library: add TIME_ALL/TIME_ELAPSED needed by ps Shoot, here's yet another bow to ps needs. But it's ok because it makes a lot of sense. Rather than force all users into their own calculations do but it once here. As an aside this need arose during ps testing when the sorts were using TIME_START or TICS_ALL. That was just fine for almost every need except 'etime' plus 'time'. That 'etime' was sorting the opposite of what's wanted when using TIME_START (of course) while 'time' yielded some weird ordering because TICS_ALL was too granular. Signed-off-by: Jim Warner --- proc/pids.c | 14 ++++++++++++++ proc/pids.h | 2 ++ 2 files changed, 16 insertions(+) diff --git a/proc/pids.c b/proc/pids.c index 9d0a8021..015656fa 100644 --- a/proc/pids.c +++ b/proc/pids.c @@ -36,6 +36,8 @@ #include #include +#include +#include #include "procps-private.h" #include "devname.h" // and a few headers for our @@ -81,6 +83,8 @@ struct procps_pidsinfo { PROCTAB *PT; // the old library essential interface struct pids_counts counts; // counts for 'procps_pids_stacks_fill' struct pids_reap reaped; // counts + stacks for 'procps_pids_reap' + unsigned long hertz; // for TIME_ALL & TIME_ELAPSED calculations + unsigned long long boot_seconds; // for TIME_ELAPSED calculation }; @@ -207,6 +211,9 @@ REG_set(TICS_SYSTEM, ull_int, stime) REG_set(TICS_SYSTEM_C, ull_int, cstime) REG_set(TICS_USER, ull_int, utime) REG_set(TICS_USER_C, ull_int, cutime) +setDECL(TIME_ALL) { R->result.ull_int = (P->utime + P->stime) / I->hertz; } +setDECL(TIME_ELAPSED) { R->result.ull_int = (I->boot_seconds >= (P->start_time / I->hertz)) ? I->boot_seconds - (P->start_time / I->hertz) : 0; } + REG_set(TIME_START, ull_int, start_time) REG_set(TTY, s_int, tty) setDECL(TTY_NAME) { char buf[64]; (void)I; dev_to_tty(buf, sizeof(buf), P->tty, P->tid, ABBREV_DEV); R->result.str = strdup(buf); } @@ -454,6 +461,8 @@ static struct { { RS(TICS_SYSTEM_C), f_stat, NULL, QS(ull_int), 0 }, { RS(TICS_USER), f_stat, NULL, QS(ull_int), 0 }, { RS(TICS_USER_C), f_stat, NULL, QS(ull_int), 0 }, + { RS(TIME_ALL), f_stat, NULL, QS(ull_int), 0 }, + { RS(TIME_ELAPSED), f_stat, NULL, QS(ull_int), 0 }, { RS(TIME_START), f_stat, NULL, QS(ull_int), 0 }, { RS(TTY), f_stat, NULL, QS(s_int), 0 }, { RS(TTY_NAME), f_stat, FF(str), QS(strvers), 0 }, @@ -1011,6 +1020,7 @@ PROCPS_EXPORT int procps_pids_new ( enum pids_item *items) { struct procps_pidsinfo *p; + double uptime_secs; int pgsz; if (info == NULL || *info != NULL) @@ -1041,6 +1051,10 @@ PROCPS_EXPORT int procps_pids_new ( config_history(p); + p->hertz = procps_hertz_get(); + procps_uptime(&uptime_secs, NULL); + p->boot_seconds = (unsigned long)uptime_secs; + p->refcount = 1; *info = p; return 0; diff --git a/proc/pids.h b/proc/pids.h index 55be7f83..3aec9b23 100644 --- a/proc/pids.h +++ b/proc/pids.h @@ -120,6 +120,8 @@ enum pids_item { PROCPS_PIDS_TICS_SYSTEM_C, // ull_int PROCPS_PIDS_TICS_USER, // ull_int PROCPS_PIDS_TICS_USER_C, // ull_int + PROCPS_PIDS_TIME_ALL, // ull_int + PROCPS_PIDS_TIME_ELAPSED, // ull_int PROCPS_PIDS_TIME_START, // ull_int PROCPS_PIDS_TTY, // s_int PROCPS_PIDS_TTY_NAME, // str -- 2.40.0