mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
pkg/testutil: more aggressive goroutine stack trace coalescing
Strips out the pointer arguments in the header of the stack trace so that more stack traces match each other.
This commit is contained in:
parent
cb30d6e6f8
commit
72b31d6fdc
@ -8,6 +8,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
@ -42,17 +43,18 @@ func CheckLeakedGoroutine() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
gs := interestingGoroutines()
|
gs := interestingGoroutines()
|
||||||
|
if len(gs) == 0 {
|
||||||
n := 0
|
|
||||||
stackCount := make(map[string]int)
|
|
||||||
for _, g := range gs {
|
|
||||||
stackCount[g]++
|
|
||||||
n++
|
|
||||||
}
|
|
||||||
|
|
||||||
if n == 0 {
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stackCount := make(map[string]int)
|
||||||
|
re := regexp.MustCompile("\\(0[0-9a-fx, ]*\\)")
|
||||||
|
for _, g := range gs {
|
||||||
|
// strip out pointer arguments in first function of stack dump
|
||||||
|
normalized := string(re.ReplaceAll([]byte(g), []byte("(...)")))
|
||||||
|
stackCount[normalized]++
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Fprintf(os.Stderr, "Too many goroutines running after all test(s).\n")
|
fmt.Fprintf(os.Stderr, "Too many goroutines running after all test(s).\n")
|
||||||
for stack, count := range stackCount {
|
for stack, count := range stackCount {
|
||||||
fmt.Fprintf(os.Stderr, "%d instances of:\n%s\n", count, stack)
|
fmt.Fprintf(os.Stderr, "%d instances of:\n%s\n", count, stack)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user