📄 sigarcpuinfo.java
字号:
/* * SigarCpuInfo.java * * Created on March 14, 2005, 12:25 PM */package net.hyperic.sigar.cmd;import net.hyperic.sigar.CpuInfo;import net.hyperic.sigar.CpuPerc;import net.hyperic.sigar.SigarException;/** * * @author Sean */public class SigarCpuInfo extends SigarCommandBase { private int _cpuInfoIndex; private int _cpuPercIndex; /** Creates a new instance of SigarCpuInfo */ public SigarCpuInfo() { super(); resetIterators(); } /** * */ public void resetIterators() { _cpuInfoIndex = 0; _cpuPercIndex = 0; } /** * */ public int getCpuCount() throws SigarException { net.hyperic.sigar.CpuInfo[] cpuInfoArr; try { cpuInfoArr = this.sigar.getCpuInfoList(); } catch (SigarException e) { throw e; } return cpuInfoArr.length; } /** * */ public net.hyperic.sigar.CpuInfo getCpuInfo(int iIndex) throws SigarException { net.hyperic.sigar.CpuInfo[] cpuInfoArr; try { cpuInfoArr = this.sigar.getCpuInfoList(); } catch (SigarException e) { throw e; } if (iIndex < 0 || iIndex > cpuInfoArr.length || cpuInfoArr.length ==0) { return null; } return cpuInfoArr[iIndex]; } /** * */ public net.hyperic.sigar.CpuInfo getNextCpuInfo() throws SigarException { net.hyperic.sigar.CpuInfo cpuInfo; try { cpuInfo = getCpuInfo(_cpuInfoIndex); } catch (SigarException e) { _cpuInfoIndex = 0; throw e; } if (cpuInfo == null) { _cpuInfoIndex = 0; return null; } _cpuInfoIndex++; return cpuInfo; } /** * */ public net.hyperic.sigar.CpuPerc getCpuPerc(int iIndex) throws SigarException { net.hyperic.sigar.CpuPerc[] cpuPercArr; try { cpuPercArr = this.sigar.getCpuPercList(); } catch (SigarException e) { throw e; } if (iIndex < 0 || iIndex > cpuPercArr.length || cpuPercArr.length == 0) { return null; } return cpuPercArr[iIndex]; } /** * */ public net.hyperic.sigar.CpuPerc getNextCpuPerc() throws SigarException { net.hyperic.sigar.CpuPerc cpuPerc; try { cpuPerc = getCpuPerc(_cpuPercIndex); } catch (SigarException e) { _cpuPercIndex = 0; throw e; } if (cpuPerc == null) { _cpuPercIndex = 0; return null; } _cpuPercIndex++; return cpuPerc; } /** * output cpu info to stdout */ public void output() throws SigarException { try { output(null); } catch (SigarException e) { throw e; } } /** * output cpu info to stdout */ public void output(String[] args) throws SigarException { net.hyperic.sigar.CpuPerc cpuPerc; net.hyperic.sigar.CpuInfo cpuInfo; try { for (int iIndex=0; iIndex<getCpuCount(); iIndex++ ) { cpuInfo = getCpuInfo(iIndex); cpuPerc = getCpuPerc(iIndex); println("Vendor........" + cpuInfo.getVendor()); println("Model........." + cpuInfo.getModel()); println("Mhz..........." + cpuInfo.getMhz()); println("Cache size...." + cpuInfo.getCacheSize()); println("User Time....." + CpuPerc.format(cpuPerc.getUser())); println("Sys Time......" + CpuPerc.format(cpuPerc.getSys())); println("Idle Time....." + CpuPerc.format(cpuPerc.getIdle())); println(""); } } catch (SigarException e) { throw e; } } public static void main( String[] args ) { try { SigarCpuInfo cpuInfo = new SigarCpuInfo(); cpuInfo.output(); } catch ( Exception ex ) { System.out.println( ex.getMessage() ); } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -