Pages

Tuesday, August 6, 2013

Find Out How Much Time the Command Or Code was taking, or Running?

Share it Please
The Time command in linux acts as Stopwatch. It provides us various forms of information on how much time the command took to run.

The Time command generates 3 kinds of output.

Real : This is the amount of time between when the command was started and completed its execution.
user : This is the time CPU took for executing the application code on behalf of the application.
sys : This is the time CPU took for executing the system code or kernel code.

real 0m0.014s ([hours:] minutes : seconds)
user 0m0.000s
sys 0m0.004s

The Time Command Displays more information besides the elapsed time .

As basic example would be,

Dev:remoteMach:root002 $ /usr/bin/time -v tomcatstop.sh ABC-A1
Base is /config/jboss/ews/1.0/domains/abc/ABC-A1
Home is /software/jboss/ews32/1.0
Stopping JBoss EWS....
Catalina Home from SetEnv: /software/jboss/ews32/1.0
Catalina Base from SetEnv: /config/jboss/ews/1.0/domains/abc/ABC-A1
Java Lib Path: /software/jboss/ews32/1.0/lib:/software/jboss/ews32/1.0/lib:
Logging path: /logs/jboss/ews/1.0/domains/abc
Implementation Environment: dev
Using CATALINA_BASE: /config/jboss/ews/1.0/domains/abc/ABC-A1
Using CATALINA_HOME: /software/jboss/ews32/1.0
Using CATALINA_TMPDIR: /config/jboss/ews/1.0/domains/abc/ABC-A1/temp
Using JRE_HOME: /software/java32/jdk1.6.0_16
JAVA_OPTS: -Djbs.name=ABC-A1 -server -Xms256m -Xmx256m -XX:MaxPermSize=128m -XX:+PrintGC ***************************

Command being timed: "tomcatstop.sh ABC-A1"
User time (seconds): 1.52
System time (seconds): 0.15
Percent of CPU this job got: 108%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:01.55
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 113328
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 1
Minor (reclaiming a frame) page faults: 10294
Voluntary context switches: 103
Involuntary context switches: 216
Swaps: 0
File system inputs: 0
File system outputs: 0
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0

The Options Include,

User time (seconds) : This is the number of seconds of CPU spent by the application.
System time (seconds) : This is the number of seconds spent in the Linux kernel on behalf of the application.
Elapsed (wall-clock) time (h:mm:ss or m:ss) : This is the amount of time elapsed (in wall-clock time) between when the application was launched and when it completed.
Percent of CPU this job got : This is the percentage of the CPU that the process consumed as it was running.
Major (requiring I/O) page faults : The number of major page faults or those that required a page of memory to be read from disk.
Minor (reclaiming a frame) page faults : The number of minor page faults or those that could be filled without going to disk.
Swaps : This is the number of times the process was swapped to disk.
Voluntary context switches : The number of times the process yielded the CPU (for example, by going to sleep).
Involuntary context switches: The number of times the CPU was taken from the process.
Page size (bytes) : The page size of the system.
Exit status : The exit status of the application

By Using the Time command we can find out how much time an application or a process from starting to completion.