Skip to content

Instantly share code, notes, and snippets.

@awreece
Created October 16, 2012 04:11
Show Gist options
  • Save awreece/3897192 to your computer and use it in GitHub Desktop.
Save awreece/3897192 to your computer and use it in GitHub Desktop.
Use the runtime.Caller() function!
func timeTrack(start time.Time) {
elapsed := time.Since(start)
fname := ""
pc, _, _, ok := runtime.Caller(1);
if ok {
fname = runtime.FuncForPC(pc).Name()
}
fmt.Printf("Function %s took %v\n", fname, elapsed);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment