diff --git a/bindings/java/src/org/hyperic/sigar/CpuTimer.java b/bindings/java/src/org/hyperic/sigar/CpuTimer.java index 5e290aa0..df96aeb3 100644 --- a/bindings/java/src/org/hyperic/sigar/CpuTimer.java +++ b/bindings/java/src/org/hyperic/sigar/CpuTimer.java @@ -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(); diff --git a/bindings/java/src/org/hyperic/sigar/jmx/CpuTimerMBean.java b/bindings/java/src/org/hyperic/sigar/jmx/CpuTimerMBean.java index f8be0968..06bb9930 100644 --- a/bindings/java/src/org/hyperic/sigar/jmx/CpuTimerMBean.java +++ b/bindings/java/src/org/hyperic/sigar/jmx/CpuTimerMBean.java @@ -29,4 +29,6 @@ public interface CpuTimerMBean { public double getCpuUsage(); public long getTotalTime(); + + public long getLastSampleTime(); }