Record Class CpuInfo
java.lang.Object
java.lang.Record
cloud.opencode.base.core.system.CpuInfo
- Record Components:
availableProcessors- number of available processors - 可用处理器数量arch- processor architecture (e.g. "amd64", "aarch64") - 处理器架构systemCpuLoad- system-wide CPU load [0.0, 1.0], or -1 if unavailable - 系统 CPU 负载processCpuLoad- JVM process CPU load [0.0, 1.0], or -1 if unavailable - 进程 CPU 负载loadAverage- 1/5/15 minute load averages; empty array on unsupported platforms - 1/5/15 分钟平均负载
public record CpuInfo(int availableProcessors, String arch, double systemCpuLoad, double processCpuLoad, double[] loadAverage)
extends Record
Immutable snapshot of CPU information.
CPU 信息的不可变快照。
Captures processor count, architecture, and current load metrics at the
time of creation. Load values may be -1 if the underlying OS does
not expose them.
捕获创建时的处理器数量、架构和当前负载指标。如果底层操作系统不公开负载值,
则可能为 -1。
Usage Examples | 使用示例:
CpuInfo cpu = SystemInfo.cpu();
System.out.println("Processors: " + cpu.availableProcessors());
System.out.println("Arch: " + cpu.archDisplay());
System.out.println("System load: " + cpu.systemCpuLoad());
- Since:
- JDK 25, opencode-base-core V1.0.3
- Author:
- Leon Soo
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionarch()Returns the value of thearchrecord component.Returns a display-friendly architecture name.intReturns the value of theavailableProcessorsrecord component.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.booleanChecks whether load average data is available.double[]Returns a defensive copy of the load average array.doubleReturns the value of theprocessCpuLoadrecord component.doubleReturns the value of thesystemCpuLoadrecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
CpuInfo
public CpuInfo(int availableProcessors, String arch, double systemCpuLoad, double processCpuLoad, double[] loadAverage) Compact canonical constructor with validation and defensive copy. 带验证和防御性复制的紧凑规范构造器。
-
-
Method Details
-
loadAverage
public double[] loadAverage()Returns a defensive copy of the load average array. 返回平均负载数组的防御性副本。- Returns:
- copy of load average values
-
isLoadAvailable
public boolean isLoadAvailable()Checks whether load average data is available. 检查平均负载数据是否可用。- Returns:
trueif load average contains at least one value
-
archDisplay
Returns a display-friendly architecture name. 返回用户友好的架构名称。Normalizes common architecture names:
- "amd64" → "x86_64"
- "x86" → "x86_32"
- Returns:
- the display architecture name
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
availableProcessors
public int availableProcessors()Returns the value of theavailableProcessorsrecord component.- Returns:
- the value of the
availableProcessorsrecord component
-
arch
-
systemCpuLoad
public double systemCpuLoad()Returns the value of thesystemCpuLoadrecord component.- Returns:
- the value of the
systemCpuLoadrecord component
-
processCpuLoad
public double processCpuLoad()Returns the value of theprocessCpuLoadrecord component.- Returns:
- the value of the
processCpuLoadrecord component
-