Class AbstractCentralProcessor
- All Implemented Interfaces:
CentralProcessor
@ThreadSafe public abstract class AbstractCentralProcessor extends java.lang.Object implements CentralProcessor
-
Nested Class Summary
Nested classes/interfaces inherited from interface oshi.hardware.CentralProcessor
CentralProcessor.LogicalProcessor, CentralProcessor.ProcessorIdentifier, CentralProcessor.TickType -
Constructor Summary
Constructors Constructor Description AbstractCentralProcessor()Create a Processor -
Method Summary
Modifier and Type Method Description protected static java.lang.StringcreateProcessorID(java.lang.String stepping, java.lang.String model, java.lang.String family, java.lang.String[] flags)Creates a Processor ID by encoding the stepping, model, family, and feature flags.longgetContextSwitches()Get the number of context switches which have occurredlong[]getCurrentFreq()Attempts to return the current frequency (in Hz), of the logical processors on this CPU.java.lang.StringgetFamily()Gets the family.java.lang.StringgetIdentifier()Identifier, eg.longgetInterrupts()Get the number of interrupts which have occurredintgetLogicalProcessorCount()Get the number of logical CPUs available for processing.CentralProcessor.LogicalProcessor[]getLogicalProcessors()Returns an array of the CPU's logical processors.longgetMaxFreq()Maximum frequeny (in Hz), of the logical processors on this CPU.java.lang.StringgetModel()Gets the model.java.lang.StringgetName()Name, eg.intgetPhysicalPackageCount()Get the number of packages/sockets in the system.intgetPhysicalProcessorCount()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[][]getProcessorCpuLoadTicks()Get Processor CPU Load tick counters.java.lang.StringgetProcessorID()Gets the Processor ID.CentralProcessor.ProcessorIdentifiergetProcessorIdentifier()The CPU's identifier strings ,including name, vendor, stepping, model, and family information (also called the signature of a CPU)java.lang.StringgetStepping()Gets the stepping.doublegetSystemCpuLoadBetweenTicks(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[]getSystemCpuLoadTicks()Get System-wide CPU Load tick counters.java.lang.StringgetVendor()Processor vendor.longgetVendorFreq()Vendor frequency (in Hz), eg.protected abstract CentralProcessor.LogicalProcessor[]initProcessorCounts()Updates logical and physical processor counts and arraysbooleanisCpu64bit()Is CPU 64bit?protected abstract longqueryContextSwitches()Get number of context switchesprotected abstract long[]queryCurrentFreq()Get processor current frequency.protected abstract longqueryInterrupts()Get number of interruptsprotected abstract longqueryMaxFreq()Get processor max frequency.protected abstract long[][]queryProcessorCpuLoadTicks()Get the processor CPU load ticksprotected abstract CentralProcessor.ProcessorIdentifierqueryProcessorId()Updates logical and physical processor counts and arraysprotected abstract long[]querySystemCpuLoadTicks()Get the system CPU load ticksjava.lang.StringtoString()
-
Constructor Details
-
AbstractCentralProcessor
public 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:CentralProcessorThe CPU's identifier strings ,including name, vendor, stepping, model, and family information (also called the signature of a CPU)- Specified by:
getProcessorIdentifierin interfaceCentralProcessor- Returns:
- a
CentralProcessor.ProcessorIdentifierobject encapsulating CPU identifier information.
-
getVendor
public java.lang.String getVendor()Description copied from interface:CentralProcessorProcessor vendor.- Specified by:
getVendorin interfaceCentralProcessor- Returns:
- vendor string.
-
getName
public java.lang.String getName()Description copied from interface:CentralProcessorName, eg. Intel(R) Core(TM)2 Duo CPU T7300 @ 2.00GHz- Specified by:
getNamein interfaceCentralProcessor- Returns:
- Processor name.
-
getFamily
public java.lang.String getFamily()Description copied from interface:CentralProcessorGets the family. For non-Intel/AMD processors, returns the comparable value, such as the Architecture.- Specified by:
getFamilyin interfaceCentralProcessor- Returns:
- the family
-
getModel
public java.lang.String getModel()Description copied from interface:CentralProcessorGets the model. For non-Intel/AMD processors, returns the comparable value, such as the Partnum.- Specified by:
getModelin interfaceCentralProcessor- Returns:
- the model
-
getStepping
public java.lang.String getStepping()Description copied from interface:CentralProcessorGets the stepping. For non-Intel/AMD processors, returns the comparable value, such as the rnpn composite of Variant and Revision.- Specified by:
getSteppingin interfaceCentralProcessor- Returns:
- the stepping
-
getProcessorID
public java.lang.String getProcessorID()Description copied from interface:CentralProcessorGets the Processor ID. This is a hexidecimal string representing an 8-byte value, normally obtained using the CPUID opcode with the EAX register set to 1. The first four bytes are the resulting contents of the EAX register, which is the Processor signature, represented in human-readable form byCentralProcessor.getIdentifier(). The remaining four bytes are the contents of the EDX register, containing feature flags.For processors that do not support the CPUID opcode this field is populated with a comparable hex string. For example, ARM Processors will fill the first 32 bytes with the MIDR.
NOTE: The order of returned bytes is platform and software dependent. Values may be in either Big Endian or Little Endian order.
NOTE: If OSHI is unable to determine the ProcessorID from native sources, it will attempt to reconstruct one from available information in the processor identifier.
- Specified by:
getProcessorIDin interfaceCentralProcessor- Returns:
- A string representing the Processor ID
-
getIdentifier
public java.lang.String getIdentifier()Description copied from interface:CentralProcessorIdentifier, eg. x86 Family 6 Model 15 Stepping 10. For non-Intel/AMD processors, this string is populated with comparable values.- Specified by:
getIdentifierin interfaceCentralProcessor- Returns:
- Processor identifier.
-
isCpu64bit
public boolean isCpu64bit()Description copied from interface:CentralProcessorIs CPU 64bit?- Specified by:
isCpu64bitin interfaceCentralProcessor- Returns:
- True if cpu is 64bit.
-
getVendorFreq
public long getVendorFreq()Description copied from interface:CentralProcessorVendor frequency (in Hz), eg. for processor named Intel(R) Core(TM)2 Duo CPU T7300 @ 2.00GHz the vendor frequency is 2000000000.- Specified by:
getVendorFreqin interfaceCentralProcessor- Returns:
- Processor frequency or -1 if unknown.
-
getMaxFreq
public long getMaxFreq()Description copied from interface:CentralProcessorMaximum frequeny (in Hz), of the logical processors on this CPU.- Specified by:
getMaxFreqin 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:CentralProcessorAttempts 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:
getCurrentFreqin 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:CentralProcessorGet the number of context switches which have occurred- Specified by:
getContextSwitchesin interfaceCentralProcessor- Returns:
- The number of context switches
-
queryContextSwitches
protected abstract long queryContextSwitches()Get number of context switches- Returns:
- The context switches
-
getInterrupts
public long getInterrupts()Description copied from interface:CentralProcessorGet the number of interrupts which have occurred- Specified by:
getInterruptsin interfaceCentralProcessor- Returns:
- The number of interrupts
-
queryInterrupts
protected abstract long queryInterrupts()Get number of interrupts- Returns:
- The interrupts
-
getLogicalProcessors
Description copied from interface:CentralProcessorReturns an array of the CPU's logical processors. The array 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:
getLogicalProcessorsin interfaceCentralProcessor- Returns:
- The logical processor array.
-
getSystemCpuLoadTicks
public long[] getSystemCpuLoadTicks()Description copied from interface:CentralProcessorGet 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:
getSystemCpuLoadTicksin 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:CentralProcessorGet 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:
getProcessorCpuLoadTicksin 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:CentralProcessorReturns the "recent cpu usage" for the whole system by counting ticks fromCentralProcessor.getSystemCpuLoadTicks()between the user-provided value from a previous call.- Specified by:
getSystemCpuLoadBetweenTicksin 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:CentralProcessorReturns the "recent cpu usage" for all logical processors by counting ticks fromCentralProcessor.getProcessorCpuLoadTicks()between the user-provided value from a previous call.- Specified by:
getProcessorCpuLoadBetweenTicksin 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:CentralProcessorGet the number of logical CPUs available for processing. This value may be higher than physical CPUs if hyperthreading is enabled.- Specified by:
getLogicalProcessorCountin interfaceCentralProcessor- Returns:
- The number of logical CPUs available.
-
getPhysicalProcessorCount
public int getPhysicalProcessorCount()Description copied from interface:CentralProcessorGet the number of physical CPUs/cores available for processing.- Specified by:
getPhysicalProcessorCountin interfaceCentralProcessor- Returns:
- The number of physical CPUs available.
-
getPhysicalPackageCount
public int getPhysicalPackageCount()Description copied from interface:CentralProcessorGet the number of packages/sockets in the system. A single package may contain multiple cores.- Specified by:
getPhysicalPackageCountin interfaceCentralProcessor- Returns:
- The number of physical packages available.
-
createProcessorID
protected static java.lang.String createProcessorID(java.lang.String stepping, java.lang.String model, java.lang.String family, java.lang.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
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-