2012-01-17 29 views
3

這個答案「How to profile a bash shell script?」似乎幾乎完美地涵蓋了我在這裏要完成的任務。我目前有一些修改提示的zsh腳本,但我認爲對oh-my-zsh的一些更新已經引發了一些我需要追捕的問題。時不時的遲緩是無法忍受的。ZSH腳本和提示性能分析?

爲此,您將如何調整此示例答案中的提示部分以使用zsh vs bash?

目前我已經修改/etc/zshenv使得它具有了初步建議從示例代碼:

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

而且我~/.zshrc具有以下附加到它的尾巴:

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

當然這些都是對於ZSH shell自定義無效。我的提示渲染代碼使用了oh-my-zsh定製。我可以在適當的代碼前添加我想提供的提示,或者我願意接受其他建議。

+0

請考慮編輯您的文章,包括「在這個例子中回答提示節」,你找到相關的,並指出它是不是適合你現在的工作。祝你好運。 – shellter 2012-01-17 18:59:52

+0

本質上,我只是需要將這些轉換爲zsh等價物,以便在我尋找定製之後加上我的提示。 :D我沒有定製它大約一年,所以我不得不挖掘部分備份,我把它埋在oh-my-zsh定製中。 – ylluminate 2012-01-17 19:30:56

回答

2

你可能需要做

setopt prompt_subst 

,如果它是不是已經。

此外,爲了解釋爲標籤的八進制轉義,使用$''

PS4=$'+ $(date "+%s.%N")\011 ' 

你也可以找到一些這些逃逸的是有用的:

%?  The return status of the last command executed just before the prompt. 

    %_  The status of the parser, i.e. the shell constructs (like `if' and `for') that have been started on the command 
      line. If given an integer number that many strings will be printed; zero or negative or no integer means print as 
      many as there are. This is most useful in prompts PS2 for continuation lines and PS4 for debugging with the 
      XTRACE option; in the latter case it will also work non-interactively. 

    %i  The line number currently being executed in the script, sourced file, or shell function given by %N. This is most 
      useful for debugging as part of $PS4. 

    %I  The line number currently being executed in the file %x. This is similar to %i, but the line number is always a 
      line number in the file where the code was defined, even if the code is a shell function. 

    %L  The current value of $SHLVL. 

    %N  The name of the script, sourced file, or shell function that zsh is currently executing, whichever was started 
      most recently. If there is none, this is equivalent to the parameter $0. An integer may follow the `%' to spec‐ 
      ify a number of trailing path components to show; zero means the full path. A negative integer specifies leading 
      components. 

    %x  The name of the file containing the source code currently being executed. This behaves as %N except that function 
      and eval command names are not shown, instead the file where they were defined. 
2

調用date每個命令將fork和exec,這會增加開銷,可能會干擾您的測量。

相反,你可以使用

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

與開銷較低(最多精確到毫秒)來記錄時間戳。

有關處理所生成的日誌的一些注意事項,請參閱http://blog.xebia.com/profiling-zsh-shell-scripts/