mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-12 02:26:26 +05:00
WarnExecTime util function
This commit is contained in:
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user