diff --git a/utils/coreutils.go b/utils/coreutils.go index 41efc74fb..57d1fac95 100644 --- a/utils/coreutils.go +++ b/utils/coreutils.go @@ -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)) + } +}