TimeTrack() a utility function to benchmark the time of caller function
(l LoggerI, start time.Time, logOnMax time.Duration)
| 902 | |
| 903 | // TimeTrack() a utility function to benchmark the time of caller function |
| 904 | func TimeTrack(l LoggerI, start time.Time, logOnMax time.Duration) { |
| 905 | elapsed, functionName := time.Since(start), "unknown" |
| 906 | if elapsed < logOnMax { |
| 907 | return |
| 908 | } |
| 909 | pcs := make([]uintptr, 10) |
| 910 | n := runtime.Callers(2, pcs) |
| 911 | for _, pc := range pcs[:n] { |
| 912 | fn := runtime.FuncForPC(pc) |
| 913 | // skip anon functions |
| 914 | if fn != nil && !strings.Contains(fn.Name(), ".func") { |
| 915 | fullName := fn.Name() |
| 916 | parts := strings.Split(fullName, ".") |
| 917 | functionName = parts[len(parts)-1] |
| 918 | break |
| 919 | } |
| 920 | } |
| 921 | l.Errorf("*** %s took %s", functionName, elapsed) |
| 922 | } |
| 923 | |
| 924 | func PrintStackTrace(print bool) (fns []string) { |
| 925 | pc := make([]uintptr, 10) // Get at most 10 stack frames |
no test coverage detected