2012-01-17 2 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 

을 수행해야 할 수 있습니다.

또한, 탭의 진수 탈출을 해석하기 위해, $''를 사용

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/