From 118461c1f7d7cd6eee28bd4b433c45edd4fc5dfd Mon Sep 17 00:00:00 2001 From: DanB Date: Thu, 1 Aug 2019 23:44:09 +0200 Subject: [PATCH] WarnExecTime util function --- utils/coreutils.go | 10 ++++++++++ 1 file changed, 10 insertions(+) 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)) + } +}