add cpu wait

This commit is contained in:
Doug MacEachern 2004-11-22 02:05:07 +00:00
parent 81a39ee55e
commit df88ea5bb4
2 changed files with 15 additions and 2 deletions

View File

@ -8,16 +8,18 @@ public class CpuPerc {
private double sys; private double sys;
private double nice; private double nice;
private double idle; private double idle;
private double wait;
CpuPerc(){ } CpuPerc(){ }
static CpuPerc calculate(Cpu oldCpu, Cpu curCpu) { 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(); diffUser = curCpu.getUser() - oldCpu.getUser();
diffSys = curCpu.getSys() - oldCpu.getSys(); diffSys = curCpu.getSys() - oldCpu.getSys();
diffNice = curCpu.getNice() - oldCpu.getNice(); diffNice = curCpu.getNice() - oldCpu.getNice();
diffIdle = curCpu.getIdle() - oldCpu.getIdle(); diffIdle = curCpu.getIdle() - oldCpu.getIdle();
diffWait = curCpu.getWait() - oldCpu.getWait();
// Sanity check -- sometimes these values waiver in between // Sanity check -- sometimes these values waiver in between
// whole numbers when Cpu is checked very rapidly // whole numbers when Cpu is checked very rapidly
@ -25,14 +27,16 @@ public class CpuPerc {
diffSys = diffSys < 0 ? 0 : diffSys; diffSys = diffSys < 0 ? 0 : diffSys;
diffNice = diffNice < 0 ? 0 : diffNice; diffNice = diffNice < 0 ? 0 : diffNice;
diffIdle = diffIdle < 0 ? 0 : diffIdle; 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(); CpuPerc perc = new CpuPerc();
perc.setUser(diffUser / diffTotal); perc.setUser(diffUser / diffTotal);
perc.setSys(diffSys / diffTotal); perc.setSys(diffSys / diffTotal);
perc.setNice(diffNice / diffTotal); perc.setNice(diffNice / diffTotal);
perc.setIdle(diffIdle / diffTotal); perc.setIdle(diffIdle / diffTotal);
perc.setWait(diffWait / diffTotal);
return perc; return perc;
} }
@ -68,6 +72,14 @@ public class CpuPerc {
this.idle = idle; this.idle = idle;
} }
public double getWait(){
return this.wait;
}
void setWait(double wait){
this.wait = wait;
}
public double getCombined() { public double getCombined() {
return this.user + this.sys; return this.user + this.sys;
} }

View File

@ -38,6 +38,7 @@ public class CpuInfo extends SigarCommandBase {
println("User Time....." + CpuPerc.format(cpu.getUser())); println("User Time....." + CpuPerc.format(cpu.getUser()));
println("Sys Time......" + CpuPerc.format(cpu.getSys())); println("Sys Time......" + CpuPerc.format(cpu.getSys()));
println("Idle Time....." + CpuPerc.format(cpu.getIdle())); println("Idle Time....." + CpuPerc.format(cpu.getIdle()));
println("Wait Time....." + CpuPerc.format(cpu.getWait()));
println(""); println("");
} }
} }