Package oshi.hardware.platform.linux
Class LinuxCentralProcessor
- java.lang.Object
-
- oshi.hardware.common.AbstractCentralProcessor
-
- oshi.hardware.platform.linux.LinuxCentralProcessor
-
- All Implemented Interfaces:
java.io.Serializable
,CentralProcessor
public class LinuxCentralProcessor extends AbstractCentralProcessor
A CPU as defined in Linux /proc.- Author:
- alessandro[at]perucchi[dot]org, alessio.fachechi[at]gmail[dot]com, widdis[at]gmail[dot]com
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface oshi.hardware.CentralProcessor
CentralProcessor.TickType
-
-
Field Summary
-
Fields inherited from class oshi.hardware.common.AbstractCentralProcessor
logicalProcessorCount, physicalPackageCount, physicalProcessorCount
-
-
Constructor Summary
Constructors Constructor Description LinuxCentralProcessor()
Create a Processor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
calculateProcessorCounts()
Updates logical and physical processor counts from /proc/cpuinfolong
getContextSwitches()
Get the number of context switches which have occurredlong
getInterrupts()
Get the number of interrupts which have occurredlong[][]
getProcessorCpuLoadTicks()
Get Processor CPU Load tick counters.long[]
getSystemCpuLoadTicks()
Get System-wide CPU Load tick counters.double[]
getSystemLoadAverage(int nelem)
Returns the system load average for the number of elements specified, up to 3, representing 1, 5, and 15 minutes.long
getSystemUptime()
Get the System uptime (time since boot).-
Methods inherited from class oshi.hardware.common.AbstractCentralProcessor
createProcessorID, getFamily, getIdentifier, getLogicalProcessorCount, getModel, getName, getPhysicalPackageCount, getPhysicalProcessorCount, getProcessorCpuLoadBetweenTicks, getProcessorID, getStepping, getSystemCpuLoad, getSystemCpuLoadBetweenTicks, getSystemLoadAverage, getVendor, getVendorFreq, initTicks, isCpu64bit, setCpu64, setFamily, setIdentifier, setModel, setName, setProcessorID, setStepping, setVendor, setVendorFreq, toString, updateProcessorTicks, updateSystemTicks
-
-
-
-
Method Detail
-
calculateProcessorCounts
protected void calculateProcessorCounts()
Updates logical and physical processor counts from /proc/cpuinfo- Specified by:
calculateProcessorCounts
in classAbstractCentralProcessor
-
getSystemCpuLoadTicks
public long[] getSystemCpuLoadTicks()
Get System-wide CPU Load tick counters. Returns an array with seven elements representing either clock ticks or milliseconds (platform dependent) spent in User (0), Nice (1), System (2), Idle (3), IOwait (4), Hardware interrupts (IRQ) (5), Software interrupts/DPC (SoftIRQ) (6), or Steal (7) states. UseCentralProcessor.TickType.getIndex()
to retrieve the appropriate index. By measuring the difference between ticks across a time interval, CPU load over that interval may be calculated. Nice and IOWait information is not available on Windows, and IOwait and IRQ information is not available on macOS, so these ticks will always be zero. To calculate overall Idle time using this method, include both Idle and IOWait ticks. Similarly, IRQ, SoftIRQ, and Steal ticks should be added to the System value to get the total. System ticks also include time executing other virtual hosts (steal).- Returns:
- An array of 7 long values representing time spent in User, Nice, System, Idle, IOwait, IRQ, SoftIRQ, and Steal states.
-
getSystemLoadAverage
public double[] getSystemLoadAverage(int nelem)
Returns the system load average for the number of elements specified, up to 3, representing 1, 5, and 15 minutes. The system load average is the sum of the number of runnable entities queued to the available processors and the number of runnable entities running on the available processors averaged over a period of time. The way in which the load average is calculated is operating system specific but is typically a damped time-dependent average. If the load average is not available, a negative value is returned. This method is designed to provide a hint about the system load and may be queried frequently. The load average may be unavailable on some platforms (e.g., Windows) where it is expensive to implement this method.- Parameters:
nelem
- Number of elements to return.- Returns:
- an array of the system load averages for 1, 5, and 15 minutes with the size of the array specified by nelem; or negative values if not available.
-
getProcessorCpuLoadTicks
public long[][] getProcessorCpuLoadTicks()
Get Processor CPU Load tick counters. Returns a two dimensional array, withCentralProcessor.getLogicalProcessorCount()
arrays, each containing seven elements representing either clock ticks or milliseconds (platform dependent) spent in User (0), Nice (1), System (2), Idle (3), IOwait (4), Hardware interrupts (IRQ) (5), Software interrupts/DPC (SoftIRQ) (6), or Steal (7) states. UseCentralProcessor.TickType.getIndex()
to retrieve the appropriate index. By measuring the difference between ticks across a time interval, CPU load over that interval may be calculated. Nice and IOwait per processor information is not available on Windows, and IOwait and IRQ information is not available on macOS, so these ticks will always be zero. To calculate overall Idle time using this method, include both Idle and IOWait ticks. Similarly, IRQ, SoftIRQ and Steal ticks should be added to the System value to get the total. System ticks also include time executing other virtual hosts (steal).- Returns:
- A 2D array of logicalProcessorCount x 7 long values representing time spent in User, Nice, System, Idle, IOwait, IRQ, SoftIRQ, and Steal states.
-
getSystemUptime
public long getSystemUptime()
Get the System uptime (time since boot).- Returns:
- Number of seconds since boot.
-
getContextSwitches
public long getContextSwitches()
Get the number of context switches which have occurred- Returns:
- The number of context switches
-
getInterrupts
public long getInterrupts()
Get the number of interrupts which have occurred- Returns:
- The number of interrupts
-
-