Page 1 of 1

capturing IM processing time

Posted: 2010-06-21T12:02:13-07:00
by fmw42
In unix, anyone know how to capture the output from the time function to a string or file?


time convert logo: logo.gif

real 0m1.147s
user 0m0.054s
sys 0m0.069s

Re: capturing IM processing time

Posted: 2010-06-21T12:24:12-07:00
by zaratol
to File

( time convert logo: logo.gif ) 2> someReportFile.txt
or: /usr/bin/time -o someReportFile.txt convert logo: logo.gif

time -o won't work and with -o you have a different format of output

to Variable:

temp=$(
{ time convert logo: logo.gif 2>/dev/null
} 2>&1 > /dev/null )

temp=${temp#*real?}
seconds=${temp%?user*}

Re: capturing IM processing time

Posted: 2010-06-21T13:14:52-07:00
by fmw42
thanks zaratol. it works. but that is a bit more unix than I understand. Can you explain the use of the parens in

( time convert logo: logo.gif ) 2> someReportFile.txt

and the use of the braces in the following and why they seem to have to be on different lines

temp=$(
{ time convert logo: logo.gif 2>/dev/null
} 2>&1 > /dev/null )

Then I can go do some reading on those concepts.

Thanks

Fred

Re: capturing IM processing time

Posted: 2010-08-12T06:53:23-07:00
by zaratol
One concept used here is redirection of output:

http://tldp.org/LDP/abs/html/io-redirection.html

the other is subshells:

http://tldp.org/LDP/abs/html/subshells.html

to be honest, only understand the first example myself, but because i was curious i stumbled on the second example via google 8)

Re: capturing IM processing time

Posted: 2010-08-12T19:21:46-07:00
by anthony
zaratol wrote:to File

( time convert logo: logo.gif ) 2> someReportFile.txt
or: /usr/bin/time -o someReportFile.txt convert logo: logo.gif
The parenthesis is not needed.

The 2> redirect the error channel (file descriptor number 2) to a file for the given command which is 'time' not 'convert'. However as 'time' executes the given 'convert' command, its errors will be included in the error channel for 'time'.

This also means convert and time errors are merged! however as time only outputs its info AFTER the command is finished the time results will be AFTER any errors from convert.

Alternatives...
time_results=`time convert logo: logo.gif 2>&1`

The 2>&1 here merges the error channel (2) to the normal output channel (1) so that the backticks can capture it.

And here I use a sub-shell to junk any errors from the 'convert' from the output of time.

time_results=`time bash -c 'convert logo: logo.gif 2>/dev/null' 2>&1`