MCPcopy
hub / github.com/canopy-network/canopy / TimeTrack

Function TimeTrack

lib/util.go:904–922  ·  view source on GitHub ↗

TimeTrack() a utility function to benchmark the time of caller function

(l LoggerI, start time.Time, logOnMax time.Duration)

Source from the content-addressed store, hash-verified

902
903// TimeTrack() a utility function to benchmark the time of caller function
904func 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
924func PrintStackTrace(print bool) (fns []string) {
925 pc := make([]uintptr, 10) // Get at most 10 stack frames

Callers 15

NewCertificateResultsMethod · 0.92
LoadRootChainInfoMethod · 0.92
GetPeerInfoMethod · 0.92
SendToMethod · 0.92
SendToPeersMethod · 0.92
HasMethod · 0.92
StopMethod · 0.92
StopMethod · 0.92
SendMethod · 0.92
sendWireBytesMethod · 0.92
queueSendsMethod · 0.92
sendLengthPrefixedFunction · 0.92

Calls 3

ContainsMethod · 0.65
NameMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected