From 606275fc36644d8cd73a588296c73141a4c4df36 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Sat, 21 Aug 2004 00:13:13 +0000 Subject: [PATCH] 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. --- bindings/java/src/jni/generate.pl | 8 ++++---- bindings/java/src/net/hyperic/sigar/ProcCpu.java | 4 ++-- bindings/java/src/net/hyperic/sigar/SigarInvoker.java | 7 +++++++ bindings/java/src/net/hyperic/sigar/cmd/Ps.java | 8 +++++++- bindings/java/src/net/hyperic/sigar/jmx/SigarProcess.java | 4 ++-- bindings/java/src/net/hyperic/sigar/test/TestInvoker.java | 5 ++++- bindings/java/src/net/hyperic/sigar/test/TestPTQL.java | 4 ++-- .../java/src/net/hyperic/sigar/test/TestProcTime.java | 4 ++-- include/sigar.h | 4 ++-- src/os/aix/aix_sigar.c | 4 ++-- src/os/darwin/darwin_sigar.c | 4 ++-- src/os/hpux/hpux_sigar.c | 4 ++-- src/os/linux/linux_sigar.c | 4 ++-- src/os/solaris/solaris_sigar.c | 4 ++-- src/os/stub/stub_sigar.c | 4 ++-- src/os/win32/win32_sigar.c | 4 ++-- 16 files changed, 46 insertions(+), 30 deletions(-) diff --git a/bindings/java/src/jni/generate.pl b/bindings/java/src/jni/generate.pl index 7e81168d..f8206966 100644 --- a/bindings/java/src/jni/generate.pl +++ b/bindings/java/src/jni/generate.pl @@ -269,14 +269,14 @@ my %classes = ( plat => 'ADHLSW' }, { - name => 'utime', type => 'Long', + name => 'user', type => 'Long', desc => 'Process cpu user time', - plat => 'AHLSW' + plat => 'ADHLSW' }, { - name => 'stime', type => 'Long', + name => 'sys', type => 'Long', desc => 'Process cpu kernel time', - plat => 'AHLSW' + plat => 'ADHLSW' }, ], ProcState => [ diff --git a/bindings/java/src/net/hyperic/sigar/ProcCpu.java b/bindings/java/src/net/hyperic/sigar/ProcCpu.java index 4e6a42e4..4f7f4d93 100644 --- a/bindings/java/src/net/hyperic/sigar/ProcCpu.java +++ b/bindings/java/src/net/hyperic/sigar/ProcCpu.java @@ -19,7 +19,7 @@ public class ProcCpu extends ProcTime { private void getValues(Sigar sigar, long pid) throws SigarException { this.nativeGet(sigar, pid); - this.time = this.utime + this.stime; + this.time = this.user + this.sys; } 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() { return this.time; diff --git a/bindings/java/src/net/hyperic/sigar/SigarInvoker.java b/bindings/java/src/net/hyperic/sigar/SigarInvoker.java index e4ba0f37..e6ff5a46 100644 --- a/bindings/java/src/net/hyperic/sigar/SigarInvoker.java +++ b/bindings/java/src/net/hyperic/sigar/SigarInvoker.java @@ -16,6 +16,7 @@ public class SigarInvoker { private static HashMap attrCache = new HashMap(); private static HashMap compatTypes = new HashMap(); + private static HashMap compatAttrs = new HashMap(); static { //XXX backwards compat for HQ because metric template @@ -23,6 +24,8 @@ public class SigarInvoker { compatTypes.put("NetIfconfig", "NetInterfaceConfig"); compatTypes.put("NetIfstat", "NetInterfaceStat"); compatTypes.put("DirStats", "DirStat"); + compatAttrs.put("Utime", "User"); + compatAttrs.put("Stime", "Sys"); } //avoid object creation as much as possible @@ -279,6 +282,10 @@ public class SigarInvoker { private Method getAttributeMethod(String attr) throws SigarException { + String alias = (String)compatAttrs.get(attr); + if (alias != null) { + attr = alias; + } Method attrMethod; Class type = getTypeMethod(null).getReturnType(); diff --git a/bindings/java/src/net/hyperic/sigar/cmd/Ps.java b/bindings/java/src/net/hyperic/sigar/cmd/Ps.java index 402a1190..a96fb022 100644 --- a/bindings/java/src/net/hyperic/sigar/cmd/Ps.java +++ b/bindings/java/src/net/hyperic/sigar/cmd/Ps.java @@ -148,6 +148,12 @@ public class Ps extends SigarCommandBase { } catch (SigarException e) {} } + else { + try { + String[] args = sigar.getProcArgs(pid); + name = args[0]; + } catch (SigarException e) {} + } info.add(name); @@ -159,7 +165,7 @@ public class Ps extends SigarCommandBase { } private static String getCpuTime(ProcTime time) { - long t = (time.getUtime() + time.getStime()); + long t = (time.getUser() + time.getSys()); return t/60 + ":" + t%60; } diff --git a/bindings/java/src/net/hyperic/sigar/jmx/SigarProcess.java b/bindings/java/src/net/hyperic/sigar/jmx/SigarProcess.java index 3a44d52f..174ca364 100644 --- a/bindings/java/src/net/hyperic/sigar/jmx/SigarProcess.java +++ b/bindings/java/src/net/hyperic/sigar/jmx/SigarProcess.java @@ -62,10 +62,10 @@ public class SigarProcess implements SigarProcessMBean { } public Long getTimeUser() { - return getLongValue(procTime, "Utime"); + return getLongValue(procTime, "User"); } public Long getTimeSys() { - return getLongValue(procTime, "Stime"); + return getLongValue(procTime, "Sys"); } } diff --git a/bindings/java/src/net/hyperic/sigar/test/TestInvoker.java b/bindings/java/src/net/hyperic/sigar/test/TestInvoker.java index 92b17bac..c7945c9a 100644 --- a/bindings/java/src/net/hyperic/sigar/test/TestInvoker.java +++ b/bindings/java/src/net/hyperic/sigar/test/TestInvoker.java @@ -24,6 +24,9 @@ public class TestInvoker extends SigarTestCase { { "sigar:Type=LoadAverage", "2" }, { "sigar:Type=ProcMem,Arg=$$", "Size" }, { "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=$$", "Utime" }, { "sigar:Type=CpuPercList,Arg=0", "Idle" }, @@ -32,7 +35,7 @@ public class TestInvoker extends SigarTestCase { private static final String[][] BROKEN_QUERIES = { { "sigar:Type=BREAK", "Free" }, { "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=BREAK", "Idle" }, }; diff --git a/bindings/java/src/net/hyperic/sigar/test/TestPTQL.java b/bindings/java/src/net/hyperic/sigar/test/TestPTQL.java index 2d7303db..37daf67d 100644 --- a/bindings/java/src/net/hyperic/sigar/test/TestPTQL.java +++ b/bindings/java/src/net/hyperic/sigar/test/TestPTQL.java @@ -28,7 +28,7 @@ public class TestPTQL extends SigarTestCase { "Cred.Uid.gt=0,Cred.Uid.lt=1000", //range of users "Cred.Uid.eq=1003,Cred.Gid.eq=1003", //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 "Mem.Size.ge=10000000,Mem.Share.le=1000000", //memory hog "State.Name.eq=sshd,Cred.Uid.eq=0", @@ -60,7 +60,7 @@ public class TestPTQL extends SigarTestCase { "State.Name.eq=$2", "State.State.eq=read", "Args.x.eq=foo", - "Time.Stime.gt=x", + "Time.Sys.gt=x", "Pid.PidFile.ne=pid.file", "Pid.Pid.eq=foo", "Pid.Service.ne=Eventlog", diff --git a/bindings/java/src/net/hyperic/sigar/test/TestProcTime.java b/bindings/java/src/net/hyperic/sigar/test/TestProcTime.java index 6977ad2d..0be229f7 100644 --- a/bindings/java/src/net/hyperic/sigar/test/TestProcTime.java +++ b/bindings/java/src/net/hyperic/sigar/test/TestProcTime.java @@ -24,8 +24,8 @@ public class TestProcTime extends SigarTestCase { //XXX //assertTrue(procTime.getStartTime() < System.currentTimeMillis()); - assertGtEqZeroTrace("Utime", procTime.getUtime()); + assertGtEqZeroTrace("User", procTime.getUser()); - assertGtEqZeroTrace("Stime", procTime.getStime()); + assertGtEqZeroTrace("Sys", procTime.getSys()); } } diff --git a/include/sigar.h b/include/sigar.h index a93d9a61..4439b34c 100644 --- a/include/sigar.h +++ b/include/sigar.h @@ -209,8 +209,8 @@ sigar_proc_cred_name_get(sigar_t *sigar, sigar_pid_t pid, typedef struct { sigar_uint64_t start_time, - utime, - stime; + user, + sys; } sigar_proc_time_t; SIGAR_DECLARE(int) sigar_proc_time_get(sigar_t *sigar, sigar_pid_t pid, diff --git a/src/os/aix/aix_sigar.c b/src/os/aix/aix_sigar.c index bfdc55c2..d3416fa3 100644 --- a/src/os/aix/aix_sigar.c +++ b/src/os/aix/aix_sigar.c @@ -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 *= 1000; /* convert to ms */ - proctime->utime = pinfo->pi_utime; - proctime->stime = pinfo->pi_stime; + proctime->user = pinfo->pi_utime; + proctime->sys = pinfo->pi_stime; return SIGAR_OK; } diff --git a/src/os/darwin/darwin_sigar.c b/src/os/darwin/darwin_sigar.c index 03a6f916..39f90bad 100644 --- a/src/os/darwin/darwin_sigar.c +++ b/src/os/darwin/darwin_sigar.c @@ -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(&stime, &tti.system_time); - time->utime = utime.seconds; - time->stime = stime.seconds; + time->user = utime.seconds; + time->sys = stime.seconds; return SIGAR_OK; } diff --git a/src/os/hpux/hpux_sigar.c b/src/os/hpux/hpux_sigar.c index ab155776..e18cd389 100644 --- a/src/os/hpux/hpux_sigar.c +++ b/src/os/hpux/hpux_sigar.c @@ -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 *= 1000; - proctime->utime = pinfo->pst_utime; - proctime->stime = pinfo->pst_stime; + proctime->user = pinfo->pst_utime; + proctime->sys = pinfo->pst_stime; return SIGAR_OK; } diff --git a/src/os/linux/linux_sigar.c b/src/os/linux/linux_sigar.c index 9cb2b755..0902afc1 100644 --- a/src/os/linux/linux_sigar.c +++ b/src/os/linux/linux_sigar.c @@ -637,8 +637,8 @@ int sigar_proc_time_get(sigar_t *sigar, sigar_pid_t pid, return status; } - proctime->utime = pstat->utime; - proctime->stime = pstat->stime; + proctime->user = pstat->utime; + proctime->sys = pstat->stime; proctime->start_time = pstat->start_time; return SIGAR_OK; diff --git a/src/os/solaris/solaris_sigar.c b/src/os/solaris/solaris_sigar.c index 68242828..b9a86661 100644 --- a/src/os/solaris/solaris_sigar.c +++ b/src/os/solaris/solaris_sigar.c @@ -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 *= 1000; - proctime->utime = PRTIME_2SIGAR(usage.pr_utime); - proctime->stime = PRTIME_2SIGAR(usage.pr_stime); + proctime->user = PRTIME_2SIGAR(usage.pr_utime); + proctime->sys = PRTIME_2SIGAR(usage.pr_stime); return SIGAR_OK; } diff --git a/src/os/stub/stub_sigar.c b/src/os/stub/stub_sigar.c index fecc42fa..d96509be 100644 --- a/src/os/stub/stub_sigar.c +++ b/src/os/stub/stub_sigar.c @@ -119,8 +119,8 @@ int sigar_proc_time_get(sigar_t *sigar, sigar_pid_t pid, sigar_proc_time_t *proctime) { proctime->start_time = -1; - proctime->utime = -1; - proctime->stime = -1; + proctime->user = -1; + proctime->sys = -1; return SIGAR_OK; } diff --git a/src/os/win32/win32_sigar.c b/src/os/win32/win32_sigar.c index ce404de3..0e24e70a 100644 --- a/src/os/win32/win32_sigar.c +++ b/src/os/win32/win32_sigar.c @@ -645,8 +645,8 @@ SIGAR_DECLARE(int) sigar_proc_time_get(sigar_t *sigar, sigar_pid_t pid, proctime->start_time = 0; } - proctime->utime = FILETIME2SEC(user_time); - proctime->stime = FILETIME2SEC(system_time); + proctime->user = FILETIME2SEC(user_time); + proctime->sys = FILETIME2SEC(system_time); return SIGAR_OK; }