if name == "" {
show = true
fmt.Fprintf(w, "#\t%#x\n", frame.PC)
- } else if name != "runtime.goexit" && (show || !strings.HasPrefix(name, "runtime.")) {
+ } else if name != "runtime.goexit" && (show || !(strings.HasPrefix(name, "runtime.") || strings.HasPrefix(name, "internal/runtime/"))) {
// Hide runtime.goexit and any runtime functions at the beginning.
// This is useful mainly for allocation traces.
show = true
return funcs
}
-// This is a regression test for https://go.dev/issue/64528 .
+// This is a regression test for https://go.dev/issue/64528.
func TestGenericsHashKeyInPprofBuilder(t *testing.T) {
if asan.Enabled {
t.Skip("extra allocations with -asan throw off the test; see #70079")
t.Errorf("expected a location with at least 3 functions\n%s\ngot\n%s\n", expectedLocation, actual)
}
}
+
+func growMap() {
+ m := make(map[int]int)
+ for i := range 512 {
+ m[i] = i
+ }
+}
+
+// Runtime frames are hidden in heap profiles.
+// This is a regression test for https://go.dev/issue/71174.
+func TestHeapRuntimeFrames(t *testing.T) {
+ previousRate := runtime.MemProfileRate
+ runtime.MemProfileRate = 1
+ defer func() {
+ runtime.MemProfileRate = previousRate
+ }()
+
+ growMap()
+
+ runtime.GC()
+ buf := bytes.NewBuffer(nil)
+ if err := WriteHeapProfile(buf); err != nil {
+ t.Fatalf("writing profile: %v", err)
+ }
+ p, err := profile.Parse(buf)
+ if err != nil {
+ t.Fatalf("profile.Parse: %v", err)
+ }
+
+ actual := profileToStrings(p)
+
+ // We must see growMap at least once.
+ foundGrowMap := false
+ for _, l := range actual {
+ if !strings.Contains(l, "runtime/pprof.growMap") {
+ continue
+ }
+ foundGrowMap = true
+
+ // Runtime frames like mapassign and map internals should be hidden.
+ if strings.Contains(l, "runtime.") {
+ t.Errorf("Sample got %s, want no runtime frames", l)
+ }
+ if strings.Contains(l, "internal/runtime/") {
+ t.Errorf("Sample got %s, want no runtime frames", l)
+ }
+ if strings.Contains(l, "runtime/internal/") {
+ t.Errorf("Sample got %s, want no runtime frames", l)
+ }
+ if strings.Contains(l, "mapassign") { // in case mapassign moves to a package not matching above paths.
+ t.Errorf("Sample got %s, want no mapassign frames", l)
+ }
+ }
+
+ if !foundGrowMap {
+ t.Errorf("Profile got:\n%s\nwant sample in runtime/pprof.growMap", strings.Join(actual, "\n"))
+ }
+}