英文:
glob.func in pprof heap profiles
问题
在使用go tool pprof进行堆剖析时,我看到一些条目,例如github.com/anacrolix/utp.glob.func1。这似乎不对应于我能看到的任何命名函数,我猜它是一个闭包。glob是指什么?我如何将这样的名称与适当的函数关联起来?
英文:
When doing a heap profile using go tool pprof, I see some entries like github.com/anacrolix/utp.glob.func1. This doesn't correspond to any named function I can see, I assume it's a closure. What does glob refer to? How can I associate names like this to the appropriate function?
答案1
得分: 2
glob指的是全局环境,func1表示匿名函数。因此,它应该指的是某个全局的匿名函数。请查看这个示例及其panic信息:
示例:
package main
import (
"fmt"
)
var (
p = func() string {
panic("a")
return "asdf"
}()
)
func main() {
fmt.Println(p)
}
Panic信息:
panic: a
goroutine 1 [running]:
panic(0x128360, 0x1040a120)
/usr/local/go/src/runtime/panic.go:464 +0x700
main.glob.func1(0x0, 0x0)
/tmp/sandbox715198144/main.go:9 +0x80
main.init()
/tmp/sandbox715198144/main.go:12 +0xa0
英文:
glob refers to global environment, func1 means anonymous function. So it should refer to some global anonymous function. Check this example and its panic information:
Example:
package main
import (
"fmt"
)
var (
p = func() string {
panic("a")
return "asdf"
}()
)
func main() {
fmt.Println(p)
}
Panic information:
panic: a
goroutine 1 [running]:
panic(0x128360, 0x1040a120)
/usr/local/go/src/runtime/panic.go:464 +0x700
main.glob.func1(0x0, 0x0)
/tmp/sandbox715198144/main.go:9 +0x80
main.init()
/tmp/sandbox715198144/main.go:12 +0xa0
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论