Skip to content

Instantly share code, notes, and snippets.

@polynomialspace
Last active Dec 18, 2021
Embed
What would you like to do?
package main
import (
"fmt"
"runtime"
)
func trace() func() {
pc, file, line, _ := runtime.Caller(1)
fmt.Printf("%s:%d enter %s\n", file, line, runtime.FuncForPC(pc).Name())
return func() {
pc, file, line, _ := runtime.Caller(1)
fmt.Printf("%s:%d exit %s\n", file, line, runtime.FuncForPC(pc).Name())
}
}
func foo() {
defer trace()()
fmt.Println("lol")
}
func main() {
foo()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment