Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ZSH script and prompt profiling?

Tags:

bash

zsh

zshrc

This answer, "How to profile a bash shell script?", seems to nearly perfectly cover what I'm trying to accomplish here. I currently have some zsh scripts that modify the prompt, however I think some updates to oh-my-zsh have evoked some issues that I need to hunt down. The sluggishness from time to time is unbearable.

To this end, how would you adapt the prompt sections in this example answer to work with zsh vs bash?

Presently I have modified /etc/zshenv such that it has the initial suggested code from the example:

PS4='+ $(date "+%s.%N")\011 '
exec 3>&2 2>/tmp/bashstart.$$.log
set -x

And my ~/.zshrc has the following appended to it's tail:

set +x
exec 2>&3 3>&-

Of course these are not valid for ZSH shell customization. My prompt rendering code utilizes oh-my-zsh customizations. I could prepend the appropriate code to the prompt I suppose or I'm open to other suggestions.

like image 757
ylluminate Avatar asked Jan 17 '12 18:01

ylluminate


1 Answers

Calling date for each command will fork and exec, which adds overhead which may interfere with your measurements.

Instead, you could use

PS4=$'+ %D{%s.%6.}\011 '

to log timestamps with lower overhead (up to millisecond precision).

For some notes on processing the resulting logs, see http://blog.xebia.com/profiling-zsh-shell-scripts/

like image 136
Arnout Engelen Avatar answered Sep 22 '22 02:09

Arnout Engelen