Skip to content

Commit

Permalink
Support Go 1.20 "created by" lines
Browse files Browse the repository at this point in the history
In Go 1.20, the "created by" lines
do not include the "in goroutine" portion.
  • Loading branch information
abhinav committed Oct 21, 2023
1 parent 06f4c64 commit 06135bd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion internal/stack/stacks.go
Expand Up @@ -211,6 +211,7 @@ func getStackBuffer(all bool) []byte {
//
// example.com/path/to/package.funcName(args...)
// example.com/path/to/package.(*typeName).funcName(args...)
// created by example.com/path/to/package.funcName
// created by example.com/path/to/package.funcName in goroutine [...]
func parseFuncName(line string) (string, error) {
var name string
Expand All @@ -219,8 +220,9 @@ func parseFuncName(line string) (string, error) {
// and before " in goroutine [...]".
idx := strings.Index(after, " in goroutine")
if idx >= 0 {
name = after[:idx]
after = after[:idx]
}
name = after
} else if idx := strings.LastIndexByte(line, '('); idx >= 0 {
// The function name is the part before the last '('.
name = line[:idx]
Expand Down
7 changes: 6 additions & 1 deletion internal/stack/stacks_test.go
Expand Up @@ -177,7 +177,12 @@ func TestParseFuncName(t *testing.T) {
want: "example.com/foo/bar.(*baz).qux",
},
{
name: "created by",
name: "created by", // Go 1.20
give: "created by example.com/foo/bar.baz",
want: "example.com/foo/bar.baz",
},
{
name: "created by/in goroutine", // Go 1.21
give: "created by example.com/foo/bar.baz in goroutine 123",
want: "example.com/foo/bar.baz",
},
Expand Down

0 comments on commit 06135bd

Please sign in to comment.