Class MacCentralProcessor
java.lang.Object
oshi.hardware.common.AbstractCentralProcessor
oshi.hardware.common.platform.mac.MacCentralProcessor
- All Implemented Interfaces:
CentralProcessor
Base class for macOS CentralProcessor implementations. Subclasses provide platform-specific sysctl, IOKit, and Mach
kernel calls.
-
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. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final intARM CPU type constant.protected static final longDefault frequency in Hz.protected static final intM1 CPU family constant.protected static final intM2 CPU family constant.protected static final intM3 CPU family constant.protected static final intM3 Pro/Max CPU family constant.protected static final intM4 CPU family constant. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidCalculates nominal frequencies for performance and efficiency cores.protected longGets the efficiency core frequency.protected longgetMaxFreqFromByteArray(byte[] data) Extracts the maximum frequency from a byte array property.protected longGets the performance core frequency.protected Quartet<List<CentralProcessor.LogicalProcessor>, List<CentralProcessor.PhysicalProcessor>, List<CentralProcessor.ProcessorCache>, List<String>> Initializes logical and physical processor lists and feature flags.protected abstract IOKitProviderReturns the IOKit provider for this implementation.protected booleanisArm()Checks if this is an ARM CPU.protected StringQueries the platform expert vendor string.Queries compatible strings for CPU identification.longGet number of context switcheslong[]Get processor current frequency.longGet number of interruptslongGet processor max frequency.protected CentralProcessor.ProcessorIdentifierUpdates logical and physical processor counts and arraysprotected voidsetEfficiencyCoreFrequency(long freq) Sets the efficiency core frequency.protected voidsetPerformanceCoreFrequency(long freq) Sets the performance core frequency.protected intQueries a sysctl integer value.protected intsysctlIntNoWarn(String name, int defaultValue) Queries a sysctl integer value without logging warnings.protected longsysctlLong(String name, long defaultValue) Queries a sysctl long value.protected abstract SysctlProviderReturns the sysctl provider for this implementation.protected StringsysctlString(String name, String defaultValue) Queries a sysctl string value.protected StringsysctlStringNoWarn(String name, String defaultValue) Queries a sysctl string value without logging warnings.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, queryProcessorCpuLoadTicks, querySystemCpuLoadTicks, 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 listprotected abstract long[][]Get the processor CPU load ticksprotected abstract long[]Get the system CPU load tickstoString()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface CentralProcessor
getProcessorCpuLoad, getSystemCpuLoad, getSystemLoadAverageModifier 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.double[]getSystemLoadAverage(int nelem) Returns the system load average for the number of elements specified, up to 3, representing 1, 5, and 15 minutes.
-
Field Details
-
ARM_CPUTYPE
protected static final int ARM_CPUTYPEARM CPU type constant.- See Also:
-
M1_CPUFAMILY
protected static final int M1_CPUFAMILYM1 CPU family constant.- See Also:
-
M2_CPUFAMILY
protected static final int M2_CPUFAMILYM2 CPU family constant.- See Also:
-
M3_CPUFAMILY
protected static final int M3_CPUFAMILYM3 CPU family constant.- See Also:
-
M3_PRO_CPUFAMILY
protected static final int M3_PRO_CPUFAMILYM3 Pro/Max CPU family constant.- See Also:
-
M4_CPUFAMILY
protected static final int M4_CPUFAMILYM4 CPU family constant.- See Also:
-
DEFAULT_FREQUENCY
protected static final long DEFAULT_FREQUENCYDefault frequency in Hz.- See Also:
-
-
Constructor Details
-
MacCentralProcessor
protected MacCentralProcessor()Default constructor.
-
-
Method Details
-
sysctlProvider
Returns the sysctl provider for this implementation.- Returns:
- the sysctl provider
-
sysctlInt
Queries a sysctl integer value.- Parameters:
name- the sysctl namedefaultValue- the default value if not found- Returns:
- the sysctl value
-
sysctlIntNoWarn
Queries a sysctl integer value without logging warnings.- Parameters:
name- the sysctl namedefaultValue- the default value if not found- Returns:
- the sysctl value
-
sysctlLong
Queries a sysctl long value.- Parameters:
name- the sysctl namedefaultValue- the default value if not found- Returns:
- the sysctl value
-
sysctlString
-
sysctlStringNoWarn
-
ioKitProvider
Returns the IOKit provider for this implementation.- Returns:
- the IOKit provider
-
platformExpert
Queries the platform expert vendor string.- Returns:
- the vendor string
-
queryCompatibleStrings
-
calculateNominalFrequencies
protected void calculateNominalFrequencies()Calculates nominal frequencies for performance and efficiency cores. -
getPerformanceCoreFrequency
protected long getPerformanceCoreFrequency()Gets the performance core frequency.- Returns:
- the performance core frequency in Hz
-
setPerformanceCoreFrequency
protected void setPerformanceCoreFrequency(long freq) Sets the performance core frequency.- Parameters:
freq- the frequency in Hz
-
getEfficiencyCoreFrequency
protected long getEfficiencyCoreFrequency()Gets the efficiency core frequency.- Returns:
- the efficiency core frequency in Hz
-
setEfficiencyCoreFrequency
protected void setEfficiencyCoreFrequency(long freq) Sets the efficiency core frequency.- Parameters:
freq- the frequency in Hz
-
isArm
protected boolean isArm()Checks if this is an ARM CPU.- Returns:
- true if ARM
-
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.
-
queryCurrentFreq
public long[] queryCurrentFreq()Description copied from class:AbstractCentralProcessorGet processor current frequency.- Specified by:
queryCurrentFreqin classAbstractCentralProcessor- Returns:
- The current frequency.
-
queryMaxFreq
public long queryMaxFreq()Description copied from class:AbstractCentralProcessorGet processor max frequency.- Overrides:
queryMaxFreqin classAbstractCentralProcessor- Returns:
- The max frequency.
-
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
-
getMaxFreqFromByteArray
protected long getMaxFreqFromByteArray(byte[] data) Extracts the maximum frequency from a byte array property.- Parameters:
data- the byte array from IOKit- Returns:
- the frequency in Hz, or DEFAULT_FREQUENCY if unavailable
-