From 362713183a8947394d2900563e711d05c9bbd67b Mon Sep 17 00:00:00 2001 From: Cherry Mui Date: Mon, 14 Nov 2022 16:34:16 -0500 Subject: [PATCH] cmd/pprof: debug TestDisasm 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 Run-TryBot: Cherry Mui Reviewed-by: Than McIntosh --- src/cmd/pprof/pprof_test.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/cmd/pprof/pprof_test.go b/src/cmd/pprof/pprof_test.go index e001975f83..753d2b149f 100644 --- a/src/cmd/pprof/pprof_test.go +++ b/src/cmd/pprof/pprof_test.go @@ -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) } }