catch getProcCpu

This commit is contained in:
Doug MacEachern 2005-06-16 21:27:54 +00:00
parent d182f89671
commit a20b334406
1 changed files with 10 additions and 4 deletions

View File

@ -3,6 +3,7 @@ package net.hyperic.sigar.cmd;
import java.util.List; import java.util.List;
import net.hyperic.sigar.Sigar; import net.hyperic.sigar.Sigar;
import net.hyperic.sigar.SigarException;
import net.hyperic.sigar.SigarProxy; import net.hyperic.sigar.SigarProxy;
import net.hyperic.sigar.CpuPerc; import net.hyperic.sigar.CpuPerc;
import net.hyperic.sigar.SigarProxyCache; import net.hyperic.sigar.SigarProxyCache;
@ -56,11 +57,16 @@ public class Top {
for (int i=0; i<pids.length; i++) { for (int i=0; i<pids.length; i++) {
long pid = pids[i]; long pid = pids[i];
ProcCpu cpu = sigar.getProcCpu(pid); String cpuPerc = "?";
List info = Ps.getInfo(sigar, pid);
info.add(info.size()-1, List info = Ps.getInfo(sigar, pid);
CpuPerc.format(cpu.getPercent())); try {
ProcCpu cpu = sigar.getProcCpu(pid);
cpuPerc = CpuPerc.format(cpu.getPercent());
} catch (SigarException e) {
}
info.add(info.size()-1, cpuPerc);
System.out.println(Ps.join(info)); System.out.println(Ps.join(info));
} }