Package oshi.hardware.platform.linux
Class LinuxCentralProcessor
- java.lang.Object
-
- oshi.hardware.common.AbstractCentralProcessor
-
- oshi.hardware.platform.linux.LinuxCentralProcessor
-
- All Implemented Interfaces:
CentralProcessor
@ThreadSafe final class LinuxCentralProcessor extends AbstractCentralProcessor
A CPU as defined in Linux /proc.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface oshi.hardware.CentralProcessor
CentralProcessor.LogicalProcessor, CentralProcessor.PhysicalProcessor, CentralProcessor.ProcessorCache, CentralProcessor.ProcessorIdentifier, CentralProcessor.TickType
-
-
Field Summary
Fields Modifier and Type Field Description private static org.slf4j.Logger
LOG
-
Constructor Summary
Constructors Constructor Description LinuxCentralProcessor()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static java.lang.String
createMIDR(java.lang.String vendor, java.lang.String stepping, java.lang.String model, java.lang.String family)
Creates the MIDR, the ARM equivalent of CPUID ProcessorIDprivate static CentralProcessor.LogicalProcessor
getLogicalProcessorFromSyspath(java.lang.String syspath, java.util.Set<CentralProcessor.ProcessorCache> caches, java.lang.String modAlias, java.util.Map<java.lang.Integer,java.lang.Integer> coreEfficiencyMap, java.util.Map<java.lang.Integer,java.lang.String> modAliasMap)
private static java.lang.String
getProcessorID(java.lang.String vendor, java.lang.String stepping, java.lang.String model, java.lang.String family, java.lang.String[] flags)
Fetches the ProcessorID from dmidecode (if possible with root permissions), the cpuid command (if installed) or by encoding the stepping, model, family, and feature flags.double[]
getSystemLoadAverage(int nelem)
Returns the system load average for the number of elements specified, up to 3, representing 1, 5, and 15 minutes.protected Quartet<java.util.List<CentralProcessor.LogicalProcessor>,java.util.List<CentralProcessor.PhysicalProcessor>,java.util.List<CentralProcessor.ProcessorCache>,java.util.List<java.lang.String>>
initProcessorCounts()
Initializes logical and physical processor lists and feature flags.private static java.util.Set<CentralProcessor.ProcessorCache>
mapCachesFromLscpu()
private static java.util.Map<java.lang.Integer,java.lang.Integer>
mapNumaNodesFromLscpu()
private static CentralProcessor.ProcessorCache.Type
parseCacheType(java.lang.String type)
long
queryContextSwitches()
Get number of context switcheslong[]
queryCurrentFreq()
Get processor current frequency.long
queryInterrupts()
Get number of interruptslong
queryMaxFreq()
Get processor max frequency.long[][]
queryProcessorCpuLoadTicks()
Get the processor CPU load ticksprotected CentralProcessor.ProcessorIdentifier
queryProcessorId()
Updates logical and physical processor counts and arrayslong[]
querySystemCpuLoadTicks()
Get the system CPU load ticksprivate static Quartet<java.util.List<CentralProcessor.LogicalProcessor>,java.util.List<CentralProcessor.ProcessorCache>,java.util.Map<java.lang.Integer,java.lang.Integer>,java.util.Map<java.lang.Integer,java.lang.String>>
readTopologyFromCpuinfo()
private static Quartet<java.util.List<CentralProcessor.LogicalProcessor>,java.util.List<CentralProcessor.ProcessorCache>,java.util.Map<java.lang.Integer,java.lang.Integer>,java.util.Map<java.lang.Integer,java.lang.String>>
readTopologyFromSysfs()
private static Quartet<java.util.List<CentralProcessor.LogicalProcessor>,java.util.List<CentralProcessor.ProcessorCache>,java.util.Map<java.lang.Integer,java.lang.Integer>,java.util.Map<java.lang.Integer,java.lang.String>>
readTopologyFromUdev()
-
Methods inherited from class oshi.hardware.common.AbstractCentralProcessor
createProcessorID, createProcListFromDmesg, getContextSwitches, getCurrentFreq, getFeatureFlags, getInterrupts, getLogicalProcessorCount, getLogicalProcessors, getMaxFreq, getPhysicalPackageCount, getPhysicalProcessorCount, getPhysicalProcessors, getProcessorCaches, getProcessorCpuLoadBetweenTicks, getProcessorCpuLoadTicks, getProcessorIdentifier, getSystemCpuLoadBetweenTicks, getSystemCpuLoadTicks, orderedProcCaches, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface oshi.hardware.CentralProcessor
getProcessorCpuLoad, getSystemCpuLoad
-
-
-
-
Method Detail
-
queryProcessorId
protected CentralProcessor.ProcessorIdentifier queryProcessorId()
Description copied from class:AbstractCentralProcessor
Updates logical and physical processor counts and arrays- Specified by:
queryProcessorId
in classAbstractCentralProcessor
- Returns:
- An array of initialized Logical Processors
-
initProcessorCounts
protected Quartet<java.util.List<CentralProcessor.LogicalProcessor>,java.util.List<CentralProcessor.PhysicalProcessor>,java.util.List<CentralProcessor.ProcessorCache>,java.util.List<java.lang.String>> initProcessorCounts()
Description copied from class:AbstractCentralProcessor
Initializes logical and physical processor lists and feature flags.- Specified by:
initProcessorCounts
in classAbstractCentralProcessor
- Returns:
- Lists of initialized Logical Processors, Physical Processors, Processor Caches, and Feature Flags.
-
readTopologyFromUdev
private static Quartet<java.util.List<CentralProcessor.LogicalProcessor>,java.util.List<CentralProcessor.ProcessorCache>,java.util.Map<java.lang.Integer,java.lang.Integer>,java.util.Map<java.lang.Integer,java.lang.String>> readTopologyFromUdev()
-
readTopologyFromSysfs
private static Quartet<java.util.List<CentralProcessor.LogicalProcessor>,java.util.List<CentralProcessor.ProcessorCache>,java.util.Map<java.lang.Integer,java.lang.Integer>,java.util.Map<java.lang.Integer,java.lang.String>> readTopologyFromSysfs()
-
getLogicalProcessorFromSyspath
private static CentralProcessor.LogicalProcessor getLogicalProcessorFromSyspath(java.lang.String syspath, java.util.Set<CentralProcessor.ProcessorCache> caches, java.lang.String modAlias, java.util.Map<java.lang.Integer,java.lang.Integer> coreEfficiencyMap, java.util.Map<java.lang.Integer,java.lang.String> modAliasMap)
-
parseCacheType
private static CentralProcessor.ProcessorCache.Type parseCacheType(java.lang.String type)
-
readTopologyFromCpuinfo
private static Quartet<java.util.List<CentralProcessor.LogicalProcessor>,java.util.List<CentralProcessor.ProcessorCache>,java.util.Map<java.lang.Integer,java.lang.Integer>,java.util.Map<java.lang.Integer,java.lang.String>> readTopologyFromCpuinfo()
-
mapNumaNodesFromLscpu
private static java.util.Map<java.lang.Integer,java.lang.Integer> mapNumaNodesFromLscpu()
-
mapCachesFromLscpu
private static java.util.Set<CentralProcessor.ProcessorCache> mapCachesFromLscpu()
-
querySystemCpuLoadTicks
public long[] querySystemCpuLoadTicks()
Description copied from class:AbstractCentralProcessor
Get the system CPU load ticks- Specified by:
querySystemCpuLoadTicks
in classAbstractCentralProcessor
- Returns:
- The system CPU load ticks
-
queryCurrentFreq
public long[] queryCurrentFreq()
Description copied from class:AbstractCentralProcessor
Get processor current frequency.- Specified by:
queryCurrentFreq
in classAbstractCentralProcessor
- Returns:
- The current frequency.
-
queryMaxFreq
public long queryMaxFreq()
Description copied from class:AbstractCentralProcessor
Get processor max frequency.- Overrides:
queryMaxFreq
in classAbstractCentralProcessor
- Returns:
- The max frequency.
-
getSystemLoadAverage
public double[] getSystemLoadAverage(int nelem)
Description copied from interface:CentralProcessor
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.This method is designed to provide a hint about the system load and may be queried frequently.
The way in which the load average is calculated is operating system specific but is typically a damped time-dependent average. Linux includes processes waiting for system resources such as disks, while macOS and Unix consider only processes waiting for CPU.
Windows does not provide a load average. Users may set the configuration property
oshi.os.windows.loadaverage
totrue
to start a daemon thread which will provide a similar metric.The load average may be unavailable on some platforms (e.g., Windows without the above configuration). If the load average is not available, a negative value is returned.
- 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.
-
queryProcessorCpuLoadTicks
public long[][] queryProcessorCpuLoadTicks()
Description copied from class:AbstractCentralProcessor
Get the processor CPU load ticks- Specified by:
queryProcessorCpuLoadTicks
in classAbstractCentralProcessor
- Returns:
- The processor CPU load ticks
-
getProcessorID
private static java.lang.String getProcessorID(java.lang.String vendor, java.lang.String stepping, java.lang.String model, java.lang.String family, java.lang.String[] flags)
Fetches the ProcessorID from dmidecode (if possible with root permissions), the cpuid command (if installed) or by encoding the stepping, model, family, and feature flags.- Parameters:
vendor
- The vendorstepping
- The steppingmodel
- The modelfamily
- The familyflags
- The flags- Returns:
- The Processor ID string
-
createMIDR
private static java.lang.String createMIDR(java.lang.String vendor, java.lang.String stepping, java.lang.String model, java.lang.String family)
Creates the MIDR, the ARM equivalent of CPUID ProcessorID- Parameters:
vendor
- the CPU implementerstepping
- the "rnpn" variant and revisionmodel
- the partnumfamily
- the architecture- Returns:
- A 32-bit hex string for the MIDR
-
queryContextSwitches
public long queryContextSwitches()
Description copied from class:AbstractCentralProcessor
Get number of context switches- Specified by:
queryContextSwitches
in classAbstractCentralProcessor
- Returns:
- The context switches
-
queryInterrupts
public long queryInterrupts()
Description copied from class:AbstractCentralProcessor
Get number of interrupts- Specified by:
queryInterrupts
in classAbstractCentralProcessor
- Returns:
- The interrupts
-
-