collect over multiple stop/start
This commit is contained in:
parent
2ad2c33bbf
commit
90ad5a74f2
|
@ -18,15 +18,19 @@ public class CpuTimer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public CpuTimer(Sigar sigar) {
|
public CpuTimer(Sigar sigar) {
|
||||||
|
clear();
|
||||||
this.sigar = sigar;
|
this.sigar = sigar;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start() {
|
public void clear() {
|
||||||
this.startTime = System.currentTimeMillis();
|
|
||||||
this.totalTime = 0;
|
this.totalTime = 0;
|
||||||
this.cpuTotal = 0;
|
this.cpuTotal = 0;
|
||||||
this.cpuUser = 0;
|
this.cpuUser = 0;
|
||||||
this.cpuSys = 0;
|
this.cpuSys = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void start() {
|
||||||
|
this.startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.cpu.gather(this.sigar, 0);
|
this.cpu.gather(this.sigar, 0);
|
||||||
|
@ -38,15 +42,15 @@ public class CpuTimer {
|
||||||
public void stop() {
|
public void stop() {
|
||||||
ThreadCpu diff = getDiff();
|
ThreadCpu diff = getDiff();
|
||||||
|
|
||||||
this.cpuTotal = diff.total;
|
this.cpuTotal += diff.total;
|
||||||
this.cpuUser = diff.user;
|
this.cpuUser += diff.user;
|
||||||
this.cpuSys = diff.sys;
|
this.cpuSys += diff.sys;
|
||||||
|
|
||||||
long stopTime = System.currentTimeMillis();
|
long stopTime = System.currentTimeMillis();
|
||||||
|
|
||||||
long time = stopTime - this.startTime;
|
long time = stopTime - this.startTime;
|
||||||
|
|
||||||
this.totalTime = time;
|
this.totalTime += time;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ThreadCpu getDiff() {
|
public ThreadCpu getDiff() {
|
||||||
|
|
Loading…
Reference in New Issue