Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Ignore ¶
Ignore filter
func CombineIgnores ¶
CombineIgnores into one
Example ¶
package main
import (
"context"
"fmt"
"strings"
"time"
"github.com/ysmood/got"
)
func main() {
ignore := got.CombineIgnores(
got.IgnoreCurrent(),
func(t got.Trace) bool {
return strings.Contains(t.Raw, "ExampleCombineIgnores.func2")
},
)
go func() {
time.Sleep(2 * time.Second)
}()
go func() {
time.Sleep(time.Second)
}()
start := time.Now()
got.Wait(context.TODO(), ignore)
end := time.Since(start)
if time.Second < end && end < 2*time.Second {
fmt.Println("only waits for the second goroutine")
}
}
Output: only waits for the second goroutine
func IgnoreCurrent ¶
func IgnoreCurrent() Ignore
IgnoreCurrent Trace list
Example ¶
package main
import (
"context"
"fmt"
"time"
"github.com/ysmood/got"
)
func main() {
ignore := got.IgnoreCurrent()
go func() {
time.Sleep(time.Second)
}()
start := time.Now()
got.Wait(context.TODO(), ignore)
end := time.Since(start)
if end > time.Second {
fmt.Println("waited for 1 second")
}
}
Output: waited for 1 second
func IgnoreFuncs ¶
IgnoreFuncs ignores a Trace if it's first Stack's Func equals one of the names.
Example ¶
package main
import (
"context"
"fmt"
"time"
"github.com/ysmood/got"
)
func main() {
ignore := got.IgnoreFuncs("internal/poll.runtime_pollWait")
go func() {
time.Sleep(time.Second)
}()
start := time.Now()
got.Wait(context.TODO(), ignore)
end := time.Since(start)
if end > time.Second {
fmt.Println("waited for 1 second")
}
}
Output: waited for 1 second
type Trace ¶
type Trace struct {
Raw string
GoroutineID int64
WaitReason string // https://github.com/golang/go/blob/874b3132a84cf76da6a48978826c04c380a37a50/src/runtime/runtime2.go#L997
Stacks []Stack
}
Trace of one goroutine
type Traces ¶
type Traces []Trace
Traces of goroutines
func Get ¶
Get the Trace of the calling goroutine. If all is true, all other goroutines' Traces will be appended into the result too.
Example ¶
package main
import (
"fmt"
"github.com/ysmood/got"
)
func main() {
list := got.Get(true)
fmt.Println("goroutine count:", len(list))
fmt.Println("id of current:", list[0].GoroutineID)
fmt.Println("caller of current:", list[0].Stacks[2].Func)
}
Output: goroutine count: 2 id of current: 1 caller of current: github.com/ysmood/got_test.ExampleGet()
func Wait ¶
Wait until all other goroutines exit. It return the remaining goroutines that are still active.
func (Traces) Format ¶
Format list into a human readable string
Example ¶
package main
import (
"fmt"
"strings"
"time"
"github.com/ysmood/got"
)
func main() {
go func() {
time.Sleep(time.Second)
}()
str := got.Wait(got.Timeout(0)).Format()
fmt.Println(strings.Contains(str, "got_test.ExampleTraces_Format"))
}
Output: true
Click to show internal directories.
Click to hide internal directories.