mirror of
https://github.com/netbirdio/netbird.git
synced 2026-04-22 18:26:41 +00:00
Add method timings with conditional logging
- Add timing measurements to key methods - Only log when duration exceeds 1 second
This commit is contained in:
@@ -1,5 +1,12 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// Difference returns the elements in `a` that aren't in `b`.
|
||||
func Difference(a, b []string) []string {
|
||||
mb := make(map[string]struct{}, len(b))
|
||||
@@ -50,3 +57,13 @@ func contains[T comparableObject[T]](slice []T, element T) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func TimeTrack(ctx context.Context, name string) func() {
|
||||
start := time.Now()
|
||||
return func() {
|
||||
elapsed := time.Since(start)
|
||||
if elapsed > time.Second {
|
||||
log.WithContext(ctx).Infof("Slow Call: [%s] took %s", name, elapsed)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user