maintain 'last' Cpu pointers in the getCpuPerc methods rather than the getCpu
methods.
This commit is contained in:
parent
b8a3cde988
commit
848dcc5093
|
@ -203,7 +203,7 @@ public class Sigar implements SigarProxy {
|
||||||
* @exception SigarException on failure.
|
* @exception SigarException on failure.
|
||||||
*/
|
*/
|
||||||
public Cpu getCpu() throws SigarException {
|
public Cpu getCpu() throws SigarException {
|
||||||
return (this.lastCpu = Cpu.fetch(this));
|
return Cpu.fetch(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pause(int millis) {
|
static void pause(int millis) {
|
||||||
|
@ -221,18 +221,19 @@ public class Sigar implements SigarProxy {
|
||||||
* @exception SigarException on failure.
|
* @exception SigarException on failure.
|
||||||
*/
|
*/
|
||||||
public CpuPerc getCpuPerc() throws SigarException {
|
public CpuPerc getCpuPerc() throws SigarException {
|
||||||
Cpu oldCpu, curCpu;
|
Cpu oldCpu;
|
||||||
|
|
||||||
if (this.lastCpu == null){
|
if (this.lastCpu == null){
|
||||||
oldCpu = this.getCpu();
|
oldCpu = getCpu();
|
||||||
pause();
|
pause();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
oldCpu = this.lastCpu;
|
oldCpu = this.lastCpu;
|
||||||
}
|
}
|
||||||
|
|
||||||
curCpu = this.getCpu();
|
this.lastCpu = getCpu();
|
||||||
return CpuPerc.calculate(oldCpu, curCpu);
|
|
||||||
|
return CpuPerc.calculate(oldCpu, this.lastCpu);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -240,7 +241,7 @@ public class Sigar implements SigarProxy {
|
||||||
* @exception SigarException on failure.
|
* @exception SigarException on failure.
|
||||||
*/
|
*/
|
||||||
public CpuPerc[] getCpuPercList() throws SigarException {
|
public CpuPerc[] getCpuPercList() throws SigarException {
|
||||||
Cpu[] oldCpuList, curCpuList;
|
Cpu[] oldCpuList;
|
||||||
|
|
||||||
if (this.lastCpuList == null){
|
if (this.lastCpuList == null){
|
||||||
oldCpuList = getCpuList();
|
oldCpuList = getCpuList();
|
||||||
|
@ -250,18 +251,18 @@ public class Sigar implements SigarProxy {
|
||||||
oldCpuList = this.lastCpuList;
|
oldCpuList = this.lastCpuList;
|
||||||
}
|
}
|
||||||
|
|
||||||
curCpuList = getCpuList();
|
this.lastCpuList = getCpuList();
|
||||||
|
|
||||||
int curLen = curCpuList.length, oldLen = oldCpuList.length;
|
int curLen = this.lastCpuList.length;
|
||||||
|
int oldLen = oldCpuList.length;
|
||||||
|
|
||||||
CpuPerc[] perc = new CpuPerc[curLen < oldLen ? curLen : oldLen];
|
CpuPerc[] perc =
|
||||||
|
new CpuPerc[curLen < oldLen ? curLen : oldLen];
|
||||||
|
|
||||||
for (int i=0; i<curCpuList.length; i++) {
|
for (int i=0; i<curLen; i++) {
|
||||||
Cpu curCpu = curCpuList[i], oldCpu;
|
perc[i] =
|
||||||
|
CpuPerc.calculate(oldCpuList[i],
|
||||||
oldCpu = oldCpuList[i];
|
this.lastCpuList[i]);
|
||||||
|
|
||||||
perc[i] = CpuPerc.calculate(oldCpu, curCpu);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return perc;
|
return perc;
|
||||||
|
@ -621,7 +622,7 @@ public class Sigar implements SigarProxy {
|
||||||
* @exception SigarException on failure.
|
* @exception SigarException on failure.
|
||||||
*/
|
*/
|
||||||
public Cpu[] getCpuList() throws SigarException {
|
public Cpu[] getCpuList() throws SigarException {
|
||||||
return (this.lastCpuList = getCpuListNative());
|
return getCpuListNative();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue