Class AbstractCentralProcessor
- All Implemented Interfaces:
CentralProcessor
- Direct Known Subclasses:
OpenBsdCentralProcessor
-
Nested Class Summary
Nested classes/interfaces inherited from interface oshi.hardware.CentralProcessor
CentralProcessor.LogicalProcessor, CentralProcessor.ProcessorIdentifier, CentralProcessor.TickType
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected static String
createProcessorID
(String stepping, String model, String family, String[] flags) Creates a Processor ID by encoding the stepping, model, family, and feature flags.long
Get the number of system-wide context switches which have occurred.long[]
Attempts to return the current frequency (in Hz), of the logical processors on this CPU.long
Get the number of system-wide interrupts which have occurred.int
Get the number of logical CPUs available for processing.Returns anUnmodifiableList
of the CPU's logical processors.long
Maximum frequeny (in Hz), of the logical processors on this CPU.int
Get the number of packages/sockets in the system.int
Get the number of physical CPUs/cores available for processing.double[]
getProcessorCpuLoadBetweenTicks
(long[][] oldTicks) Returns the "recent cpu usage" for all logical processors by counting ticks fromCentralProcessor.getProcessorCpuLoadTicks()
between the user-provided value from a previous call.long[][]
Get Processor CPU Load tick counters.The CPU's identifier strings ,including name, vendor, stepping, model, and family information (also called the signature of a CPU).double
getSystemCpuLoadBetweenTicks
(long[] oldTicks) Returns the "recent cpu usage" for the whole system by counting ticks fromCentralProcessor.getSystemCpuLoadTicks()
between the user-provided value from a previous call.long[]
Get System-wide CPU Load tick counters.protected abstract List<CentralProcessor.LogicalProcessor>
Updates logical and physical processor counts and arraysprotected abstract long
Get number of context switchesprotected abstract long[]
Get processor current frequency.protected abstract long
Get number of interruptsprotected abstract long
Get processor max frequency.protected abstract long[][]
Get the processor CPU load ticksprotected abstract CentralProcessor.ProcessorIdentifier
Updates logical and physical processor counts and arraysprotected abstract long[]
Get the system CPU load tickstoString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface oshi.hardware.CentralProcessor
getSystemLoadAverage
-
Constructor Details
-
AbstractCentralProcessor
protected AbstractCentralProcessor()Create a Processor
-
-
Method Details
-
initProcessorCounts
Updates logical and physical processor counts and arrays- Returns:
- An array of initialized Logical Processors
-
queryProcessorId
Updates logical and physical processor counts and arrays- Returns:
- An array of initialized Logical Processors
-
getProcessorIdentifier
Description copied from interface:CentralProcessor
The CPU's identifier strings ,including name, vendor, stepping, model, and family information (also called the signature of a CPU).The Processor Identifier is primarily associated with Intel-based chips. Attempts are made to provide comparable values for other chip manufacturers.
- Specified by:
getProcessorIdentifier
in interfaceCentralProcessor
- Returns:
- a
CentralProcessor.ProcessorIdentifier
object encapsulating CPU identifier information.
-
getMaxFreq
public long getMaxFreq()Description copied from interface:CentralProcessor
Maximum frequeny (in Hz), of the logical processors on this CPU.- Specified by:
getMaxFreq
in interfaceCentralProcessor
- Returns:
- The max frequency or -1 if unknown.
-
queryMaxFreq
protected abstract long queryMaxFreq()Get processor max frequency.- Returns:
- The max frequency.
-
getCurrentFreq
public long[] getCurrentFreq()Description copied from interface:CentralProcessor
Attempts to return the current frequency (in Hz), of the logical processors on this CPU.May not be implemented on all Operating Systems.
On Windows, returns an estimate based on the percent of maximum frequency. On Windows systems with more than 64 logical processors, may only return frequencies for the current processor group in the first portion of the array.
- Specified by:
getCurrentFreq
in interfaceCentralProcessor
- Returns:
- An array of processor frequencies for each logical processor on the
system. Use the
CentralProcessor.getLogicalProcessors()
to correlate these frequencies with physical packages and processors.
-
queryCurrentFreq
protected abstract long[] queryCurrentFreq()Get processor current frequency.- Returns:
- The current frequency.
-
getContextSwitches
public long getContextSwitches()Description copied from interface:CentralProcessor
Get the number of system-wide context switches which have occurred.Not available system-wide on macOS. Process- and Thread-level context switches are available from
OSProcess.getContextSwitches()
andOSThread.getContextSwitches()
.- Specified by:
getContextSwitches
in interfaceCentralProcessor
- Returns:
- The number of context switches, if this information is available; 0 otherwise.
-
queryContextSwitches
protected abstract long queryContextSwitches()Get number of context switches- Returns:
- The context switches
-
getInterrupts
public long getInterrupts()Description copied from interface:CentralProcessor
Get the number of system-wide interrupts which have occurred.Not available system-wide on macOS.
- Specified by:
getInterrupts
in interfaceCentralProcessor
- Returns:
- The number of interrupts, if this information is available; 0 otherwise.
-
queryInterrupts
protected abstract long queryInterrupts()Get number of interrupts- Returns:
- The interrupts
-
getLogicalProcessors
Description copied from interface:CentralProcessor
Returns anUnmodifiableList
of the CPU's logical processors. The list will be sorted in order of increasing NUMA node number, and then processor number. This order is consistent with other methods providing per-processor results.- Specified by:
getLogicalProcessors
in interfaceCentralProcessor
- Returns:
- An
UnmodifiabeList
of logical processors.
-
getSystemCpuLoadTicks
public long[] getSystemCpuLoadTicks()Description copied from interface:CentralProcessor
Get System-wide CPU Load tick counters. Returns an array with seven elements representing milliseconds 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.Note that while tick counters are in units of milliseconds, they may advance in larger increments along with (platform dependent) clock ticks. For example, by default Windows clock ticks are 1/64 of a second (about 15 or 16 milliseconds) and Linux ticks are distribution and configuration dependent but usually 1/100 of a second (10 milliseconds).
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).
- Specified by:
getSystemCpuLoadTicks
in interfaceCentralProcessor
- Returns:
- An array of 7 long values representing time spent in User, Nice, System, Idle, IOwait, IRQ, SoftIRQ, and Steal states.
-
querySystemCpuLoadTicks
protected abstract long[] querySystemCpuLoadTicks()Get the system CPU load ticks- Returns:
- The system CPU load ticks
-
getProcessorCpuLoadTicks
public long[][] getProcessorCpuLoadTicks()Description copied from interface:CentralProcessor
Get Processor CPU Load tick counters. Returns a two dimensional array, withCentralProcessor.getLogicalProcessorCount()
arrays, each containing seven elements representing milliseconds 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.Note that while tick counters are in units of milliseconds, they may advance in larger increments along with (platform dependent) clock ticks. For example, by default Windows clock ticks are 1/64 of a second (about 15 or 16 milliseconds) and Linux ticks are distribution and configuration dependent but usually 1/100 of a second (10 milliseconds).
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).
- Specified by:
getProcessorCpuLoadTicks
in interfaceCentralProcessor
- Returns:
- A 2D array of logicalProcessorCount x 7 long values representing time spent in User, Nice, System, Idle, IOwait, IRQ, SoftIRQ, and Steal states.
-
queryProcessorCpuLoadTicks
protected abstract long[][] queryProcessorCpuLoadTicks()Get the processor CPU load ticks- Returns:
- The processor CPU load ticks
-
getSystemCpuLoadBetweenTicks
public double getSystemCpuLoadBetweenTicks(long[] oldTicks) Description copied from interface:CentralProcessor
Returns the "recent cpu usage" for the whole system by counting ticks fromCentralProcessor.getSystemCpuLoadTicks()
between the user-provided value from a previous call.- Specified by:
getSystemCpuLoadBetweenTicks
in interfaceCentralProcessor
- Parameters:
oldTicks
- A tick array from a previous call toCentralProcessor.getSystemCpuLoadTicks()
- Returns:
- CPU load between 0 and 1 (100%)
-
getProcessorCpuLoadBetweenTicks
public double[] getProcessorCpuLoadBetweenTicks(long[][] oldTicks) Description copied from interface:CentralProcessor
Returns the "recent cpu usage" for all logical processors by counting ticks fromCentralProcessor.getProcessorCpuLoadTicks()
between the user-provided value from a previous call.- Specified by:
getProcessorCpuLoadBetweenTicks
in interfaceCentralProcessor
- Parameters:
oldTicks
- A tick array from a previous call toCentralProcessor.getProcessorCpuLoadTicks()
- Returns:
- array of CPU load between 0 and 1 (100%) for each logical processor
-
getLogicalProcessorCount
public int getLogicalProcessorCount()Description copied from interface:CentralProcessor
Get the number of logical CPUs available for processing. This value may be higher than physical CPUs if hyperthreading is enabled.- Specified by:
getLogicalProcessorCount
in interfaceCentralProcessor
- Returns:
- The number of logical CPUs available.
-
getPhysicalProcessorCount
public int getPhysicalProcessorCount()Description copied from interface:CentralProcessor
Get the number of physical CPUs/cores available for processing.- Specified by:
getPhysicalProcessorCount
in interfaceCentralProcessor
- Returns:
- The number of physical CPUs available.
-
getPhysicalPackageCount
public int getPhysicalPackageCount()Description copied from interface:CentralProcessor
Get the number of packages/sockets in the system. A single package may contain multiple cores.- Specified by:
getPhysicalPackageCount
in interfaceCentralProcessor
- Returns:
- The number of physical packages available.
-
createProcessorID
protected static String createProcessorID(String stepping, String model, String family, String[] flags) Creates a Processor ID by encoding the stepping, model, family, and feature flags.- Parameters:
stepping
- The CPU steppingmodel
- The CPU modelfamily
- The CPU familyflags
- A space-delimited list of CPU feature flags- Returns:
- The Processor ID string
-
toString
-