package net.hyperic.sigar.cmd;

import net.hyperic.sigar.Sigar;
import net.hyperic.sigar.SigarException;
import net.hyperic.sigar.ThreadCpu;

public class Time extends SigarCommandBase {

    public Time(Shell shell) {
        super(shell);
    }

    public Time() {
        super();
    }

    protected boolean validateArgs(String[] args) {
        return args.length >= 1;
    }

    public String getSyntaxArgs() {
        return "[command] [...]";
    }

    public String getUsageShort() {
        return "Time command";
    }

    public void output(String[] args) throws SigarException {
        ThreadCpu cpu = new ThreadCpu();
        long start = System.currentTimeMillis();

        this.shell.handleCommand("time " + args[0], args);

        cpu.gather(this.sigar, 0);
        System.out.println("real....." +
                           (System.currentTimeMillis() - start) / 1000);
        System.out.println("user....." + toMillis(cpu.getUser()));
        System.out.println("sys......" + toMillis(cpu.getSys()));
        System.out.println("total...." + toMillis(cpu.getTotal()));
    }

    private static long toMillis(long nano) {
        return nano / 1000000;
    }

    public static void main(String[] args) throws Exception {
        new Time().processCommand(args);
    }
}

@@ -780,35 +780,24 @@
 0);%0A        
-System.out.
 println(%22rea
@@ -822,27 +822,23 @@
         
-           
+format(
 (System.
@@ -865,23 +865,17 @@
 - start)
- / 1000
+)
 );%0A     
@@ -873,35 +873,24 @@
 ));%0A        
-System.out.
 println(%22use
@@ -891,32 +891,39 @@
 n(%22user.....%22 + 
+format(
 toMillis(cpu.get
@@ -926,24 +926,25 @@
 .getUser()))
+)
 ;%0A        Sy
@@ -937,35 +937,24 @@
 ));%0A        
-System.out.
 println(%22sys
@@ -955,32 +955,39 @@
 n(%22sys......%22 + 
+format(
 toMillis(cpu.get
@@ -997,76 +997,93 @@
 ()))
+)
 ;%0A    
+%7D%0A%0A
     
-System.out.println(%22total....%22 + toMillis(cpu.getTotal()))
+private static long toMillis(long nano) %7B%0A        return nano / 1000000
 ;%0A  
@@ -1106,39 +1106,36 @@
  static 
-long toMillis
+String format
 (long 
-nano
+t
 ) %7B%0A    
@@ -1138,36 +1138,58 @@
         
-return nano
+t
  /
+=
  1000
-00
+;%0A        return t/60 + %22:%22 + t%256
 0;%0A    %7D

format time