add LastSampleTime
This commit is contained in:
parent
60c864fd55
commit
421f3b4dc5
|
@ -32,7 +32,7 @@ public class CpuTimer implements CpuTimerMBean {
|
||||||
|
|
||||||
private ThreadCpu cpu = new ThreadCpu();
|
private ThreadCpu cpu = new ThreadCpu();
|
||||||
|
|
||||||
private long startTime;
|
private long startTime, stopTime;
|
||||||
|
|
||||||
public CpuTimer() {
|
public CpuTimer() {
|
||||||
this(null);
|
this(null);
|
||||||
|
@ -44,6 +44,8 @@ public class CpuTimer implements CpuTimerMBean {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
|
this.startTime = -1;
|
||||||
|
this.stopTime = -1;
|
||||||
this.totalTime = 0;
|
this.totalTime = 0;
|
||||||
this.cpuTotal = 0;
|
this.cpuTotal = 0;
|
||||||
this.cpuUser = 0;
|
this.cpuUser = 0;
|
||||||
|
@ -83,9 +85,9 @@ public class CpuTimer implements CpuTimerMBean {
|
||||||
this.cpuUser += diff.user;
|
this.cpuUser += diff.user;
|
||||||
this.cpuSys += diff.sys;
|
this.cpuSys += diff.sys;
|
||||||
|
|
||||||
long timeNow = System.currentTimeMillis();
|
this.stopTime = System.currentTimeMillis();
|
||||||
|
|
||||||
double timeDiff = timeNow - this.startTime;
|
double timeDiff = this.stopTime - this.startTime;
|
||||||
|
|
||||||
this.totalTime += timeDiff;
|
this.totalTime += timeDiff;
|
||||||
|
|
||||||
|
@ -140,6 +142,10 @@ public class CpuTimer implements CpuTimerMBean {
|
||||||
return this.cpuPercent;
|
return this.cpuPercent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getLastSampleTime() {
|
||||||
|
return this.stopTime;
|
||||||
|
}
|
||||||
|
|
||||||
public String format(long elap) {
|
public String format(long elap) {
|
||||||
String fraction = (elap % 1000) + "";
|
String fraction = (elap % 1000) + "";
|
||||||
int pad = 3 - fraction.length();
|
int pad = 3 - fraction.length();
|
||||||
|
|
|
@ -29,4 +29,6 @@ public interface CpuTimerMBean {
|
||||||
public double getCpuUsage();
|
public double getCpuUsage();
|
||||||
|
|
||||||
public long getTotalTime();
|
public long getTotalTime();
|
||||||
|
|
||||||
|
public long getLastSampleTime();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue