format_interval_wide
This commit is contained in:
parent
1e1645c4d4
commit
33023bbf34
@ -12,9 +12,9 @@
|
|||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
#ifdef MINORVERSION
|
#ifdef MINORVERSION
|
||||||
char procps_version[] = "procps version " VERSION "." SUBVERSION "." MINORVERSION;
|
const char procps_version[] = "procps version " VERSION "." SUBVERSION "." MINORVERSION;
|
||||||
#else
|
#else
|
||||||
char procps_version[] = "procps version " VERSION ;
|
const char procps_version[] = "procps version " VERSION "." SUBVERSION;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void display_version(void) {
|
void display_version(void) {
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
extern void display_version(void); /* display suite version */
|
extern void display_version(void); /* display suite version */
|
||||||
extern char procps_version[]; /* global buf for suite version */
|
extern const char procps_version[]; /* global buf for suite version */
|
||||||
|
|
||||||
extern int linux_version_code; /* runtime version of LINUX_VERSION_CODE
|
extern int linux_version_code; /* runtime version of LINUX_VERSION_CODE
|
||||||
in /usr/include/linux/version.h */
|
in /usr/include/linux/version.h */
|
||||||
|
48
top.c
48
top.c
@ -755,6 +755,45 @@ static const char *scale_tics (TICS_t tics, const int width)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static const char *format_interval_wide(unsigned long long tick64)
|
||||||
|
{
|
||||||
|
static char buf[TNYBUFSIZ];
|
||||||
|
unsigned day, hr, min, sec;
|
||||||
|
|
||||||
|
if( sizeof(long)==4 && (tick64>>32) ){ // if need 64-bit on 32-bit
|
||||||
|
sec = tick64 / Hertz; // seconds won't overflow 32-bit
|
||||||
|
min = sec/60u; // total minutes
|
||||||
|
}else{
|
||||||
|
unsigned long hz = Hertz;
|
||||||
|
unsigned long tick = tick64;
|
||||||
|
sec = tick / hz; // total seconds
|
||||||
|
min = sec/60u; // total minutes
|
||||||
|
if(min < 120u){ // less than 120 minutes --> use MMM:SS.XX
|
||||||
|
unsigned wee = tick - sec*hz;
|
||||||
|
if(100ul != hz){ // if jiffies aren't centiseconds
|
||||||
|
if(1000ul == hz) wee /= 10u;
|
||||||
|
else wee = wee * 100u / hz;
|
||||||
|
}
|
||||||
|
sec = sec - min * 60u; // seconds past minute
|
||||||
|
snprintf(buf, sizeof buf, "%3u:%02u.%02u", min, sec, wee);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// won't fit in MMM:SS.XX format
|
||||||
|
sec = sec - min * 60u; // seconds past minute
|
||||||
|
hr = min / 60u; // total hours
|
||||||
|
min = min - hr * 60u; // min past the hour
|
||||||
|
if(hr < 48){
|
||||||
|
snprintf(buf, sizeof buf, "%3u:%02u:%02u", hr, min, sec);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
day = hr / 24u; // total days
|
||||||
|
hr = hr - day * 24u; // hours past the day
|
||||||
|
snprintf(buf, sizeof buf, "%3u-%02u:%02u", day, hr, min);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Calculate and the elapsed time since the last update along with the
|
* Calculate and the elapsed time since the last update along with the
|
||||||
* scaling factor used in multiplication (vs. division) when calculating
|
* scaling factor used in multiplication (vs. division) when calculating
|
||||||
@ -2044,13 +2083,20 @@ static void show_a_task (WIN_t *q, proc_t *task)
|
|||||||
, scale_num(PAGES_2K(task->size - task->resident), w, s));
|
, scale_num(PAGES_2K(task->size - task->resident), w, s));
|
||||||
break;
|
break;
|
||||||
case P_TME:
|
case P_TME:
|
||||||
case P_TM2:
|
|
||||||
{ TICS_t t;
|
{ TICS_t t;
|
||||||
|
|
||||||
t = task->utime + task->stime;
|
t = task->utime + task->stime;
|
||||||
if (CHKw(q, Show_CTIMES))
|
if (CHKw(q, Show_CTIMES))
|
||||||
t += (task->cutime + task->cstime);
|
t += (task->cutime + task->cstime);
|
||||||
MKCOL(q, i, a, &pad, cbuf, scale_tics(t, w));
|
MKCOL(q, i, a, &pad, cbuf, scale_tics(t, w));
|
||||||
|
}
|
||||||
|
case P_TM2:
|
||||||
|
{ TICS_t t;
|
||||||
|
|
||||||
|
t = task->utime + task->stime;
|
||||||
|
if (CHKw(q, Show_CTIMES))
|
||||||
|
t += (task->cutime + task->cstime);
|
||||||
|
MKCOL(q, i, a, &pad, cbuf, format_interval_wide(t));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case P_TTY:
|
case P_TTY:
|
||||||
|
Loading…
Reference in New Issue
Block a user