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

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 03190651924e 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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
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/blockrate", http.HandlerFunc(BlockProfileRate) )
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 // BlockProfileRate gets or sets runtime.BlockProfileRate.
152 // The package initialization registers it as /debug/pprof/blockrate.
153 func BlockProfileRate(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.BlockProfileRate = int(v)
165 }
166 fmt.Fprintf(w, "%v", runtime.BlockProfileRate)
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