sigar/bindings/java/src/org/hyperic/sigar/cmd/CpuInfo.java
Doug MacEachern e472dc9d9a add copyright
2006-07-15 17:46:36 +00:00

91 lines
2.7 KiB
Java

/*
* Copyright (C) [2004, 2005, 2006], Hyperic, Inc.
* This file is part of SIGAR.
*
* SIGAR is free software; you can redistribute it and/or modify
* it under the terms version 2 of the GNU General Public License as
* published by the Free Software Foundation. This program is distributed
* in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*/
package org.hyperic.sigar.cmd;
import org.hyperic.sigar.CpuPerc;
import org.hyperic.sigar.Sigar;
import org.hyperic.sigar.SigarException;
/**
* Display cpu information for each cpu found on the system.
*/
public class CpuInfo extends SigarCommandBase {
public boolean displayTimes = true;
public CpuInfo(Shell shell) {
super(shell);
}
public CpuInfo() {
super();
}
public String getUsageShort() {
return "Display cpu information";
}
private void output(CpuPerc cpu) {
println("User Time....." + CpuPerc.format(cpu.getUser()));
println("Sys Time......" + CpuPerc.format(cpu.getSys()));
println("Idle Time....." + CpuPerc.format(cpu.getIdle()));
println("Wait Time....." + CpuPerc.format(cpu.getWait()));
println("Nice Time....." + CpuPerc.format(cpu.getNice()));
println("Combined......" + CpuPerc.format(cpu.getCombined()));
println("");
}
public void output(String[] args) throws SigarException {
org.hyperic.sigar.CpuInfo[] infos =
this.sigar.getCpuInfoList();
CpuPerc[] cpus = null;
println(infos.length + " total CPUs..");
org.hyperic.sigar.CpuInfo info = infos[0];
long cacheSize = info.getCacheSize();
println("Vendor........" + info.getVendor());
println("Model........." + info.getModel());
println("Mhz..........." + info.getMhz());
if (cacheSize != Sigar.FIELD_NOTIMPL) {
println("Cache size...." + cacheSize);
}
println("");
if (!this.displayTimes) {
return;
}
for (int i=0; i<infos.length; i++) {
println("CPU " + i + ".........");
if (cpus == null) {
cpus = this.sigar.getCpuPercList();
}
output(cpus[i]);
}
println("Totals........");
output(this.sigar.getCpuPerc());
}
public static void main(String[] args) throws Exception {
new CpuInfo().processCommand(args);
}
}