debug: Add --search to print only specific goroutines (#19158)

Easier to filter goroutines belonging to a specific subsystem
This commit is contained in:
Anis Eleuch 2024-02-29 17:28:18 +01:00 committed by GitHub
parent 467714f33b
commit 828d4df6f0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,4 +1,4 @@
// Copyright (c) 2015-2023 MinIO, Inc.
// Copyright (c) 2015-2024 MinIO, Inc.
//
// This file is part of MinIO Object Storage stack
//
@ -33,16 +33,19 @@ import (
)
var (
re *regexp.Regexp
goroutinesRE, searchRE *regexp.Regexp
// User input flags
searchText string
goTime, less, margin time.Duration
)
func init() {
re = regexp.MustCompile(`^goroutine [0-9]+ \[[^,]+(, ([0-9]+) minutes)?\]:$`)
flag.DurationVar(&less, "less", 0, "goroutine waiting less than the specified time")
flag.DurationVar(&goTime, "time", 0, "goroutine waiting for exactly the specified time")
flag.DurationVar(&margin, "margin", 0, "margin time")
flag.StringVar(&searchText, "search", "", "Regex to search for a text in one goroutine stacktrace")
}
func parseGoroutineType2(path string) (map[time.Duration][]string, error) {
@ -77,13 +80,16 @@ func parseGoroutineType2(path string) (map[time.Duration][]string, error) {
case skip && line == "":
skip = false
case record && line == "":
record = false
ret[t] = append(ret[t], bf.String())
stackTrace := bf.String()
reset()
record = false
if searchRE == nil || searchRE.MatchString(stackTrace) {
ret[t] = append(ret[t], stackTrace)
}
case record:
save(line)
default:
z := re.FindStringSubmatch(line)
z := goroutinesRE.FindStringSubmatch(line)
if len(z) == 3 {
if z[2] != "" {
a, _ := strconv.Atoi(z[2])
@ -115,6 +121,17 @@ func main() {
log.Fatal(helpUsage)
}
var err error
goroutinesRE = regexp.MustCompile(`^goroutine [0-9]+ \[[^,]+(, ([0-9]+) minutes)?\]:$`)
if searchText != "" {
searchRE, err = regexp.Compile(searchText)
if err != nil {
log.Fatal(err)
}
}
for _, arg := range flag.Args() {
if !strings.HasSuffix(arg, "-goroutines-before,debug=2.txt") {
continue