Class LinuxCentralProcessor
java.lang.Object
oshi.hardware.common.AbstractCentralProcessor
oshi.hardware.common.platform.linux.LinuxCentralProcessor
- All Implemented Interfaces:
CentralProcessor
- Direct Known Subclasses:
LinuxCentralProcessorNF
A CPU as defined in Linux /proc.
-
Nested Class Summary
Nested classes/interfaces inherited from interface CentralProcessor
CentralProcessor.LogicalProcessor, CentralProcessor.PhysicalProcessor, CentralProcessor.ProcessorCache, CentralProcessor.ProcessorIdentifier, CentralProcessor.TickTypeModifier and TypeInterfaceDescriptionstatic classA class representing a Logical Processor and its replationship to physical processors, physical packages, and logical groupings such as NUMA Nodes and Processor groups, useful for identifying processor topology.static classA class representing a Physical Processor (a core) providing per-core statistics that may vary, particularly in hybrid/modular processors.static classA class representing CPU Cache Memory.static final classA class encapsulating ghe CPU's identifier strings ,including name, vendor, stepping, model, and family information (also called the signature of a CPU)static enumIndex of CPU tick counters in theCentralProcessor.getSystemCpuLoadTicks()andCentralProcessor.getProcessorCpuLoadTicks()arrays. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected static CentralProcessor.LogicalProcessorgetLogicalProcessorFromSyspath(String syspath, Set<CentralProcessor.ProcessorCache> caches, String modAlias, Map<Integer, Integer> coreEfficiencyMap, Map<Integer, String> modAliasMap) getLogicalProcessorFromSyspath.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<List<CentralProcessor.LogicalProcessor>, List<CentralProcessor.PhysicalProcessor>, List<CentralProcessor.ProcessorCache>, List<String>> Initializes logical and physical processor lists and feature flags.longGet number of context switcheslong[]Get processor current frequency.protected static booleanqueryCurrentFreqFromSysfs(long[] freqs) queryCurrentFreqFromSysfs.protected abstract booleanqueryCurrentFreqFromUdev(long[] freqs) Fills the freqs array from udev cpu-freq source.protected longQueries the hardware capabilities from the auxiliary vector.longGet number of interruptslongGet processor max frequency.protected static longqueryMaxFreqFromCpuFreqPath(String cpuFreqPath) Queries the maximum frequency from a cpufreq path.protected static longQueries the maximum frequency from sysfs.protected abstract longQueries the maximum frequency from udev.long[][]Get the processor CPU load ticksprotected CentralProcessor.ProcessorIdentifierUpdates logical and physical processor counts and arrayslong[]Get the system CPU load ticksprotected static Quartet<List<CentralProcessor.LogicalProcessor>, List<CentralProcessor.ProcessorCache>, Map<Integer, Integer>, Map<Integer, String>> Reads processor topology from sysfs using the default CPU path.protected abstract Quartet<List<CentralProcessor.LogicalProcessor>, List<CentralProcessor.ProcessorCache>, Map<Integer, Integer>, Map<Integer, String>> Reads processor topology using udev.Methods inherited from class AbstractCentralProcessor
createProcessorID, createProcessorID, createProcListFromDmesg, getContextSwitches, getCurrentFreq, getFeatureFlags, getInterrupts, getLogicalProcessorCount, getLogicalProcessors, getMaxFreq, getPhysicalPackageCount, getPhysicalProcessorCount, getPhysicalProcessors, getProcessorCaches, getProcessorCpuLoadBetweenTicks, getProcessorCpuLoadBetweenTicks, getProcessorCpuLoadTicks, getProcessorIdentifier, getSystemCpuLoadBetweenTicks, getSystemCpuLoadBetweenTicks, getSystemCpuLoadTicks, orderedProcCaches, toStringModifier 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 static StringcreateProcessorID(String stepping, String model, String family, String[] flags, long hwcap) 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) Creates a list of physical processors from dmesg output.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.double[]getProcessorCpuLoadBetweenTicks(long[][] oldTicks, long[][] ticks) 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.doublegetSystemCpuLoadBetweenTicks(long[] oldTicks, long[] ticks) Returns the "recent cpu usage" for the whole system by counting ticks between two user-provided values, retrieved fromCentralProcessor.getSystemCpuLoadTicks()at different points in time.long[]Get System-wide CPU Load tick counters.static List<CentralProcessor.ProcessorCache> Filters a set of processor caches to an ordered listtoString()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface CentralProcessor
getProcessorCpuLoad, getSystemCpuLoadModifier and TypeMethodDescriptiondefault double[]getProcessorCpuLoad(long delay) This is a convenience method which collects an initial set of ticks usingCentralProcessor.getProcessorCpuLoadTicks()and passes that result toCentralProcessor.getProcessorCpuLoadBetweenTicks(long[][])after the specified delay.default doublegetSystemCpuLoad(long delay) This is a convenience method which collects an initial set of ticks usingCentralProcessor.getSystemCpuLoadTicks()and passes that result toCentralProcessor.getSystemCpuLoadBetweenTicks(long[])after the specified delay.
-
Constructor Details
-
LinuxCentralProcessor
protected LinuxCentralProcessor(long hz) LinuxCentralProcessor.- Parameters:
hz- the hz
-
-
Method Details
-
queryProcessorId
Description copied from class:AbstractCentralProcessorUpdates logical and physical processor counts and arrays- Specified by:
queryProcessorIdin classAbstractCentralProcessor- Returns:
- An array of initialized Logical Processors
-
initProcessorCounts
protected Quartet<List<CentralProcessor.LogicalProcessor>, List<CentralProcessor.PhysicalProcessor>, List<CentralProcessor.ProcessorCache>, List<String>> initProcessorCounts()Description copied from class:AbstractCentralProcessorInitializes logical and physical processor lists and feature flags.- Specified by:
initProcessorCountsin classAbstractCentralProcessor- Returns:
- Lists of initialized Logical Processors, Physical Processors, Processor Caches, and Feature Flags.
-
readTopologyWithUdev
-
readTopologyFromSysfs
protected static Quartet<List<CentralProcessor.LogicalProcessor>, List<CentralProcessor.ProcessorCache>, Map<Integer,Integer>, Map<Integer, readTopologyFromSysfs()String>> Reads processor topology from sysfs using the default CPU path.- Returns:
- a quartet of logical processors, caches, efficiency map, and modalias map
-
getLogicalProcessorFromSyspath
protected static CentralProcessor.LogicalProcessor getLogicalProcessorFromSyspath(String syspath, Set<CentralProcessor.ProcessorCache> caches, String modAlias, Map<Integer, Integer> coreEfficiencyMap, Map<Integer, String> modAliasMap) getLogicalProcessorFromSyspath.- Parameters:
syspath- the syspathcaches- the cachesmodAlias- the modAliascoreEfficiencyMap- the coreEfficiencyMapmodAliasMap- the modAliasMap- Returns:
- a LogicalProcessor for the given syspath
-
querySystemCpuLoadTicks
public long[] querySystemCpuLoadTicks()Description copied from class:AbstractCentralProcessorGet the system CPU load ticks- Specified by:
querySystemCpuLoadTicksin classAbstractCentralProcessor- Returns:
- The system CPU load ticks
-
queryCurrentFreq
public long[] queryCurrentFreq()Description copied from class:AbstractCentralProcessorGet processor current frequency.- Specified by:
queryCurrentFreqin classAbstractCentralProcessor- Returns:
- The current frequency.
-
queryCurrentFreqFromUdev
protected abstract boolean queryCurrentFreqFromUdev(long[] freqs) Fills the freqs array from udev cpu-freq source. Returns true if successful (max > 0). Subclasses provide the implementation.- Parameters:
freqs- array to fill with per-logical-processor frequencies in Hz- Returns:
- true if frequencies were successfully read
-
queryCurrentFreqFromSysfs
protected static boolean queryCurrentFreqFromSysfs(long[] freqs) queryCurrentFreqFromSysfs.- Parameters:
freqs- the freqs- Returns:
- the result
-
queryMaxFreq
public long queryMaxFreq()Description copied from class:AbstractCentralProcessorGet processor max frequency.- Overrides:
queryMaxFreqin classAbstractCentralProcessor- Returns:
- The max frequency.
-
queryMaxFreqFromUdev
protected abstract long queryMaxFreqFromUdev()Queries the maximum frequency from udev.- Returns:
- the maximum frequency in Hz
-
queryMaxFreqFromSysfs
protected static long queryMaxFreqFromSysfs()Queries the maximum frequency from sysfs.- Returns:
- the maximum frequency in Hz
-
queryMaxFreqFromCpuFreqPath
Queries the maximum frequency from a cpufreq path.- Parameters:
cpuFreqPath- the cpufreq directory path- Returns:
- the maximum frequency in Hz
-
getSystemLoadAverage
public double[] getSystemLoadAverage(int nelem) Description copied from interface:CentralProcessorReturns 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.loadaveragetotrueto 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:AbstractCentralProcessorGet the processor CPU load ticks- Specified by:
queryProcessorCpuLoadTicksin classAbstractCentralProcessor- Returns:
- The processor CPU load ticks
-
queryHwcap
protected long queryHwcap()Queries the hardware capabilities from the auxiliary vector. Subclasses provide platform-specific implementations using JNA or FFM native access.- Returns:
- The hardware capabilities value, or 0 if unavailable
-
queryContextSwitches
public long queryContextSwitches()Description copied from class:AbstractCentralProcessorGet number of context switches- Specified by:
queryContextSwitchesin classAbstractCentralProcessor- Returns:
- The context switches
-
queryInterrupts
public long queryInterrupts()Description copied from class:AbstractCentralProcessorGet number of interrupts- Specified by:
queryInterruptsin classAbstractCentralProcessor- Returns:
- The interrupts
-