Skip to content

Instantly share code, notes, and snippets.

@polynomialspace
Last active November 19, 2022 18:26
Show Gist options
  • Save polynomialspace/01cd5a32ef9f57ecf42adcfe4d5362a1 to your computer and use it in GitHub Desktop.
Save polynomialspace/01cd5a32ef9f57ecf42adcfe4d5362a1 to your computer and use it in GitHub Desktop.
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