mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: enable profiling on g0
Since we now have stack information for code running on the systemstack, we can traceback over it. To make cpu profiles useful, add a case in gentraceback to jump over systemstack switches. Fixes #10609. Change-Id: I21f47fcc802c07c5d4a1ada56374314e388a6dc7 Reviewed-on: https://go-review.googlesource.com/9506 Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
This commit is contained in:
parent
19e81a9b3b
commit
db6f88a84b
12 changed files with 105 additions and 142 deletions
|
|
@ -6,13 +6,8 @@ package runtime_test
|
|||
|
||||
import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
. "runtime"
|
||||
"runtime/debug"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"unsafe"
|
||||
)
|
||||
|
|
@ -88,53 +83,6 @@ func BenchmarkDeferMany(b *testing.B) {
|
|||
}
|
||||
}
|
||||
|
||||
// The profiling signal handler needs to know whether it is executing runtime.gogo.
|
||||
// The constant RuntimeGogoBytes in arch_*.h gives the size of the function;
|
||||
// we don't have a way to obtain it from the linker (perhaps someday).
|
||||
// Test that the constant matches the size determined by 'go tool nm -S'.
|
||||
// The value reported will include the padding between runtime.gogo and the
|
||||
// next function in memory. That's fine.
|
||||
func TestRuntimeGogoBytes(t *testing.T) {
|
||||
switch GOOS {
|
||||
case "android", "nacl":
|
||||
t.Skipf("skipping on %s", GOOS)
|
||||
case "darwin":
|
||||
switch GOARCH {
|
||||
case "arm", "arm64":
|
||||
t.Skipf("skipping on %s/%s, no fork", GOOS, GOARCH)
|
||||
}
|
||||
}
|
||||
|
||||
dir, err := ioutil.TempDir("", "go-build")
|
||||
if err != nil {
|
||||
t.Fatalf("failed to create temp directory: %v", err)
|
||||
}
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
out, err := exec.Command("go", "build", "-o", dir+"/hello", "../../test/helloworld.go").CombinedOutput()
|
||||
if err != nil {
|
||||
t.Fatalf("building hello world: %v\n%s", err, out)
|
||||
}
|
||||
|
||||
out, err = exec.Command("go", "tool", "nm", "-size", dir+"/hello").CombinedOutput()
|
||||
if err != nil {
|
||||
t.Fatalf("go tool nm: %v\n%s", err, out)
|
||||
}
|
||||
|
||||
for _, line := range strings.Split(string(out), "\n") {
|
||||
f := strings.Fields(line)
|
||||
if len(f) == 4 && f[3] == "runtime.gogo" {
|
||||
size, _ := strconv.Atoi(f[1])
|
||||
if GogoBytes() != int32(size) {
|
||||
t.Fatalf("RuntimeGogoBytes = %d, should be %d", GogoBytes(), size)
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
t.Fatalf("go tool nm did not report size for runtime.gogo")
|
||||
}
|
||||
|
||||
// golang.org/issue/7063
|
||||
func TestStopCPUProfilingWithProfilerOff(t *testing.T) {
|
||||
SetCPUProfileRate(0)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue