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 long startTime;
 | 
			
		||||
    private long startTime, stopTime;
 | 
			
		||||
 | 
			
		||||
    public CpuTimer() {
 | 
			
		||||
        this(null);
 | 
			
		||||
@ -44,6 +44,8 @@ public class CpuTimer implements CpuTimerMBean {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void clear() {
 | 
			
		||||
        this.startTime = -1;
 | 
			
		||||
        this.stopTime = -1;
 | 
			
		||||
        this.totalTime = 0;
 | 
			
		||||
        this.cpuTotal = 0;
 | 
			
		||||
        this.cpuUser  = 0;
 | 
			
		||||
@ -83,9 +85,9 @@ public class CpuTimer implements CpuTimerMBean {
 | 
			
		||||
        this.cpuUser  += diff.user;
 | 
			
		||||
        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;
 | 
			
		||||
 | 
			
		||||
@ -140,6 +142,10 @@ public class CpuTimer implements CpuTimerMBean {
 | 
			
		||||
        return this.cpuPercent;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public long getLastSampleTime() {
 | 
			
		||||
        return this.stopTime;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String format(long elap) {
 | 
			
		||||
        String fraction = (elap % 1000) + "";
 | 
			
		||||
        int pad = 3 - fraction.length();
 | 
			
		||||
 | 
			
		||||
@ -29,4 +29,6 @@ public interface CpuTimerMBean {
 | 
			
		||||
    public double getCpuUsage();
 | 
			
		||||
 | 
			
		||||
    public long getTotalTime();
 | 
			
		||||
 | 
			
		||||
    public long getLastSampleTime();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user