mirror of
https://github.com/minio/minio.git
synced 2025-05-21 09:33:50 -04: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
|
// This file is part of MinIO Object Storage stack
|
||||||
//
|
//
|
||||||
@ -33,16 +33,19 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
re *regexp.Regexp
|
goroutinesRE, searchRE *regexp.Regexp
|
||||||
|
|
||||||
|
// User input flags
|
||||||
|
searchText string
|
||||||
goTime, less, margin time.Duration
|
goTime, less, margin time.Duration
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
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(&less, "less", 0, "goroutine waiting less than the specified time")
|
||||||
flag.DurationVar(&goTime, "time", 0, "goroutine waiting for exactly the specified time")
|
flag.DurationVar(&goTime, "time", 0, "goroutine waiting for exactly the specified time")
|
||||||
flag.DurationVar(&margin, "margin", 0, "margin 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) {
|
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 == "":
|
case skip && line == "":
|
||||||
skip = false
|
skip = false
|
||||||
case record && line == "":
|
case record && line == "":
|
||||||
record = false
|
stackTrace := bf.String()
|
||||||
ret[t] = append(ret[t], bf.String())
|
|
||||||
reset()
|
reset()
|
||||||
|
record = false
|
||||||
|
if searchRE == nil || searchRE.MatchString(stackTrace) {
|
||||||
|
ret[t] = append(ret[t], stackTrace)
|
||||||
|
}
|
||||||
case record:
|
case record:
|
||||||
save(line)
|
save(line)
|
||||||
default:
|
default:
|
||||||
z := re.FindStringSubmatch(line)
|
z := goroutinesRE.FindStringSubmatch(line)
|
||||||
if len(z) == 3 {
|
if len(z) == 3 {
|
||||||
if z[2] != "" {
|
if z[2] != "" {
|
||||||
a, _ := strconv.Atoi(z[2])
|
a, _ := strconv.Atoi(z[2])
|
||||||
@ -115,6 +121,17 @@ func main() {
|
|||||||
log.Fatal(helpUsage)
|
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() {
|
for _, arg := range flag.Args() {
|
||||||
if !strings.HasSuffix(arg, "-goroutines-before,debug=2.txt") {
|
if !strings.HasSuffix(arg, "-goroutines-before,debug=2.txt") {
|
||||||
continue
|
continue
|
||||||
|
Loading…
x
Reference in New Issue
Block a user