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 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:
      true if load average contains at least one value
    • archDisplay

      public String archDisplay()
      Returns a display-friendly architecture name. 返回用户友好的架构名称。

      Normalizes common architecture names:

      • "amd64" → "x86_64"
      • "x86" → "x86_32"
      Returns:
      the display architecture name
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • availableProcessors

      public int availableProcessors()
      Returns the value of the availableProcessors record component.
      Returns:
      the value of the availableProcessors record component
    • arch

      public String arch()
      Returns the value of the arch record component.
      Returns:
      the value of the arch record component
    • systemCpuLoad

      public double systemCpuLoad()
      Returns the value of the systemCpuLoad record component.
      Returns:
      the value of the systemCpuLoad record component
    • processCpuLoad

      public double processCpuLoad()
      Returns the value of the processCpuLoad record component.
      Returns:
      the value of the processCpuLoad record component