Class AbstractCentralProcessor
- All Implemented Interfaces:
- CentralProcessor
- Direct Known Subclasses:
- OpenBsdCentralProcessor
- 
Nested Class SummaryNested classes/interfaces inherited from interface oshi.hardware.CentralProcessorCentralProcessor.LogicalProcessor, CentralProcessor.PhysicalProcessor, CentralProcessor.ProcessorCache, CentralProcessor.ProcessorIdentifier, CentralProcessor.TickType
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected static StringcreateProcessorID(String stepping, String model, String family, String[] flags) Creates a Processor ID by encoding the stepping, model, family, and feature flags.protected List<CentralProcessor.PhysicalProcessor> createProcListFromDmesg(List<CentralProcessor.LogicalProcessor> logProcs, Map<Integer, String> dmesg) longGet 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.Returns a list of platform-specific strings which identify CPU Feature Flags.longGet the number of system-wide interrupts which have occurred.intGet the number of logical CPUs available for processing.Returns anUnmodifiableListof the CPU's logical processors.longMaximum frequeny (in Hz), of the logical processors on this CPU.intGet the number of packages/sockets in the system.intGet the number of physical CPUs/cores available for processing.Returns anUnmodifiableListof the CPU's physical processors.Makes a best-effort attempt to identify the CPU's processor caches.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).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[]Get System-wide CPU Load tick counters.protected abstract Quartet<List<CentralProcessor.LogicalProcessor>, List<CentralProcessor.PhysicalProcessor>, List<CentralProcessor.ProcessorCache>, List<String>> Initializes logical and physical processor lists and feature flags.static List<CentralProcessor.ProcessorCache> Filters a set of processor caches to an ordered listprotected abstract longGet number of context switchesprotected abstract long[]Get processor current frequency.protected abstract longGet number of interruptsprotected longGet processor max frequency.protected abstract long[][]Get the processor CPU load ticksprotected abstract CentralProcessor.ProcessorIdentifierUpdates logical and physical processor counts and arraysprotected abstract long[]Get the system CPU load tickstoString()Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface oshi.hardware.CentralProcessorgetProcessorCpuLoad, getSystemCpuLoad, getSystemLoadAverage
- 
Constructor Details- 
AbstractCentralProcessorprotected AbstractCentralProcessor()Create a Processor
 
- 
- 
Method Details- 
initProcessorCountsprotected abstract Quartet<List<CentralProcessor.LogicalProcessor>,List<CentralProcessor.PhysicalProcessor>, initProcessorCounts()List<CentralProcessor.ProcessorCache>, List<String>> Initializes logical and physical processor lists and feature flags.- Returns:
- Lists of initialized Logical Processors, Physical Processors, Processor Caches, and Feature Flags.
 
- 
queryProcessorIdUpdates logical and physical processor counts and arrays- Returns:
- An array of initialized Logical Processors
 
- 
getProcessorIdentifierDescription copied from interface:CentralProcessorThe 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:
- getProcessorIdentifierin interface- CentralProcessor
- Returns:
- a CentralProcessor.ProcessorIdentifierobject encapsulating CPU identifier information.
 
- 
getMaxFreqpublic long getMaxFreq()Description copied from interface:CentralProcessorMaximum frequeny (in Hz), of the logical processors on this CPU.- Specified by:
- getMaxFreqin interface- CentralProcessor
- Returns:
- The max frequency or -1 if unknown.
 
- 
queryMaxFreqprotected long queryMaxFreq()Get processor max frequency.- Returns:
- The max frequency.
 
- 
getCurrentFreqpublic 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 interface- CentralProcessor
- 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.
 
- 
queryCurrentFreqprotected abstract long[] queryCurrentFreq()Get processor current frequency.- Returns:
- The current frequency.
 
- 
getContextSwitchespublic long getContextSwitches()Description copied from interface:CentralProcessorGet 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:
- getContextSwitchesin interface- CentralProcessor
- Returns:
- The number of context switches, if this information is available; 0 otherwise.
 
- 
queryContextSwitchesprotected abstract long queryContextSwitches()Get number of context switches- Returns:
- The context switches
 
- 
getInterruptspublic long getInterrupts()Description copied from interface:CentralProcessorGet the number of system-wide interrupts which have occurred.Not available system-wide on macOS. - Specified by:
- getInterruptsin interface- CentralProcessor
- Returns:
- The number of interrupts, if this information is available; 0 otherwise.
 
- 
queryInterruptsprotected abstract long queryInterrupts()Get number of interrupts- Returns:
- The interrupts
 
- 
getLogicalProcessorsDescription copied from interface:CentralProcessorReturns anUnmodifiableListof the CPU's logical processors. The list will be sorted in order of increasing NUMA node number, and then processor number. This order is (usually) consistent with other methods providing per-processor results.On some operating systems with variable numbers of logical processors, the size of this array could change and may not align with other per-processor methods. - Specified by:
- getLogicalProcessorsin interface- CentralProcessor
- Returns:
- An UnmodifiabeListof logical processors.
 
- 
getPhysicalProcessorsDescription copied from interface:CentralProcessorReturns anUnmodifiableListof the CPU's physical processors. The list will be sorted in order of increasing core ID.- Specified by:
- getPhysicalProcessorsin interface- CentralProcessor
- Returns:
- An UnmodifiabeListof physical processors.
 
- 
getProcessorCachesDescription copied from interface:CentralProcessorMakes a best-effort attempt to identify the CPU's processor caches. For hybrid processors, both performance and efficiency core caches are shown. Only one instance of per-core caches is shown.Values are unreliable in virtual machines and rely in information made available by the VM or hypervisor. Callers should conduct sanity checking of the returned objects. Not all values are available on all operating systems or architectures. Not available on Solaris. - Specified by:
- getProcessorCachesin interface- CentralProcessor
- Returns:
- An UnmodifiabeListof processor caches.
 
- 
getFeatureFlagsDescription copied from interface:CentralProcessorReturns a list of platform-specific strings which identify CPU Feature Flags. This string requires user parsing to obtain meaningful information.- Specified by:
- getFeatureFlagsin interface- CentralProcessor
- Returns:
- On Windows, returns a list of values for which the IsProcessorFeaturePresent()function evaluates to true.On macOS x86, returns relevant sysctl.machdep.featurevalues. On Apple Silicon, returns relevantsysctl hw.optional.arm.FEATvalues.On Linux, returns the flagsand/orfeaturesfields from/proc/cpuinfo.On OpenBSD, FreeBSD, and Solaris, returns dmesgoutput containing the wordFeature.For unimplemented operating systems, returns an empty list. 
 
- 
getSystemCpuLoadTickspublic long[] getSystemCpuLoadTicks()Description copied from interface:CentralProcessorGet System-wide CPU Load tick counters. Returns an array with eight 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.On some operating systems with variable numbers of logical processors, the size of this array could change and may not align with other per-processor methods. 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 interface- CentralProcessor
- Returns:
- An array of 8 long values representing time spent in User, Nice, System, Idle, IOwait, IRQ, SoftIRQ, and Steal states.
 
- 
querySystemCpuLoadTicksprotected abstract long[] querySystemCpuLoadTicks()Get the system CPU load ticks- Returns:
- The system CPU load ticks
 
- 
getProcessorCpuLoadTickspublic 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 interface- CentralProcessor
- Returns:
- A 2D array of logicalProcessorCount x 7 long values representing time spent in User, Nice, System, Idle, IOwait, IRQ, SoftIRQ, and Steal states.
 
- 
queryProcessorCpuLoadTicksprotected abstract long[][] queryProcessorCpuLoadTicks()Get the processor CPU load ticks- Returns:
- The processor CPU load ticks
 
- 
getSystemCpuLoadBetweenTickspublic 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.On some operating systems with variable numbers of logical processors, the size of the array returned from a previous call to CentralProcessor.getSystemCpuLoadTicks()could change and will throw anIllegalArgumentException. Calling code on these operating systems should handle this exception.- Specified by:
- getSystemCpuLoadBetweenTicksin interface- CentralProcessor
- Parameters:
- oldTicks- A tick array from a previous call to- CentralProcessor.getSystemCpuLoadTicks()
- Returns:
- CPU load between 0 and 1 (100%)
 
- 
getProcessorCpuLoadBetweenTickspublic 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.On some operating systems with variable numbers of logical processors, the size of the array returned from the two calls could change and will throw an IllegalArgumentException. Calling code on these operating systems should handle this exception.- Specified by:
- getProcessorCpuLoadBetweenTicksin interface- CentralProcessor
- Parameters:
- oldTicks- A tick array from a previous call to- CentralProcessor.getProcessorCpuLoadTicks()
- Returns:
- array of CPU load between 0 and 1 (100%) for each logical processor
 
- 
getLogicalProcessorCountpublic 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.On some operating systems with variable numbers of logical processors, may return a max value. - Specified by:
- getLogicalProcessorCountin interface- CentralProcessor
- Returns:
- The number of logical CPUs available.
 
- 
getPhysicalProcessorCountpublic int getPhysicalProcessorCount()Description copied from interface:CentralProcessorGet the number of physical CPUs/cores available for processing.On some operating systems with variable numbers of physical processors available to the OS, may return a max value. - Specified by:
- getPhysicalProcessorCountin interface- CentralProcessor
- Returns:
- The number of physical CPUs available.
 
- 
getPhysicalPackageCountpublic 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 interface- CentralProcessor
- Returns:
- The number of physical packages available.
 
- 
createProcessorIDprotected 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 stepping
- model- The CPU model
- family- The CPU family
- flags- A space-delimited list of CPU feature flags
- Returns:
- The Processor ID string
 
- 
createProcListFromDmesgprotected List<CentralProcessor.PhysicalProcessor> createProcListFromDmesg(List<CentralProcessor.LogicalProcessor> logProcs, Map<Integer, String> dmesg) 
- 
orderedProcCachespublic static List<CentralProcessor.ProcessorCache> orderedProcCaches(Set<CentralProcessor.ProcessorCache> caches) Filters a set of processor caches to an ordered list- Parameters:
- caches- A set of unique caches.
- Returns:
- A list sorted by level (desc), type, and size (desc)
 
- 
toString
 
-