Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1163)

Delta Between Two Patch Sets: src/pkg/net/http/pprof/pprof.go

Issue 6443115: code review 6443115: pprof: add contention profiling (Closed)
Left Patch Set: diff -r 248e11862ed5 https://go.googlecode.com/hg/ Created 11 years, 6 months ago
Right Patch Set: diff -r 2aef5548a9cf https://go.googlecode.com/hg/ Created 11 years, 5 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/cmd/go/testflag.go ('k') | src/pkg/runtime/chan.c » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
(...skipping 12 matching lines...) Expand all
23 // }() 23 // }()
24 // 24 //
25 // Then use the pprof tool to look at the heap profile: 25 // Then use the pprof tool to look at the heap profile:
26 // 26 //
27 // go tool pprof http://localhost:6060/debug/pprof/heap 27 // go tool pprof http://localhost:6060/debug/pprof/heap
28 // 28 //
29 // Or to look at a 30-second CPU profile: 29 // Or to look at a 30-second CPU profile:
30 // 30 //
31 // go tool pprof http://localhost:6060/debug/pprof/profile 31 // go tool pprof http://localhost:6060/debug/pprof/profile
32 // 32 //
33 // Or to look at the contention profile: 33 // Or to look at the goroutine blocking profile:
34 // 34 //
35 //» go tool pprof http://localhost:6060/debug/pprof/contention 35 //» go tool pprof http://localhost:6060/debug/pprof/block
36 // 36 //
37 // Or to view all available profiles: 37 // Or to view all available profiles:
38 // 38 //
39 // go tool pprof http://localhost:6060/debug/pprof/ 39 // go tool pprof http://localhost:6060/debug/pprof/
40 // 40 //
41 // For a study of the facility in action, visit 41 // For a study of the facility in action, visit
42 // 42 //
43 // http://blog.golang.org/2011/06/profiling-go-programs.html 43 // http://blog.golang.org/2011/06/profiling-go-programs.html
44 // 44 //
45 package pprof 45 package pprof
(...skipping 12 matching lines...) Expand all
58 "strconv" 58 "strconv"
59 "strings" 59 "strings"
60 "time" 60 "time"
61 ) 61 )
62 62
63 func init() { 63 func init() {
64 http.Handle("/debug/pprof/", http.HandlerFunc(Index)) 64 http.Handle("/debug/pprof/", http.HandlerFunc(Index))
65 http.Handle("/debug/pprof/cmdline", http.HandlerFunc(Cmdline)) 65 http.Handle("/debug/pprof/cmdline", http.HandlerFunc(Cmdline))
66 http.Handle("/debug/pprof/profile", http.HandlerFunc(Profile)) 66 http.Handle("/debug/pprof/profile", http.HandlerFunc(Profile))
67 http.Handle("/debug/pprof/symbol", http.HandlerFunc(Symbol)) 67 http.Handle("/debug/pprof/symbol", http.HandlerFunc(Symbol))
68 http.Handle("/debug/pprof/contentionrate", http.HandlerFunc(ContentionPr ofileRate))
69 } 68 }
70 69
71 // Cmdline responds with the running program's 70 // Cmdline responds with the running program's
72 // command line, with arguments separated by NUL bytes. 71 // command line, with arguments separated by NUL bytes.
73 // The package initialization registers it as /debug/pprof/cmdline. 72 // The package initialization registers it as /debug/pprof/cmdline.
74 func Cmdline(w http.ResponseWriter, r *http.Request) { 73 func Cmdline(w http.ResponseWriter, r *http.Request) {
75 w.Header().Set("Content-Type", "text/plain; charset=utf-8") 74 w.Header().Set("Content-Type", "text/plain; charset=utf-8")
76 fmt.Fprintf(w, strings.Join(os.Args, "\x00")) 75 fmt.Fprintf(w, strings.Join(os.Args, "\x00"))
77 } 76 }
78 77
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 // symbol will have an err because it doesn't end in +. 138 // symbol will have an err because it doesn't end in +.
140 if err != nil { 139 if err != nil {
141 if err != io.EOF { 140 if err != io.EOF {
142 fmt.Fprintf(&buf, "reading request: %v\n", err) 141 fmt.Fprintf(&buf, "reading request: %v\n", err)
143 } 142 }
144 break 143 break
145 } 144 }
146 } 145 }
147 146
148 w.Write(buf.Bytes()) 147 w.Write(buf.Bytes())
149 }
150
151 // ContentionProfileRate gets or sets runtime.ContentionProfileRate.
152 // The package initialization registers it as /debug/pprof/contentionrate.
153 func ContentionProfileRate(w http.ResponseWriter, r *http.Request) {
154 if err := r.ParseForm(); err != nil {
155 fmt.Fprintf(w, "Failed to parse request: %v\n", err)
156 return
157 }
158 if s := r.Form.Get("v"); s != "" {
159 v, err := strconv.ParseInt(s, 10, 32)
160 if err != nil {
161 fmt.Fprintf(w, "Failed to parse request: %v\n", err)
162 return
163 }
164 runtime.ContentionProfileRate = int(v)
165 }
166 fmt.Fprintf(w, "%v", runtime.ContentionProfileRate)
167 } 148 }
168 149
169 // Handler returns an HTTP handler that serves the named profile. 150 // Handler returns an HTTP handler that serves the named profile.
170 func Handler(name string) http.Handler { 151 func Handler(name string) http.Handler {
171 return handler(name) 152 return handler(name)
172 } 153 }
173 154
174 type handler string 155 type handler string
175 156
176 func (name handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { 157 func (name handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 <table> 197 <table>
217 {{range .}} 198 {{range .}}
218 <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>
219 {{end}} 200 {{end}}
220 </table> 201 </table>
221 <br> 202 <br>
222 <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>
223 </body> 204 </body>
224 </html> 205 </html>
225 `)) 206 `))
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b