system
Class SystemInformation

java.lang.Object
  extended by system.SystemInformation

public abstract class SystemInformation
extends java.lang.Object


Nested Class Summary
static class SystemInformation.CPUUsageSnapshot
          A simple class to represent data snapshots taken by makeCPUUsageSnapshot().
static class SystemInformation.NegativeCPUTime
           
 
Field Summary
static int MIN_ELAPSED_TIME
          Minimum time difference [in milliseconds] enforced for the inputs into getProcessCPUUsage(SystemInformation.CPUUsageSnapshot,SystemInformation.CPUUsageSnapshot).
 
Method Summary
static int detachProcess()
          Closes native-dependent process handle, if necessary.
static int getCPUs()
          Returns the number of processors on machine
static long getFreeMem()
          Returns current free memory in the system.
static long getMaxMem()
          Returns maximum memory available in the system.
static long getMemoryResident()
          Returns current process space being resident in memory, in Kbytes.
static long getMemoryUsage()
          Returns current space allocated for the process, in Kbytes.
static double getProcessCPUPercentage()
          Returns CPU (kernel + user) time used by the current process [in perecents].
static long getProcessCPUTime()
          Returns CPU (kernel + user) time used by the current process [in milliseconds].
static double getProcessCPUUsage()
          Returns CPU usage (fraction of 1.0) so far by the current process.
static double getProcessCPUUsage(SystemInformation.CPUUsageSnapshot start, SystemInformation.CPUUsageSnapshot end)
          Computes CPU usage (fraction of 1.0) between start.m_CPUTime and end.m_CPUTime time points [1.0 corresponds to 100% utilization of all processors].
static int getProcessID()
          Returns the PID of the current process.
static java.lang.String getSysInfo()
          Returns system name info like "uname" command output
static SystemInformation.CPUUsageSnapshot makeCPUUsageSnapshot()
          Creates a CPU usage data snapshot by associating CPU time used with system time.
static int setPid(int pid)
          Sets the system native process PID for which all measurements will be done.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MIN_ELAPSED_TIME

public static final int MIN_ELAPSED_TIME
Minimum time difference [in milliseconds] enforced for the inputs into getProcessCPUUsage(SystemInformation.CPUUsageSnapshot,SystemInformation.CPUUsageSnapshot). The motivation for this restriction is the fact that System.currentTimeMillis() on some systems has a low resolution (e.g., 10ms on win32). The current value is 100 ms.

See Also:
Constant Field Values
Method Detail

makeCPUUsageSnapshot

public static SystemInformation.CPUUsageSnapshot makeCPUUsageSnapshot()
                                                               throws SystemInformation.NegativeCPUTime
Creates a CPU usage data snapshot by associating CPU time used with system time. The resulting data can be fed into getProcessCPUUsage(SystemInformation.CPUUsageSnapshot,SystemInformation.CPUUsageSnapshot).

Throws:
SystemInformation.NegativeCPUTime

getProcessCPUUsage

public static double getProcessCPUUsage(SystemInformation.CPUUsageSnapshot start,
                                        SystemInformation.CPUUsageSnapshot end)
Computes CPU usage (fraction of 1.0) between start.m_CPUTime and end.m_CPUTime time points [1.0 corresponds to 100% utilization of all processors].

Throws:
java.lang.IllegalArgumentException - if start and end time points are less than MIN_ELAPSED_TIME ms apart.
java.lang.IllegalArgumentException - if either argument is null;

getProcessID

public static int getProcessID()
Returns the PID of the current process. The result is useful when you need to integrate a Java app with external tools.


getCPUs

public static int getCPUs()
Returns the number of processors on machine


getProcessCPUTime

public static long getProcessCPUTime()
Returns CPU (kernel + user) time used by the current process [in milliseconds]. The returned value is adjusted for the number of processors in the system.


getProcessCPUPercentage

public static double getProcessCPUPercentage()
Returns CPU (kernel + user) time used by the current process [in perecents]. The returned value is either CPU percentage, or zero if this is not supported by OS. Currently it is supported by Solaris8, and not supported by Windows XP


getMaxMem

public static long getMaxMem()
Returns maximum memory available in the system.


getFreeMem

public static long getFreeMem()
Returns current free memory in the system.


getSysInfo

public static java.lang.String getSysInfo()
Returns system name info like "uname" command output


getProcessCPUUsage

public static double getProcessCPUUsage()
Returns CPU usage (fraction of 1.0) so far by the current process. This is a total for all processors since the process creation time.


getMemoryUsage

public static long getMemoryUsage()
Returns current space allocated for the process, in Kbytes. Those pages may or may not be in memory.


getMemoryResident

public static long getMemoryResident()
Returns current process space being resident in memory, in Kbytes.


setPid

public static int setPid(int pid)
Sets the system native process PID for which all measurements will be done. If this method is not called then the current JVM pid will act as a default. Returns the native-dependent error code, or 0 in case of success.


detachProcess

public static int detachProcess()
Closes native-dependent process handle, if necessary.