How to output 'time' to file ?

How to output 'time' to file ?

Post by moon » Sat, 11 Feb 2006 14:57:35



How to output time output to file ?

# time mpstat
CPU minf mjf xcal  intr ithr  csw icsw migr smtx  srw syscl  usr sys  wt idl
  0   18  15 1633   104   99  133    4    6   16    0   937    6   5  23  65
  1   17  17 1508   154  150  134    3    6   16    0   932    6   4  23  67
  2   17  17 1868   167  162  134    4    6   17    0   937    7   6  25  63
  3   18  10 1054   825  616  109    3    5   16    0   929    5   4  15  76

real    0m0.02s
user    0m0.01s
sys     0m0.01s

I want output real, user, sys to file.

 
 
 

How to output 'time' to file ?

Post by matt_left_coas » Sat, 11 Feb 2006 15:26:40



> How to output time output to file ?

> # time mpstat
> CPU minf mjf xcal  intr ithr  csw icsw migr smtx  srw syscl  usr sys  wt
> idl
>   0   18  15 1633   104   99  133    4    6   16    0   937    6   5  23
>   65
>   1   17  17 1508   154  150  134    3    6   16    0   932    6   4  23
>   67
>   2   17  17 1868   167  162  134    4    6   17    0   937    7   6  25
>   63
>   3   18  10 1054   825  616  109    3    5   16    0   929    5   4  15
>   76

> real    0m0.02s
> user    0m0.01s
> sys     0m0.01s

> I want output real, user, sys to file.

If real user and sys are always the last 3 lines one way would be:

time mpstat | tail -3 > file

--

 
 
 

How to output 'time' to file ?

Post by cro.. » Sat, 11 Feb 2006 23:24:48


I think you need to sub-shell it like this:

(time ls) 2>&1 | \
      awk ' /real/ || /user/ || /sys/ { printf("%s ", $NF)  } END {
print "\n" } '

This will give you just the values on 1 line.
________________________________________________
TechRock
+-.                         .
|  |  .-.   .--  |  /     _/ \_
+-.  |   | |     +-.     \     /
|  \  ._.   .__  |  \    /_   _\
|   \_____________________ \./   s.homedns.org
by goldenfeather.com.au

 
 
 

How to output 'time' to file ?

Post by Chris F.A. Johnso » Sun, 12 Feb 2006 01:57:25



> How to output time output to file ?

> # time mpstat
> CPU minf mjf xcal  intr ithr  csw icsw migr smtx  srw syscl  usr sys  wt idl
>   0   18  15 1633   104   99  133    4    6   16    0   937    6   5  23  65
>   1   17  17 1508   154  150  134    3    6   16    0   932    6   4  23  67
>   2   17  17 1868   167  162  134    4    6   17    0   937    7   6  25  63
>   3   18  10 1054   825  616  109    3    5   16    0   929    5   4  15  76

> real    0m0.02s
> user    0m0.01s
> sys     0m0.01s

> I want output real, user, sys to file.

( time mpstat ) 2> FILE

--
   Chris F.A. Johnson, author   |    <http://cfaj.freeshell.org>
   Shell Scripting Recipes:     |  My code in this post, if any,
   A Problem-Solution Approach  |          is released under the
   2005, Apress                 |     GNU General Public Licence

 
 
 

How to output 'time' to file ?

Post by moon » Tue, 14 Feb 2006 10:47:54


Thank. It works. Then 2> for error output ?

Quote:>( time mpstat ) 2> FILE

CPU minf mjf xcal  intr ithr  csw icsw migr smtx  srw syscl  usr sys  wt idl
  0  233  10    0   157   57   76    8    0    0    0   142   14  15   7  64

Quote:>cat FILE

real    0m0.10s
user    0m0.01s
sys     0m0.04s
ux2 /mfgusers/eric>




>> How to output time output to file ?

>> # time mpstat
>> CPU minf mjf xcal  intr ithr  csw icsw migr smtx  srw syscl  usr sys  wt
>> idl
>>   0   18  15 1633   104   99  133    4    6   16    0   937    6   5  23
>> 65
>>   1   17  17 1508   154  150  134    3    6   16    0   932    6   4  23
>> 67
>>   2   17  17 1868   167  162  134    4    6   17    0   937    7   6  25
>> 63
>>   3   18  10 1054   825  616  109    3    5   16    0   929    5   4  15
>> 76

>> real    0m0.02s
>> user    0m0.01s
>> sys     0m0.01s

>> I want output real, user, sys to file.

> ( time mpstat ) 2> FILE

> --
>   Chris F.A. Johnson, author   |    <http://cfaj.freeshell.org>
>   Shell Scripting Recipes:     |  My code in this post, if any,
>   A Problem-Solution Approach  |          is released under the
>   2005, Apress                 |     GNU General Public Licence

 
 
 

How to output 'time' to file ?

Post by bsh » Wed, 15 Feb 2006 09:22:18



> How to output time output to file ?
> I want output real, user, sys to file.

The documented method in B&K for ksh88 & ksh93 is:

{ { time mpstat; } 2>&1; } > myfile    # IIRC; not tested

=Brian

 
 
 

1. How do I re-format the 'time' command's output?

I've been trying to use the 'time' command built-into tcsh to time
processes.  Although it reports the time used correctly and all, I'm trying
to following the instructions in the man page to have it also display the
amount of memory used by the process.

From the tcsh man page:
  time    If set to a number, then the time builtin (q.v.) executes auto-
            matically  after  each  command which takes more than that many
            CPU seconds.  If there is a second word, it is used as a format
            string  for  the  output of the time builtin. (u) The following
            sequences may be used in the format string:
                    ...
            %X  The average amount in (shared) text space used in Kbytes.
            %D  The average amount in (unshared) data/stack space  used in
                   Kbytes.
            %K  The total space used (%X + %D) in Kbytes.
            %M  The  maximum  memory  the process had in use at any time in
                   Kbytes.
                     ...

My problem is that I have no idea how to format this time variable.  I've
tried just about everything I can think of (and then even some stuff that
others have suggested), but to no avail.  I just can't seem to get the
format string to change at all  - not in the slightest.

Has anyone else modified the output of this command before?  Do you know how
I can determine the total/max amount of memory used by a process?  In theory
the time
command does just that - I just can't get it to work.  And 'top' isn't an
option.

Thanks!

Eric


2. Stealth VLB32 Timings from Diamond

3. sox: Can't open output file '/dev/dsp': No such device

4. Journaling ReiserFS on Alpha ?

5. ``Output file requires shared library `libc.so.4' ''

6. Practical examples of FNS/XFN advantages?

7. what does 'ld: Output file requires shared library `libc.so.4'' mean?

8. Problem with ld?

9. Odd 'w', 'who' and 'tty' output

10. what does the output of 'time' (unix) mean?

11. output rediection for 'time' command

12. how to change the default output of 'time' command

13. redirect ``time'' output