mirror of
https://github.com/minio/minio.git
synced 2024-12-24 22:25:54 -05:00
debug: Add --search to print only specific goroutines (#19158)
Easier to filter goroutines belonging to a specific subsystem
This commit is contained in:
parent
467714f33b
commit
828d4df6f0
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user