From 421f3b4dc5e6b33bb37a7ee731d1b9912f3c9597 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Thu, 1 Feb 2007 00:49:06 +0000 Subject: [PATCH] add LastSampleTime --- bindings/java/src/org/hyperic/sigar/CpuTimer.java | 12 +++++++++--- .../src/org/hyperic/sigar/jmx/CpuTimerMBean.java | 2 ++ 2 files changed, 11 insertions(+), 3 deletions(-) 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(); }