From df88ea5bb4b1a135e5281603ed516a5de7fc0102 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Mon, 22 Nov 2004 02:05:07 +0000 Subject: [PATCH] add cpu wait --- bindings/java/src/net/hyperic/sigar/CpuPerc.java | 16 ++++++++++++++-- .../java/src/net/hyperic/sigar/cmd/CpuInfo.java | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/bindings/java/src/net/hyperic/sigar/CpuPerc.java b/bindings/java/src/net/hyperic/sigar/CpuPerc.java index fc81755c..6fbfb950 100644 --- a/bindings/java/src/net/hyperic/sigar/CpuPerc.java +++ b/bindings/java/src/net/hyperic/sigar/CpuPerc.java @@ -8,16 +8,18 @@ public class CpuPerc { private double sys; private double nice; private double idle; + private double wait; CpuPerc(){ } static CpuPerc calculate(Cpu oldCpu, Cpu curCpu) { - double diffUser, diffSys, diffNice, diffIdle, diffTotal; + double diffUser, diffSys, diffNice, diffIdle, diffWait, diffTotal; diffUser = curCpu.getUser() - oldCpu.getUser(); diffSys = curCpu.getSys() - oldCpu.getSys(); diffNice = curCpu.getNice() - oldCpu.getNice(); diffIdle = curCpu.getIdle() - oldCpu.getIdle(); + diffWait = curCpu.getWait() - oldCpu.getWait(); // Sanity check -- sometimes these values waiver in between // whole numbers when Cpu is checked very rapidly @@ -25,14 +27,16 @@ public class CpuPerc { diffSys = diffSys < 0 ? 0 : diffSys; diffNice = diffNice < 0 ? 0 : diffNice; diffIdle = diffIdle < 0 ? 0 : diffIdle; + diffWait = diffWait < 0 ? 0 : diffWait; - diffTotal = diffUser + diffSys + diffNice + diffIdle; + diffTotal = diffUser + diffSys + diffNice + diffIdle + diffWait; CpuPerc perc = new CpuPerc(); perc.setUser(diffUser / diffTotal); perc.setSys(diffSys / diffTotal); perc.setNice(diffNice / diffTotal); perc.setIdle(diffIdle / diffTotal); + perc.setWait(diffWait / diffTotal); return perc; } @@ -68,6 +72,14 @@ public class CpuPerc { this.idle = idle; } + public double getWait(){ + return this.wait; + } + + void setWait(double wait){ + this.wait = wait; + } + public double getCombined() { return this.user + this.sys; } diff --git a/bindings/java/src/net/hyperic/sigar/cmd/CpuInfo.java b/bindings/java/src/net/hyperic/sigar/cmd/CpuInfo.java index 7ec745e7..305392ea 100644 --- a/bindings/java/src/net/hyperic/sigar/cmd/CpuInfo.java +++ b/bindings/java/src/net/hyperic/sigar/cmd/CpuInfo.java @@ -38,6 +38,7 @@ public class CpuInfo extends SigarCommandBase { println("User Time....." + CpuPerc.format(cpu.getUser())); println("Sys Time......" + CpuPerc.format(cpu.getSys())); println("Idle Time....." + CpuPerc.format(cpu.getIdle())); + println("Wait Time....." + CpuPerc.format(cpu.getWait())); println(""); } }