]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/pprof: debug TestDisasm
authorCherry Mui <cherryyz@google.com>
Mon, 14 Nov 2022 21:34:16 +0000 (16:34 -0500)
committerCherry Mui <cherryyz@google.com>
Tue, 15 Nov 2022 02:57:47 +0000 (02:57 +0000)
If pprof -disasm fails, print the profile content for debugging.

For #56574.

Change-Id: I5d9377b7fb80f6b85317bc53f3ebb18f70c2f06d
Reviewed-on: https://go-review.googlesource.com/c/go/+/450281
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Cherry Mui <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
src/cmd/pprof/pprof_test.go

index e001975f83196bb74b9dd537fe3c7e3170716e2d..753d2b149f33a3df6d5eaa671133d8dc0b1f542d 100644 (file)
@@ -115,12 +115,22 @@ func TestDisasm(t *testing.T) {
        cmd = exec.Command(pprofExe, "-disasm", "main.main", cpuExe, profile)
        out, err = cmd.CombinedOutput()
        if err != nil {
-               t.Fatalf("pprof failed: %v\n%s", err, out)
+               t.Errorf("pprof -disasm failed: %v\n%s", err, out)
+
+               // Try to print out profile content for debugging.
+               cmd = exec.Command(pprofExe, "-raw", cpuExe, profile)
+               out, err = cmd.CombinedOutput()
+               if err != nil {
+                       t.Logf("pprof -raw failed: %v\n%s", err, out)
+               } else {
+                       t.Logf("profile content:\n%s", out)
+               }
+               return
        }
 
        sout := string(out)
        want := "ROUTINE ======================== main.main"
        if !strings.Contains(sout, want) {
-               t.Errorf("pprof disasm got %s want contains %q", sout, want)
+               t.Errorf("pprof -disasm got %s want contains %q", sout, want)
        }
 }