com.jezhumble.javasysmon
Class CpuTimes

java.lang.Object
  extended by com.jezhumble.javasysmon.CpuTimes

public class CpuTimes
extends java.lang.Object

This object represents a snapshot detailing the total time the CPUs have spent idle, in user mode, and in kernel mode.


Constructor Summary
CpuTimes(long userMillis, long systemMillis, long idleMillis)
           
 
Method Summary
 float getCpuUsage(CpuTimes previous)
          Gets the CPU usage given a previous snapshot of CPU times.
 long getIdleMillis()
          The total time in milliseconds that the CPUs have spent idle.
 long getSystemMillis()
          The total time in milliseconds that the CPUs have spent in kernel mode.
 long getTotalMillis()
          The total time in milliseconds that the CPUs have been alive since the system was last booted.
 long getUserMillis()
          The total time in milliseconds that the CPUs have spent in user mode.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CpuTimes

public CpuTimes(long userMillis,
                long systemMillis,
                long idleMillis)
Method Detail

getUserMillis

public long getUserMillis()
The total time in milliseconds that the CPUs have spent in user mode.

Returns:
The total time in milliseconds that the CPUs have spent in user mode.

getSystemMillis

public long getSystemMillis()
The total time in milliseconds that the CPUs have spent in kernel mode.

Returns:
The total time in milliseconds that the CPUs have spent in kernel mode.

getIdleMillis

public long getIdleMillis()
The total time in milliseconds that the CPUs have spent idle.

Returns:
The total time in milliseconds that the CPUs have spent idle.

getTotalMillis

public long getTotalMillis()
The total time in milliseconds that the CPUs have been alive since the system was last booted. Should equal the sum of the other three numbers.

Returns:
The total time in milliseconds that the CPUs have been alive.

getCpuUsage

public float getCpuUsage(CpuTimes previous)
Gets the CPU usage given a previous snapshot of CPU times. The number returned represents the proportion of time between the two snapshots that the CPUs spent not idle.

Parameters:
previous - a CpuTimes snapshot taken previously.
Returns:
the proportion of time between the previous snapshot and this snapshot that the CPUs have spent working. 1 represents 100% usage, 0 represents 0% usage.


Copyright © 2009 ThoughtWorks. All Rights Reserved.