Google CPU Profiler
download : http://code.google.com/p/google-perftools/downloads/list
toturial : http://google-perftools.googlecode.com/svn/trunk/doc/cpuprofile.html
설치방법
tar -zxvf google-perftools-1.6.tar.gz
cd google-perftools-1.6
./configure
make
su
make install
사전 작업
1. 프로파일링을 워하는 프로그램 컴파일시에 -lprofiler를 같이 컴파일한다.
2. <google/profiler.h>를 include한다
bash >
export LD_LIBRARY_PATH=/usr/local/lib
export CPUPROFILE=output.txt( CPUPROFILE로 설정된 파일명으로 출력파일이 생성된다 )
특정 함수에 대해서만 프로파일링을 하기 위해서는
ProfilerStart()와 ProfilerStop()를 사용하면 된다.
ProfilerStart()에는 함수명을 파라미터로 준다.( ProfileStart("test_func"); )
여기까지 설정한후에 실행을 하면
CPUPROFILE에 설정한 파일명으로 파일이 하나 생성이 된다.
이파일은 바이너리 포맷이라서 그냥 볼수는 없고
/usr/local/bin/pprof 라는 파일로 볼수 있다.
/usr/local/bin/pprof [실행파일명] [output.txt]
(pprof)라고 프로프트가 뜨면 top를 입력
(pprof) top
상위에 노출되는 함수들이 실행시간이 오래걸리는 함수들이다.
특정 함수에 대한 프로파일링 :
pprof --gv --focus=함수명 실행파일 출력파일
특정 함수를 제외한 프로파일링
pprof --gv --ignore=함수명 실행파일 출력파일
좀더 자세한 내용은 요기서 ; http://google-perftools.googlecode.com/svn/trunk/doc/cpuprofile.html