2012-01-17 11 views
3

この回答 "How to profile a bash shell script?"は、私がここで達成しようとしていることをほぼ完全にカバーしているようです。私は現在、プロンプトを変更するいくつかのzshスクリプトを持っていますが、oh-my-zshへのいくつかの更新が、私が狩りに必要ないくつかの問題を引き起こしたと思います。時々の低迷は耐え難いことです。ZSHスクリプトとプロンプトのプロファイリング?

この例では、zshとbashで動作するようにこの例の回答のプロンプトセクションをどのように調整しますか?

現在、私はそれが初期の例からコードを示唆しているよう/etc/zshenv変更した:これらされているがもちろん

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

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

をそして、私の~/.zshrcはそれの末尾に次を追加しましたがZSHシェルのカスタマイズには有効ではありません。私のプロンプトのレンダリングコードは、oh-my-zshのカスタマイズを利用しています。私は、私が推測するプロンプトに適切なコードを付加することができます。あるいは私は他の提案にもオープンしています。

+0

を参照してくださいあなたは、関連する見つける「は、この例の答えでプロンプトセクション」を含んでおり、それは今あなたのために働いていない場所を示すためにあなたのポストを編集してご検討ください。がんばろう。 – shellter

+0

基本的に私はこれらの翻訳されたzsh同値を必要とします。 :D私は約1年間それをカスタマイズしていないので、私はoh-my-zshカスタマイズの中に埋め込んだ箇所のバックアップを掘り下げなければなりません。 – ylluminate

答えて

2

がまだない場合は、

setopt prompt_subst 

を行う必要があります。

また、タブの8進数のエスケープを解釈するために、$''を使用します。

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/

関連する問題