aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2011-05-03 01:43:30 -0400
committerRuss Cox <rsc@golang.org>2011-05-03 01:43:30 -0400
commit006e5e279b4c0dc8c3a4fbe324e0893c76ede27d (patch)
tree074b73f39d89207bd95ffd91cd6173b2389800ba
parent5af3c75e3017c42102affc40f3ce61670491dcdb (diff)
downloadgo-006e5e279b4c0dc8c3a4fbe324e0893c76ede27d.tar.gz
go-006e5e279b4c0dc8c3a4fbe324e0893c76ede27d.zip
[release-branch.r57] http/pprof: fix POST reading bug
««« CL 4430075 / ca45c67d28cf http/pprof: fix POST reading bug R=bradfitz CC=golang-dev https://golang.org/cl/4430075 »»» TBR=adg CC=golang-dev https://golang.org/cl/4454053
-rwxr-xr-xsrc/cmd/prof/gopprof9
-rw-r--r--src/pkg/http/pprof/pprof.go14
2 files changed, 17 insertions, 6 deletions
diff --git a/src/cmd/prof/gopprof b/src/cmd/prof/gopprof
index 8fa00cbe8c..8863fc6238 100755
--- a/src/cmd/prof/gopprof
+++ b/src/cmd/prof/gopprof
@@ -2880,17 +2880,18 @@ sub FetchSymbols {
my @toask = @pcs;
while (@toask > 0) {
my $n = @toask;
- if ($n > 49) { $n = 49; }
+ # NOTE(rsc): Limiting the number of PCs requested per round
+ # used to be necessary, but I think it was a bug in
+ # debug/pprof/symbol's implementation. Leaving here
+ # in case I am wrong.
+ # if ($n > 49) { $n = 49; }
my @thisround = @toask[0..$n];
-my $t = @toask;
-print STDERR "$n $t\n";
@toask = @toask[($n+1)..(@toask-1)];
my $post_data = join("+", sort((map {"0x" . "$_"} @thisround)));
open(POSTFILE, ">$main::tmpfile_sym");
print POSTFILE $post_data;
close(POSTFILE);
-print STDERR "SYMBL!\n";
my $url = SymbolPageURL();
$url = ResolveRedirectionForCurl($url);
my $command_line = "$CURL -sd '\@$main::tmpfile_sym' '$url'";
diff --git a/src/pkg/http/pprof/pprof.go b/src/pkg/http/pprof/pprof.go
index bc79e21832..917c7f877a 100644
--- a/src/pkg/http/pprof/pprof.go
+++ b/src/pkg/http/pprof/pprof.go
@@ -26,6 +26,7 @@ package pprof
import (
"bufio"
+ "bytes"
"fmt"
"http"
"os"
@@ -88,10 +89,14 @@ func Profile(w http.ResponseWriter, r *http.Request) {
func Symbol(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
+ // We have to read the whole POST body before
+ // writing any output. Buffer the output here.
+ var buf bytes.Buffer
+
// We don't know how many symbols we have, but we
// do have symbol information. Pprof only cares whether
// this number is 0 (no symbols available) or > 0.
- fmt.Fprintf(w, "num_symbols: 1\n")
+ fmt.Fprintf(&buf, "num_symbols: 1\n")
var b *bufio.Reader
if r.Method == "POST" {
@@ -109,14 +114,19 @@ func Symbol(w http.ResponseWriter, r *http.Request) {
if pc != 0 {
f := runtime.FuncForPC(uintptr(pc))
if f != nil {
- fmt.Fprintf(w, "%#x %s\n", pc, f.Name())
+ fmt.Fprintf(&buf, "%#x %s\n", pc, f.Name())
}
}
// Wait until here to check for err; the last
// symbol will have an err because it doesn't end in +.
if err != nil {
+ if err != os.EOF {
+ fmt.Fprintf(&buf, "reading request: %v\n", err)
+ }
break
}
}
+
+ w.Write(buf.Bytes())
}