2016-04-15 6 views
1

Wenn ich ein Heap-Profil mit go tool pprof mache, sehe ich einige Einträge wie github.com/anacrolix/utp.glob.func1. Dies entspricht keiner benannten Funktion, die ich sehen kann, ich nehme an, es ist eine Schließung. Was bedeutet glob? Wie kann ich Namen wie diese der entsprechenden Funktion zuordnen? enter image description hereglob.func in pprof Heap-Profilen

Antwort

2

glob bezieht sich auf globale Umgebung, func1 bedeutet anonyme Funktion. Es sollte sich also auf eine globale anonyme Funktion beziehen. Prüfen this example und seine Panik Informationen:

Beispiel:

package main 

import (
    "fmt" 
) 

var (
    p = func() string { 
     panic("a") 

     return "asdf" 
    }() 
) 

func main() { 
    fmt.Println(p) 
} 

Panik Informationen:

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 
Verwandte Themen