package net.hyperic.sigar.cmd;

import net.hyperic.sigar.CpuPerc;
import net.hyperic.sigar.Sigar;
import net.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";
    }

    public void output(String[] args) throws SigarException {
        net.hyperic.sigar.CpuInfo[] infos =
            this.sigar.getCpuInfoList();

        CpuPerc[] cpus = null;

        println(infos.length + " total CPUs..");
        net.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);
        }

        if (!this.displayTimes) {
            return;
        }

        for (int i=0; i<infos.length; i++) {
            if (cpus == null) {
                cpus = this.sigar.getCpuPercList();
            }
            CpuPerc cpu = cpus[i];
            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 static void main(String[] args) throws Exception {
        new CpuInfo().processCommand(args);
    }
}

@@ -483,32 +483,504 @@
 mation%22;%0A    %7D%0A%0A
+    private void output(CpuPerc cpu) %7B%0A        println(%22User Time.....%22 + CpuPerc.format(cpu.getUser()));%0A        println(%22Sys Time......%22 + CpuPerc.format(cpu.getSys()));%0A        println(%22Idle Time.....%22 + CpuPerc.format(cpu.getIdle()));%0A        println(%22Wait Time.....%22 + CpuPerc.format(cpu.getWait()));%0A        println(%22Nice Time.....%22 + CpuPerc.format(cpu.getNice()));%0A        println(%22Combined......%22 + CpuPerc.format(cpu.getCombined()));%0A        println(%22%22);%0A    %7D%0A%0A
     public void 
@@ -1017,32 +1017,32 @@
 igarException %7B%0A
-
         net.hype
@@ -1547,32 +1547,53 @@
 Size);%0A        %7D
+%0A        println(%22%22);
 %0A%0A        if (!t
@@ -1684,24 +1684,71 @@
 gth; i++) %7B%0A
+            println(%22CPU %22 + i + %22.........%22);%0A
             
@@ -1849,29 +1849,23 @@
     
-CpuPerc cpu = 
+output(
 cpus%5Bi%5D
+)
 ;%0A  
@@ -1874,209 +1874,43 @@
     
-  
-  println(%22User Time.....%22 + CpuPerc.format(cpu.getUser()));%0A            println(%22Sys Time......%22 + CpuPerc.format(cpu.getSys()));%0A            println(%22Idle Time.....%22 + CpuPerc.format(cpu.getIdle())
+%7D%0A%0A        println(%22Totals........%22
 );%0A 
@@ -1920,264 +1920,40 @@
     
-  
-  println(%22Wait Time.....%22 + CpuPerc.format(cpu.getWait()));%0A            println(%22Nice Time.....%22 + CpuPerc.format(cpu.getNice()));%0A            println(%22Combined......%22 + CpuPerc.format(cpu.getCombined()));%0A            %0A            println(%22%22);%0A        %7D
+output(this.sigar.getCpuPerc());
 %0A   

include totals from Sigar.getCpuPerc()