From b8a3cde988f4bbacba800d058580d51e4d55e336 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Thu, 2 Mar 2006 00:25:24 +0000 Subject: [PATCH] add main method to test CpuPerc --- .../src/net/hyperic/sigar/test/TestCpu.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/bindings/java/src/net/hyperic/sigar/test/TestCpu.java b/bindings/java/src/net/hyperic/sigar/test/TestCpu.java index e31dea04..58de6427 100644 --- a/bindings/java/src/net/hyperic/sigar/test/TestCpu.java +++ b/bindings/java/src/net/hyperic/sigar/test/TestCpu.java @@ -3,6 +3,7 @@ package net.hyperic.sigar.test; import net.hyperic.sigar.Sigar; import net.hyperic.sigar.SigarNotImplementedException; import net.hyperic.sigar.Cpu; +import net.hyperic.sigar.CpuPerc; public class TestCpu extends SigarTestCase { @@ -45,4 +46,39 @@ public class TestCpu extends SigarTestCase { //ok } } + + private static void printCpu(String prefix, CpuPerc cpu) { + System.out.println(prefix + + CpuPerc.format(cpu.getUser()) + "\t" + + CpuPerc.format(cpu.getSys()) + "\t" + + CpuPerc.format(cpu.getWait()) + "\t" + + CpuPerc.format(cpu.getNice()) + "\t" + + CpuPerc.format(cpu.getIdle()) + "\t" + + CpuPerc.format(cpu.getCombined())); + } + + public static void main(String[] args) throws Exception { + final String HEADER = + " User\tSys\tWait\tNice\tIdle\tTotal"; + int interval = 1; + if (args.length > 0) { + interval = Integer.parseInt(args[0]); + } + int sleep = 1000 * 60 * interval; + + Sigar sigar = new Sigar(); + + while (true) { + System.out.println(HEADER); + + printCpu(" ", sigar.getCpuPerc()); + + CpuPerc[] cpuList = sigar.getCpuPercList(); + + for (int i=0; i