2012-12-04 12 views
7

गो प्रोग्राम में पीप्रोफ का उपयोग कैसे करें?गो प्रोग्राम में पीप्रोफ का उपयोग कैसे करें

net/http/pprof नामक एक गो पैकेज है, लेकिन मैं इसका उपयोग नहीं कर सकता।

दस्तावेज़ go tool pprof http://localhost:6060/debug/pprof/heap कहता है, जो काम नहीं करता है।

और, नीचे क्या मतलब है?

import _ "net/http/pprof"

उत्तर

8

your comment पर आधारित, यह मुद्दा हो सकता है कि आप सही पोर्ट नंबर का उपयोग नहीं कर रहे हैं।

आप http://localhost:9997 पर एक http सर्वर चला रहे हैं, तो मुझे लगता है कि आप http://localhost:9997 साथ आदेश चलाना चाहते हैं:, net/http/pprof pkg doc page के अनुसार

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

यदि आपके आवेदन पहले से ही एक http सर्वर चल रहा है भी नहीं पड़ेगी एक शुरू करने की आवश्यकता है और केवल आपके प्रोग्राम में import _ "net/http/pprof" शामिल करने की आवश्यकता है। http://localhost:6060 सर्वर एक उदाहरण के रूप में शुरू हुआ है और होस्ट और पोर्ट मनमाने ढंग से हैं।

import _ "net/http/pprof" का मतलब है कि पैकेज आयात किया गया है लेकिन आप इसके किसी भी निर्यात किए गए पहचानकर्ताओं का उपयोग नहीं करते हैं। go language spec के अनुसार, यह पूरी तरह से इसके दुष्प्रभावों के लिए पैकेज आयात करेगा।को package's source files में परिभाषित किया गया है, और जाहिर है, registered variables में इन दुष्प्रभावों में शामिल हैं, init() functions का निष्पादन शामिल है।

इसके अलावा, आप इस ब्लॉग पोस्ट उपयोगी हो सकती है:

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

मैं एक सर्वर जाओ द्वारा लिखित एपीआई है, और मैं इसे अनुकूलित करना चाहते हैं। जब मैं 'localhost: 9997' पर सर्वर सुन रहा हूं, तो मैं पीप्रोफ का उपयोग कैसे कर सकता हूं? मैं 'go टूल pprof http: // localhost: 6060/डीबग/पीप्रोफ/हीप' कमांड का उपयोग करता हूं, लेकिन' टूल पप्रोफ http: // localhost: 6060/डीबग/पीप्रोफ/हीप पढ़ें http: // localhost: 6060/डीबग/पीप्रोफ/प्रतीक /usr/local/go/pkg/tool/linux_amd64/pprof line 2957 पर प्रतिस्थापन (एस ///) में अनियमित मूल्य का उपयोग। http: // localhost: 6060/डीबग/पीप्रोफ/प्रतीक मौजूद नहीं है उपकरण pprof जाओ: बाहर निकलें स्थिति 1' – Codefor

संबंधित मुद्दे