LEFT | RIGHT |
1 // Copyright 2010 The Go Authors. All rights reserved. | 1 // Copyright 2010 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Package pprof serves via its HTTP server runtime profiling data | 5 // Package pprof serves via its HTTP server runtime profiling data |
6 // in the format expected by the pprof visualization tool. | 6 // in the format expected by the pprof visualization tool. |
7 // For more information about pprof, see | 7 // For more information about pprof, see |
8 // http://code.google.com/p/google-perftools/. | 8 // http://code.google.com/p/google-perftools/. |
9 // | 9 // |
10 // The package is typically only imported for the side effect of | 10 // The package is typically only imported for the side effect of |
11 // registering its HTTP handlers. | 11 // registering its HTTP handlers. |
12 // The handled paths all begin with /debug/pprof/. | 12 // The handled paths all begin with /debug/pprof/. |
13 // | 13 // |
14 // To use pprof, link this package into your program: | 14 // To use pprof, link this package into your program: |
15 // import _ "net/http/pprof" | 15 // import _ "net/http/pprof" |
16 // | 16 // |
| 17 // If your application is not already running an http server, you |
| 18 // need to start one. Add "net/http" and "log" to your imports and |
| 19 // the following code to your main function: |
| 20 // |
| 21 // go func() { |
| 22 // log.Println(http.ListenAndServe("localhost:6060", nil)) |
| 23 // }() |
| 24 // |
17 // Then use the pprof tool to look at the heap profile: | 25 // Then use the pprof tool to look at the heap profile: |
18 // | 26 // |
19 // go tool pprof http://localhost:6060/debug/pprof/heap | 27 // go tool pprof http://localhost:6060/debug/pprof/heap |
20 // | 28 // |
21 // Or to look at a 30-second CPU profile: | 29 // Or to look at a 30-second CPU profile: |
22 // | 30 // |
23 // go tool pprof http://localhost:6060/debug/pprof/profile | 31 // go tool pprof http://localhost:6060/debug/pprof/profile |
24 // | 32 // |
25 // Or to look at the contention profile: | 33 // Or to look at the goroutine blocking profile: |
26 // | 34 // |
27 //» go tool pprof http://localhost:6060/debug/pprof/contention | 35 //» go tool pprof http://localhost:6060/debug/pprof/block |
28 // | 36 // |
29 // Or to view all available profiles: | 37 // Or to view all available profiles: |
30 // | 38 // |
31 // go tool pprof http://localhost:6060/debug/pprof/ | 39 // go tool pprof http://localhost:6060/debug/pprof/ |
32 // | 40 // |
33 // For a study of the facility in action, visit | 41 // For a study of the facility in action, visit |
34 // | 42 // |
35 // http://blog.golang.org/2011/06/profiling-go-programs.html | 43 // http://blog.golang.org/2011/06/profiling-go-programs.html |
36 // | 44 // |
37 package pprof | 45 package pprof |
(...skipping 12 matching lines...) Expand all Loading... |
50 "strconv" | 58 "strconv" |
51 "strings" | 59 "strings" |
52 "time" | 60 "time" |
53 ) | 61 ) |
54 | 62 |
55 func init() { | 63 func init() { |
56 http.Handle("/debug/pprof/", http.HandlerFunc(Index)) | 64 http.Handle("/debug/pprof/", http.HandlerFunc(Index)) |
57 http.Handle("/debug/pprof/cmdline", http.HandlerFunc(Cmdline)) | 65 http.Handle("/debug/pprof/cmdline", http.HandlerFunc(Cmdline)) |
58 http.Handle("/debug/pprof/profile", http.HandlerFunc(Profile)) | 66 http.Handle("/debug/pprof/profile", http.HandlerFunc(Profile)) |
59 http.Handle("/debug/pprof/symbol", http.HandlerFunc(Symbol)) | 67 http.Handle("/debug/pprof/symbol", http.HandlerFunc(Symbol)) |
60 runtime.ContentionProfileRate = 1 | |
61 } | 68 } |
62 | 69 |
63 // Cmdline responds with the running program's | 70 // Cmdline responds with the running program's |
64 // command line, with arguments separated by NUL bytes. | 71 // command line, with arguments separated by NUL bytes. |
65 // The package initialization registers it as /debug/pprof/cmdline. | 72 // The package initialization registers it as /debug/pprof/cmdline. |
66 func Cmdline(w http.ResponseWriter, r *http.Request) { | 73 func Cmdline(w http.ResponseWriter, r *http.Request) { |
67 w.Header().Set("Content-Type", "text/plain; charset=utf-8") | 74 w.Header().Set("Content-Type", "text/plain; charset=utf-8") |
68 fmt.Fprintf(w, strings.Join(os.Args, "\x00")) | 75 fmt.Fprintf(w, strings.Join(os.Args, "\x00")) |
69 } | 76 } |
70 | 77 |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 <table> | 197 <table> |
191 {{range .}} | 198 {{range .}} |
192 <tr><td align=right>{{.Count}}<td><a href="/debug/pprof/{{.Name}}?debug=1">{{.Na
me}}</a> | 199 <tr><td align=right>{{.Count}}<td><a href="/debug/pprof/{{.Name}}?debug=1">{{.Na
me}}</a> |
193 {{end}} | 200 {{end}} |
194 </table> | 201 </table> |
195 <br> | 202 <br> |
196 <a href="/debug/pprof/goroutine?debug=2">full goroutine stack dump</a><br> | 203 <a href="/debug/pprof/goroutine?debug=2">full goroutine stack dump</a><br> |
197 </body> | 204 </body> |
198 </html> | 205 </html> |
199 `)) | 206 `)) |
LEFT | RIGHT |