2012-12-04 10 views
7

Go 프로그램에서 pprof를 사용하는 방법은 무엇입니까?Go 프로그램에서 pprof를 사용하는 방법

net/http/pprof이라는 Go 패키지가 있지만 사용할 수 없습니다.

문서에 go tool pprof http://localhost:6060/debug/pprof/heap이 표시되며 작동하지 않습니다.

그리고 아래에서 의미하는 것은 무엇입니까?

import _ "net/http/pprof"

답변

8

your comment에 따르면 올바른 포트 번호를 사용하지 않는 것이 문제 일 수 있습니다. 응용 프로그램이 이미 http 서버를 당신이 할 실행중인 경우,

$ go tool pprof http://localhost:9997/debug/pprof/heap 

net/http/pprof pkg doc page에 따르면

당신이 http://localhost:9997에서 HTTP 서버를 실행하는 경우, 그럼 당신이 http://localhost:9997으로 명령을 실행하려는 생각 프로그램을 시작해야하며 프로그램에 import _ "net/http/pprof"을 포함시켜야합니다. http://localhost:6060은 예제로 시작된 서버이며 호스트와 포트는 임의적입니다.

import _ "net/http/pprof"은 패키지를 가져 왔지만 내 보낸 식별자를 사용하지 않음을 의미합니다. go language spec에 따르면이 패키지는 부작용을 위해서만 가져올 것입니다. 이 부작용은 package's source files에 정의 된 init() functions의 실행과 분명히 registered variables을 포함합니다.

또한, 당신은 도움이 블로그 게시물을 찾을 수 있습니다

http://blog.golang.org/2011/06/profiling-go-programs.html

1

어떤 수단을 "작동하지 않는다"? 예상되는 것과 대신에 관찰되는 것은 무엇입니까?

실행

$ go tool pprof -h 

이 도구의 버전에 대한 도움말을 볼 수 있습니다. 내 로컬 버전은 출시 시점이나 출시 시점이 아닙니다. 그것은 보여줍니다 : 두 번째 질문에

(10:16) [email protected]:~$ go tool pprof -h 
Option h is ambiguous (heapcheck, help) 
Invalid option(s) 

Usage: 
pprof [options] <program> <profiles> 
    <profiles> is a space separated list of profile names. 
pprof [options] <symbolized-profiles> 
    <symbolized-profiles> is a list of profile files where each file contains 
    the necessary symbol mappings as well as profile data (likely generated 
    with --raw). 
pprof [options] <profile> 
    <profile> is a remote form. Symbols are obtained from host:port/pprof/symbol 

    Each name can be: 
    /path/to/profile  - a path to a profile file 
    host:port[/<service>] - a location of a service to get profile from 

    The /<service> can be /pprof/heap, /pprof/profile, /pprof/pmuprofile, 
         /pprof/growth, /pprof/contention, /pprof/wall, 
         /pprof/thread, or /pprof/filteredprofile. 
    For instance: 
    pprof http://myserver.com:80/pprof/heap 
    If /<service> is omitted, the service defaults to /pprof/profile (cpu profiling). 
pprof --symbols <program> 
    Maps addresses to symbol names. In this mode, stdin should be a 
    list of library mappings, in the same format as is found in the heap- 
    and cpu-profile files (this loosely matches that of /proc/self/maps 
    on linux), followed by a list of hex addresses to map, one per line. 

    For more help with querying remote servers, including how to add the 
    necessary server-side support code, see this filename (or one like it): 

    /usr/doc/google-perftools-1.5/pprof_remote_servers.html 

Options: 
    --cum    Sort by cumulative data 
    --base=<base>  Subtract <base> from <profile> before display 
    --interactive  Run in interactive mode (interactive "help" gives help) [default] 
    --seconds=<n>  Length of time for dynamic profiles [default=30 secs] 
    --add_lib=<file> Read additional symbols and line info from the given library 
    --lib_prefix=<dir> Comma separated list of library path prefixes 

Reporting Granularity: 
    --addresses   Report at address level 
    --lines    Report at source line level 
    --functions   Report at function level [default] 
    --files    Report at source file level 

Output type: 
    --text    Generate text report 
    --callgrind   Generate callgrind format to stdout 
    --gv    Generate Postscript and display 
    --web    Generate SVG and display 
    --list=<regexp>  Generate source listing of matching routines 
    --disasm=<regexp> Generate disassembly of matching routines 
    --symbols   Print demangled symbol names found at given addresses 
    --dot    Generate DOT file to stdout 
    --ps    Generate Postcript to stdout 
    --pdf    Generate PDF to stdout 
    --svg    Generate SVG to stdout 
    --gif    Generate GIF to stdout 
    --raw    Generate symbolized pprof data (useful with remote fetch) 

Heap-Profile Options: 
    --inuse_space  Display in-use (mega)bytes [default] 
    --inuse_objects  Display in-use objects 
    --alloc_space  Display allocated (mega)bytes 
    --alloc_objects  Display allocated objects 
    --show_bytes  Display space in bytes 
    --drop_negative  Ignore negative differences 

Contention-profile options: 
    --total_delay  Display total delay at each region [default] 
    --contentions  Display number of delays at each region 
    --mean_delay  Display mean delay at each region 

Call-graph Options: 
    --nodecount=<n>  Show at most so many nodes [default=80] 
    --nodefraction=<f> Hide nodes below <f>*total [default=.005] 
    --edgefraction=<f> Hide edges below <f>*total [default=.001] 
    --focus=<regexp> Focus on nodes matching <regexp> 
    --ignore=<regexp> Ignore nodes matching <regexp> 
    --scale=<n>   Set GV scaling [default=0] 
    --heapcheck   Make nodes with non-0 object counts 
         (i.e. direct leak generators) more visible 

Miscellaneous: 
    --tools=<prefix> Prefix for object tool pathnames 
    --test    Run unit tests 
    --help    This message 
    --version   Version information 

Environment Variables: 
    PPROF_TMPDIR  Profiles directory. Defaults to $HOME/pprof 
    PPROF_TOOLS   Prefix for object tools pathnames 

Examples: 

pprof /bin/ls ls.prof 
         Enters "interactive" mode 
pprof --text /bin/ls ls.prof 
         Outputs one line per procedure 
pprof --web /bin/ls ls.prof 
         Displays annotated call-graph in web browser 
pprof --gv /bin/ls ls.prof 
         Displays annotated call-graph via 'gv' 
pprof --gv --focus=Mutex /bin/ls ls.prof 
         Restricts to code paths including a .*Mutex.* entry 
pprof --gv --focus=Mutex --ignore=string /bin/ls ls.prof 
         Code paths including Mutex but not string 
pprof --list=getdir /bin/ls ls.prof 
         (Per-line) annotated source listing for getdir() 
pprof --disasm=getdir /bin/ls ls.prof 
         (Per-PC) annotated disassembly for getdir() 

pprof http://localhost:1234/ 
         Enters "interactive" mode 
pprof --text localhost:1234 
         Outputs one line per procedure for localhost:1234 
pprof --raw localhost:1234 > ./local.raw 
pprof --text ./local.raw 
         Fetches a remote profile for later analysis and then 
         analyzes it in text mode. 

FATAL ERROR: Invalid option(s) 
go tool pprof: exit status 1 
(10:16) [email protected]:~$ 

: "foo는" '관용구는 foo는의 초기화의 부작용에 대한 패키지 foo는 가져 오는 _은`가져 오기를. 예를 들어, foo가 제공하는 기능을 등록하여 다른 패키지 내에서 사용할 수 있도록 할 수 있습니다. 이에 대한 구체적인 예는 특정 이미지 형식 handling packages (하단의 "하위 디렉토리"참조)과 추상 image 패키지입니다.

+3

을 나는 이동에 의해 작성된 서버 API를 가지고 있고, 나는 그것을 최적화 할 수 있습니다. 'localhost : 9997'에서 서버를 시작할 때 pprof를 어떻게 사용할 수 있습니까? 나는'go tool pprof http : // localhost : 6060/debug/pprof/heap' 명령을 사용하지만'tool pprof http : // localhost : 6060/debug/pprof/heap을 가지고있다. http : // localhost :/dev/pprof/symbol /usr/local/go/pkg/tool/linux_amd64/pprof 라인 2957에서 초기화되지 않은 값 (s ///)을 사용합니다. http : // localhost : 6060/debug/pprof/기호가 존재하지 않습니다. go tool pprof : exit status 1' – Codefor