WarnExecTime util function

This commit is contained in:
DanB
2019-08-01 23:44:09 +02:00
parent b909f76105
commit 118461c1f7

View File

@@ -992,3 +992,13 @@ type RatingPlanCostArg struct {
Usage string
*ArgDispatcher
}
// WarnExecTime is used when we need to meassure the execution of specific functions
// and warn when the total duration is higher than expected
// should be usually called with defer, ie: defer WarnExecTime(time.Now(), "MyTestFunc", time.Duration(2*time.Second))
func WarnExecTime(startTime time.Time, logID string, maxDur time.Duration) {
totalDur := time.Since(startTime)
if totalDur > maxDur {
Logger.Warning(fmt.Sprintf("<%s> execution took: <%s>", totalDur))
}
}