2016-07-11 15:33:05 +02:00
|
|
|
---
|
|
|
|
ps/common.h | 1 +
|
|
|
|
ps/global.c | 5 ++++-
|
|
|
|
ps/output.c | 19 ++++++++++---------
|
|
|
|
3 files changed, 15 insertions(+), 10 deletions(-)
|
|
|
|
|
2008-09-24 17:24:28 +02:00
|
|
|
--- ps/common.h
|
2018-04-04 15:18:39 +02:00
|
|
|
+++ ps/common.h 2018-04-04 11:14:33.915688098 +0000
|
2021-02-10 11:58:18 +01:00
|
|
|
@@ -303,6 +303,7 @@ extern int running_only;
|
2008-09-24 17:24:28 +02:00
|
|
|
extern int screen_cols;
|
|
|
|
extern int screen_rows;
|
2012-06-04 16:22:08 +02:00
|
|
|
extern time_t seconds_since_boot;
|
2008-09-24 17:24:28 +02:00
|
|
|
+extern unsigned long long jiffies_since_boot;
|
|
|
|
extern selection_node *selection_list;
|
|
|
|
extern unsigned simple_select;
|
|
|
|
extern sort_node *sort_list;
|
|
|
|
--- ps/global.c
|
2018-04-04 15:18:39 +02:00
|
|
|
+++ ps/global.c 2018-04-04 11:14:33.915688098 +0000
|
2016-07-11 15:33:05 +02:00
|
|
|
@@ -78,6 +78,7 @@ int prefer_bsd_defaults = -1
|
2008-09-24 17:24:28 +02:00
|
|
|
int screen_cols = -1;
|
|
|
|
int screen_rows = -1;
|
2012-06-04 16:22:08 +02:00
|
|
|
time_t seconds_since_boot = -1;
|
2008-09-24 17:24:28 +02:00
|
|
|
+unsigned long long jiffies_since_boot = -1;
|
|
|
|
selection_node *selection_list = (selection_node *)0xdeadbeef;
|
|
|
|
unsigned simple_select = 0xffffffff;
|
|
|
|
sort_node *sort_list = (sort_node *)0xdeadbeef; /* ready-to-use sort list */
|
2016-07-11 15:33:05 +02:00
|
|
|
@@ -361,6 +362,7 @@ static const char *set_personality(void)
|
2008-09-24 17:24:28 +02:00
|
|
|
/************ Call this to reinitialize everything ***************/
|
|
|
|
void reset_global(void){
|
|
|
|
static proc_t p;
|
|
|
|
+ double uptime_secs;
|
|
|
|
reset_selection_list();
|
|
|
|
look_up_our_self(&p);
|
|
|
|
set_screen_size();
|
2016-07-11 15:33:05 +02:00
|
|
|
@@ -383,7 +385,8 @@ void reset_global(void){
|
2008-09-24 17:24:28 +02:00
|
|
|
negate_selection = 0;
|
|
|
|
page_size = getpagesize();
|
|
|
|
running_only = 0;
|
|
|
|
- seconds_since_boot = uptime(0,0);
|
|
|
|
+ seconds_since_boot = uptime(&uptime_secs,0);
|
|
|
|
+ jiffies_since_boot = ((long double)uptime_secs * Hertz);
|
|
|
|
selection_list = NULL;
|
|
|
|
simple_select = 0;
|
|
|
|
sort_list = NULL;
|
|
|
|
--- ps/output.c
|
2018-04-04 15:18:39 +02:00
|
|
|
+++ ps/output.c 2018-04-04 11:14:33.915688098 +0000
|
2018-06-05 12:53:56 +02:00
|
|
|
@@ -134,6 +134,7 @@ static int sr_ ## NAME (const proc_t* P,
|
2013-05-29 15:55:21 +02:00
|
|
|
#define cook_time(P) (P->utime + P->stime) / Hertz
|
|
|
|
|
|
|
|
#define cook_etime(P) (((unsigned long long)seconds_since_boot >= (P->start_time / Hertz)) ? ((unsigned long long)seconds_since_boot - (P->start_time / Hertz)) : 0)
|
2013-12-17 14:19:30 +01:00
|
|
|
+#define cook_jtime(P) (((unsigned long long)jiffies_since_boot >= (P->start_time)) ? ((unsigned long long)jiffies_since_boot - (P->start_time)) : 0)
|
2013-05-29 15:55:21 +02:00
|
|
|
|
|
|
|
#define CMP_COOKED_TIME(NAME) \
|
|
|
|
static int sr_ ## NAME (const proc_t* P, const proc_t* Q) { \
|
2018-06-05 12:53:56 +02:00
|
|
|
@@ -507,11 +508,11 @@ static int pr_etimes(char *restrict cons
|
2008-09-24 17:24:28 +02:00
|
|
|
static int pr_c(char *restrict const outbuf, const proc_t *restrict const pp){
|
|
|
|
unsigned long long total_time; /* jiffies used by this process */
|
|
|
|
unsigned pcpu = 0; /* scaled %cpu, 99 means 99% */
|
|
|
|
- unsigned long long seconds; /* seconds of process life */
|
|
|
|
+ unsigned long long jiffies; /* jiffies of process life */
|
|
|
|
total_time = pp->utime + pp->stime;
|
|
|
|
if(include_dead_children) total_time += (pp->cutime + pp->cstime);
|
2013-05-29 15:55:21 +02:00
|
|
|
- seconds = cook_etime(pp);
|
2008-09-24 17:24:28 +02:00
|
|
|
- if(seconds) pcpu = (total_time * 100ULL / Hertz) / seconds;
|
2013-05-29 15:55:21 +02:00
|
|
|
+ jiffies = cook_jtime(pp);
|
2013-12-17 14:19:30 +01:00
|
|
|
+ if(jiffies) pcpu = (total_time * 100ULL) / jiffies;
|
2008-09-24 17:24:28 +02:00
|
|
|
if (pcpu > 99U) pcpu = 99U;
|
|
|
|
return snprintf(outbuf, COLWID, "%2u", pcpu);
|
|
|
|
}
|
2018-06-05 12:53:56 +02:00
|
|
|
@@ -519,11 +520,11 @@ static int pr_c(char *restrict const out
|
2008-09-24 17:24:28 +02:00
|
|
|
static int pr_pcpu(char *restrict const outbuf, const proc_t *restrict const pp){
|
|
|
|
unsigned long long total_time; /* jiffies used by this process */
|
|
|
|
unsigned pcpu = 0; /* scaled %cpu, 999 means 99.9% */
|
|
|
|
- unsigned long long seconds; /* seconds of process life */
|
|
|
|
+ unsigned long long jiffies; /* jiffies of process life */
|
|
|
|
total_time = pp->utime + pp->stime;
|
|
|
|
if(include_dead_children) total_time += (pp->cutime + pp->cstime);
|
2013-05-29 15:55:21 +02:00
|
|
|
- seconds = cook_etime(pp);
|
2008-09-24 17:24:28 +02:00
|
|
|
- if(seconds) pcpu = (total_time * 1000ULL / Hertz) / seconds;
|
2013-05-29 15:55:21 +02:00
|
|
|
+ jiffies = cook_jtime(pp);
|
2013-12-17 14:19:30 +01:00
|
|
|
+ if(jiffies) pcpu = (total_time * 1000ULL) / jiffies;
|
2013-05-29 15:55:21 +02:00
|
|
|
if (pcpu > 999U)
|
|
|
|
return snprintf(outbuf, COLWID, "%u", pcpu/10U);
|
2008-09-24 17:24:28 +02:00
|
|
|
return snprintf(outbuf, COLWID, "%u.%u", pcpu/10U, pcpu%10U);
|
2018-06-05 12:53:56 +02:00
|
|
|
@@ -532,11 +533,11 @@ static int pr_pcpu(char *restrict const
|
2008-09-24 17:24:28 +02:00
|
|
|
static int pr_cp(char *restrict const outbuf, const proc_t *restrict const pp){
|
|
|
|
unsigned long long total_time; /* jiffies used by this process */
|
|
|
|
unsigned pcpu = 0; /* scaled %cpu, 999 means 99.9% */
|
|
|
|
- unsigned long long seconds; /* seconds of process life */
|
|
|
|
+ unsigned long long jiffies; /* jiffies of process life */
|
|
|
|
total_time = pp->utime + pp->stime;
|
|
|
|
if(include_dead_children) total_time += (pp->cutime + pp->cstime);
|
2013-05-29 15:55:21 +02:00
|
|
|
- seconds = cook_etime(pp);
|
2008-09-24 17:24:28 +02:00
|
|
|
- if(seconds) pcpu = (total_time * 1000ULL / Hertz) / seconds;
|
2013-05-29 15:55:21 +02:00
|
|
|
+ jiffies = cook_jtime(pp);
|
2013-12-17 14:19:30 +01:00
|
|
|
+ if(jiffies) pcpu = (total_time * 1000ULL) / jiffies;
|
2008-09-24 17:24:28 +02:00
|
|
|
if (pcpu > 999U) pcpu = 999U;
|
|
|
|
return snprintf(outbuf, COLWID, "%3u", pcpu);
|
|
|
|
}
|