Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: zsh debug tracing with timestamp



On Apr 14, 11:47pm, Paul Lew wrote:
} Subject: zsh debug tracing with timestamp
}
} Any method to insert timestamp in front of the trace command turned on
} by set -x?

Yes, if you're using 3.1.6 or later.  Just set PS4 using any of the usual
prompt expansion escapes, e.g.:

% PS4=': %D %T ; '
% set -x
% sleep 5; echo hello
: 01-04-15 12:43 ; sleep 5
: 01-04-15 12:43 ; echo hello
hello

If you need finer granularity, setopt promptsubst and use $SECONDS:

% setopt promptsubst
: 01-04-15 12:44 ; setopt promptsubst
% PS4=': %D %T {$SECONDS}; '
: 01-04-15 12:44 ; PS4=: %D %T {$SECONDS};  
% sleep 5; echo hello
: 01-04-15 12:45 {261}; sleep 5
: 01-04-15 12:45 {266}; echo hello
hello

One-second granularity is the smallest you can get.

I chose the :...; format so that you can cut-and-paste the trace output
into another shell and the leading timestamps will be ignored.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   



Messages sorted by: Reverse Date, Date, Thread, Author