[SIGAR-19] change process cpu time units to milliseconds
This commit is contained in:
parent
4e45608ce0
commit
795fa1ae44
|
@ -52,7 +52,7 @@ public class ProcCpu extends ProcTime {
|
|||
ptable.put(cpu, cpu);
|
||||
}
|
||||
|
||||
long timeNow = System.currentTimeMillis() / 1000; //seconds
|
||||
long timeNow = System.currentTimeMillis();
|
||||
double diff = timeNow - cpu.lastTime;
|
||||
if (diff == 0) {
|
||||
return cpu; //we were just called within < 1 second ago.
|
||||
|
|
|
@ -149,7 +149,7 @@ public class Ps extends SigarCommandBase {
|
|||
}
|
||||
|
||||
public static String getCpuTime(ProcTime time) {
|
||||
long t = time.getTotal();
|
||||
long t = time.getTotal() / 1000;
|
||||
return t/60 + ":" + t%60;
|
||||
}
|
||||
|
||||
|
|
|
@ -100,12 +100,17 @@
|
|||
#define strnEQ(s1, s2, n) (strncmp(s1, s2, n) == 0)
|
||||
#endif
|
||||
|
||||
#define SIGAR_MSEC 1000L
|
||||
|
||||
#define SIGAR_SEC2NANO(s) \
|
||||
((sigar_uint64_t)(s) * (sigar_uint64_t)1000000000)
|
||||
|
||||
/* cpu ticks to seconds */
|
||||
#define SIGAR_TICK2SEC(s) ((s) / sigar->ticks)
|
||||
|
||||
/* cpu ticks to milliseconds */
|
||||
#define SIGAR_TICK2MSEC(s) ((s) * (SIGAR_MSEC / sigar->ticks))
|
||||
|
||||
#define IFTYPE_LO 2
|
||||
#define IFTYPE_ETH 3
|
||||
|
||||
|
|
|
@ -1082,9 +1082,9 @@ int sigar_proc_time_get(sigar_t *sigar, sigar_pid_t pid,
|
|||
}
|
||||
|
||||
proctime->start_time = pinfo->pi_start;
|
||||
proctime->start_time *= 1000; /* convert to ms */
|
||||
proctime->user = pinfo->pi_utime;
|
||||
proctime->sys = pinfo->pi_stime;
|
||||
proctime->start_time *= SIGAR_MSEC; /* convert to ms */
|
||||
proctime->user = pinfo->pi_utime * SIGAR_MSEC;
|
||||
proctime->sys = pinfo->pi_stime * SIGAR_MSEC;
|
||||
proctime->total = proctime->user + proctime->sys;
|
||||
|
||||
return SIGAR_OK;
|
||||
|
|
|
@ -332,9 +332,9 @@ int sigar_proc_time_get(sigar_t *sigar, sigar_pid_t pid,
|
|||
}
|
||||
|
||||
proctime->start_time = pinfo->pst_start;
|
||||
proctime->start_time *= 1000;
|
||||
proctime->user = pinfo->pst_utime;
|
||||
proctime->sys = pinfo->pst_stime;
|
||||
proctime->start_time *= SIGAR_MSEC;
|
||||
proctime->user = pinfo->pst_utime * SIGAR_MSEC;
|
||||
proctime->sys = pinfo->pst_stime * SIGAR_MSEC;
|
||||
proctime->total = proctime->user + proctime->sys;
|
||||
|
||||
return SIGAR_OK;
|
||||
|
|
|
@ -720,8 +720,8 @@ static int proc_stat_read(sigar_t *sigar, sigar_pid_t pid)
|
|||
pstat->major_faults = sigar_strtoull(ptr); /* (12) */
|
||||
ptr = sigar_skip_token(ptr); /* (13) cmaj flt */
|
||||
|
||||
pstat->utime = sigar_strtoull(ptr) / sigar->ticks; /* (14) */
|
||||
pstat->stime = sigar_strtoull(ptr) / sigar->ticks; /* (15) */
|
||||
pstat->utime = SIGAR_TICK2MSEC(sigar_strtoull(ptr)); /* (14) */
|
||||
pstat->stime = SIGAR_TICK2MSEC(sigar_strtoull(ptr)); /* (15) */
|
||||
|
||||
ptr = sigar_skip_token(ptr); /* (16) cutime */
|
||||
ptr = sigar_skip_token(ptr); /* (17) cstime */
|
||||
|
|
|
@ -681,8 +681,8 @@ int sigar_proc_cred_get(sigar_t *sigar, sigar_pid_t pid,
|
|||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
#define PRTIME_2SIGAR(t) \
|
||||
(t.tv_sec + t.tv_nsec / NANOSEC)
|
||||
#define PRTIME_2MSEC(t) \
|
||||
((t.tv_sec * MILLISEC) + (t.tv_nsec / (NANOSEC/MILLISEC)))
|
||||
|
||||
int sigar_proc_time_get(sigar_t *sigar, sigar_pid_t pid,
|
||||
sigar_proc_time_t *proctime)
|
||||
|
@ -695,7 +695,7 @@ int sigar_proc_time_get(sigar_t *sigar, sigar_pid_t pid,
|
|||
}
|
||||
|
||||
proctime->start_time = usage.pr_create.tv_sec + sigar->boot_time;
|
||||
proctime->start_time *= 1000;
|
||||
proctime->start_time *= MILLISEC;
|
||||
|
||||
if (usage.pr_utime.tv_sec < 0) {
|
||||
/* XXX wtf? seen on solaris 10, only for the self process */
|
||||
|
@ -712,8 +712,8 @@ int sigar_proc_time_get(sigar_t *sigar, sigar_pid_t pid,
|
|||
usage.pr_stime.tv_nsec = pstatus.pr_stime.tv_nsec;
|
||||
}
|
||||
|
||||
proctime->user = PRTIME_2SIGAR(usage.pr_utime);
|
||||
proctime->sys = PRTIME_2SIGAR(usage.pr_stime);
|
||||
proctime->user = PRTIME_2MSEC(usage.pr_utime);
|
||||
proctime->sys = PRTIME_2MSEC(usage.pr_stime);
|
||||
proctime->total = proctime->user + proctime->sys;
|
||||
|
||||
return SIGAR_OK;
|
||||
|
|
Loading…
Reference in New Issue