renaming proc_time.{utime,stime} to proc_time.{user,sys}

'utime' and 'stime' are common within system structures, but with lots of
other stuff in the structure unrelated to time.  having 'time' in both the
structure/class name and the field at the sigar level is just lame.
This commit is contained in:
Doug MacEachern 2004-08-21 00:13:13 +00:00
parent 641253b359
commit 606275fc36
16 changed files with 46 additions and 30 deletions

View File

@ -269,14 +269,14 @@ my %classes = (
plat => 'ADHLSW' plat => 'ADHLSW'
}, },
{ {
name => 'utime', type => 'Long', name => 'user', type => 'Long',
desc => 'Process cpu user time', desc => 'Process cpu user time',
plat => 'AHLSW' plat => 'ADHLSW'
}, },
{ {
name => 'stime', type => 'Long', name => 'sys', type => 'Long',
desc => 'Process cpu kernel time', desc => 'Process cpu kernel time',
plat => 'AHLSW' plat => 'ADHLSW'
}, },
], ],
ProcState => [ ProcState => [

View File

@ -19,7 +19,7 @@ public class ProcCpu extends ProcTime {
private void getValues(Sigar sigar, long pid) private void getValues(Sigar sigar, long pid)
throws SigarException { throws SigarException {
this.nativeGet(sigar, pid); this.nativeGet(sigar, pid);
this.time = this.utime + this.stime; this.time = this.user + this.sys;
} }
static synchronized ProcCpu get(Sigar sigar, long pid) static synchronized ProcCpu get(Sigar sigar, long pid)
@ -69,7 +69,7 @@ public class ProcCpu extends ProcTime {
} }
/** /**
* @return Sum of Utime and Stime. * @return Sum of User and Sys.
*/ */
public long getTotal() { public long getTotal() {
return this.time; return this.time;

View File

@ -16,6 +16,7 @@ public class SigarInvoker {
private static HashMap attrCache = new HashMap(); private static HashMap attrCache = new HashMap();
private static HashMap compatTypes = new HashMap(); private static HashMap compatTypes = new HashMap();
private static HashMap compatAttrs = new HashMap();
static { static {
//XXX backwards compat for HQ because metric template //XXX backwards compat for HQ because metric template
@ -23,6 +24,8 @@ public class SigarInvoker {
compatTypes.put("NetIfconfig", "NetInterfaceConfig"); compatTypes.put("NetIfconfig", "NetInterfaceConfig");
compatTypes.put("NetIfstat", "NetInterfaceStat"); compatTypes.put("NetIfstat", "NetInterfaceStat");
compatTypes.put("DirStats", "DirStat"); compatTypes.put("DirStats", "DirStat");
compatAttrs.put("Utime", "User");
compatAttrs.put("Stime", "Sys");
} }
//avoid object creation as much as possible //avoid object creation as much as possible
@ -279,6 +282,10 @@ public class SigarInvoker {
private Method getAttributeMethod(String attr) private Method getAttributeMethod(String attr)
throws SigarException { throws SigarException {
String alias = (String)compatAttrs.get(attr);
if (alias != null) {
attr = alias;
}
Method attrMethod; Method attrMethod;
Class type = getTypeMethod(null).getReturnType(); Class type = getTypeMethod(null).getReturnType();

View File

@ -148,6 +148,12 @@ public class Ps extends SigarCommandBase {
} catch (SigarException e) {} } catch (SigarException e) {}
} }
else {
try {
String[] args = sigar.getProcArgs(pid);
name = args[0];
} catch (SigarException e) {}
}
info.add(name); info.add(name);
@ -159,7 +165,7 @@ public class Ps extends SigarCommandBase {
} }
private static String getCpuTime(ProcTime time) { private static String getCpuTime(ProcTime time) {
long t = (time.getUtime() + time.getStime()); long t = (time.getUser() + time.getSys());
return t/60 + ":" + t%60; return t/60 + ":" + t%60;
} }

View File

@ -62,10 +62,10 @@ public class SigarProcess implements SigarProcessMBean {
} }
public Long getTimeUser() { public Long getTimeUser() {
return getLongValue(procTime, "Utime"); return getLongValue(procTime, "User");
} }
public Long getTimeSys() { public Long getTimeSys() {
return getLongValue(procTime, "Stime"); return getLongValue(procTime, "Sys");
} }
} }

View File

@ -24,6 +24,9 @@ public class TestInvoker extends SigarTestCase {
{ "sigar:Type=LoadAverage", "2" }, { "sigar:Type=LoadAverage", "2" },
{ "sigar:Type=ProcMem,Arg=$$", "Size" }, { "sigar:Type=ProcMem,Arg=$$", "Size" },
{ "sigar:Type=ProcMem,Arg=$$", "Vsize" }, { "sigar:Type=ProcMem,Arg=$$", "Vsize" },
{ "sigar:Type=ProcTime,Arg=$$", "Sys" },
{ "sigar:Type=ProcTime,Arg=$$", "User" },
//test Utime/Stime backcompat.
{ "sigar:Type=ProcTime,Arg=$$", "Stime" }, { "sigar:Type=ProcTime,Arg=$$", "Stime" },
{ "sigar:Type=ProcTime,Arg=$$", "Utime" }, { "sigar:Type=ProcTime,Arg=$$", "Utime" },
{ "sigar:Type=CpuPercList,Arg=0", "Idle" }, { "sigar:Type=CpuPercList,Arg=0", "Idle" },
@ -32,7 +35,7 @@ public class TestInvoker extends SigarTestCase {
private static final String[][] BROKEN_QUERIES = { private static final String[][] BROKEN_QUERIES = {
{ "sigar:Type=BREAK", "Free" }, { "sigar:Type=BREAK", "Free" },
{ "sigar:Type=Mem", "BREAK" }, { "sigar:Type=Mem", "BREAK" },
{ "sigar:Type=ProcTime,Arg=BREAK", "Stime" }, { "sigar:Type=ProcTime,Arg=BREAK", "Sys" },
{ "sigar:Type=CpuPercList,Arg=1000", "Idle" }, { "sigar:Type=CpuPercList,Arg=1000", "Idle" },
{ "sigar:Type=CpuPercList,Arg=BREAK", "Idle" }, { "sigar:Type=CpuPercList,Arg=BREAK", "Idle" },
}; };

View File

@ -28,7 +28,7 @@ public class TestPTQL extends SigarTestCase {
"Cred.Uid.gt=0,Cred.Uid.lt=1000", //range of users "Cred.Uid.gt=0,Cred.Uid.lt=1000", //range of users
"Cred.Uid.eq=1003,Cred.Gid.eq=1003", //me "Cred.Uid.eq=1003,Cred.Gid.eq=1003", //me
"CredName.User.eq=dougm", //me "CredName.User.eq=dougm", //me
"Time.Stime.gt=1000", //cpu hog "Time.Sys.gt=1000", //cpu hog
"Fd.Total.gt=20", //lots of open files "Fd.Total.gt=20", //lots of open files
"Mem.Size.ge=10000000,Mem.Share.le=1000000", //memory hog "Mem.Size.ge=10000000,Mem.Share.le=1000000", //memory hog
"State.Name.eq=sshd,Cred.Uid.eq=0", "State.Name.eq=sshd,Cred.Uid.eq=0",
@ -60,7 +60,7 @@ public class TestPTQL extends SigarTestCase {
"State.Name.eq=$2", "State.Name.eq=$2",
"State.State.eq=read", "State.State.eq=read",
"Args.x.eq=foo", "Args.x.eq=foo",
"Time.Stime.gt=x", "Time.Sys.gt=x",
"Pid.PidFile.ne=pid.file", "Pid.PidFile.ne=pid.file",
"Pid.Pid.eq=foo", "Pid.Pid.eq=foo",
"Pid.Service.ne=Eventlog", "Pid.Service.ne=Eventlog",

View File

@ -24,8 +24,8 @@ public class TestProcTime extends SigarTestCase {
//XXX //XXX
//assertTrue(procTime.getStartTime() < System.currentTimeMillis()); //assertTrue(procTime.getStartTime() < System.currentTimeMillis());
assertGtEqZeroTrace("Utime", procTime.getUtime()); assertGtEqZeroTrace("User", procTime.getUser());
assertGtEqZeroTrace("Stime", procTime.getStime()); assertGtEqZeroTrace("Sys", procTime.getSys());
} }
} }

View File

@ -209,8 +209,8 @@ sigar_proc_cred_name_get(sigar_t *sigar, sigar_pid_t pid,
typedef struct { typedef struct {
sigar_uint64_t sigar_uint64_t
start_time, start_time,
utime, user,
stime; sys;
} sigar_proc_time_t; } sigar_proc_time_t;
SIGAR_DECLARE(int) sigar_proc_time_get(sigar_t *sigar, sigar_pid_t pid, SIGAR_DECLARE(int) sigar_proc_time_get(sigar_t *sigar, sigar_pid_t pid,

View File

@ -965,8 +965,8 @@ int sigar_proc_time_get(sigar_t *sigar, sigar_pid_t pid,
proctime->start_time = pinfo->pi_start; proctime->start_time = pinfo->pi_start;
proctime->start_time *= 1000; /* convert to ms */ proctime->start_time *= 1000; /* convert to ms */
proctime->utime = pinfo->pi_utime; proctime->user = pinfo->pi_utime;
proctime->stime = pinfo->pi_stime; proctime->sys = pinfo->pi_stime;
return SIGAR_OK; return SIGAR_OK;
} }

View File

@ -420,8 +420,8 @@ static int get_proc_times(sigar_pid_t pid, sigar_proc_time_t *time)
time_value_add(&utime, &tti.user_time); time_value_add(&utime, &tti.user_time);
time_value_add(&stime, &tti.system_time); time_value_add(&stime, &tti.system_time);
time->utime = utime.seconds; time->user = utime.seconds;
time->stime = stime.seconds; time->sys = stime.seconds;
return SIGAR_OK; return SIGAR_OK;
} }

View File

@ -295,8 +295,8 @@ int sigar_proc_time_get(sigar_t *sigar, sigar_pid_t pid,
proctime->start_time = pinfo->pst_start; proctime->start_time = pinfo->pst_start;
proctime->start_time *= 1000; proctime->start_time *= 1000;
proctime->utime = pinfo->pst_utime; proctime->user = pinfo->pst_utime;
proctime->stime = pinfo->pst_stime; proctime->sys = pinfo->pst_stime;
return SIGAR_OK; return SIGAR_OK;
} }

View File

@ -637,8 +637,8 @@ int sigar_proc_time_get(sigar_t *sigar, sigar_pid_t pid,
return status; return status;
} }
proctime->utime = pstat->utime; proctime->user = pstat->utime;
proctime->stime = pstat->stime; proctime->sys = pstat->stime;
proctime->start_time = pstat->start_time; proctime->start_time = pstat->start_time;
return SIGAR_OK; return SIGAR_OK;

View File

@ -582,8 +582,8 @@ 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 = usage.pr_create.tv_sec + sigar->boot_time;
proctime->start_time *= 1000; proctime->start_time *= 1000;
proctime->utime = PRTIME_2SIGAR(usage.pr_utime); proctime->user = PRTIME_2SIGAR(usage.pr_utime);
proctime->stime = PRTIME_2SIGAR(usage.pr_stime); proctime->sys = PRTIME_2SIGAR(usage.pr_stime);
return SIGAR_OK; return SIGAR_OK;
} }

View File

@ -119,8 +119,8 @@ int sigar_proc_time_get(sigar_t *sigar, sigar_pid_t pid,
sigar_proc_time_t *proctime) sigar_proc_time_t *proctime)
{ {
proctime->start_time = -1; proctime->start_time = -1;
proctime->utime = -1; proctime->user = -1;
proctime->stime = -1; proctime->sys = -1;
return SIGAR_OK; return SIGAR_OK;
} }

View File

@ -645,8 +645,8 @@ SIGAR_DECLARE(int) sigar_proc_time_get(sigar_t *sigar, sigar_pid_t pid,
proctime->start_time = 0; proctime->start_time = 0;
} }
proctime->utime = FILETIME2SEC(user_time); proctime->user = FILETIME2SEC(user_time);
proctime->stime = FILETIME2SEC(system_time); proctime->sys = FILETIME2SEC(system_time);
return SIGAR_OK; return SIGAR_OK;
} }