mirror of
https://github.com/argoproj/argo-cd.git
synced 2026-02-20 01:28:45 +01:00
* group read comparison settings during app reconciliation * Reduce lock contention in clusterInfo::ensureSynced(). Add getRepoObj stats * Remove additional source of lock contention * Exclude the coordination.k8s.io/Lease resource Co-authored-by: Alexander Matyushentsev <amatyushentsev@gmail.com>
53 lines
957 B
Go
53 lines
957 B
Go
package stats
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
// mock out time.Now() for unit tests
|
|
var now = time.Now
|
|
|
|
// TimingStats is a helper to breakdown the timing of an expensive function call
|
|
// Usage:
|
|
// ts := NewTimingStats()
|
|
// ts.AddCheckpoint("checkpoint-1")
|
|
// ...
|
|
// ts.AddCheckpoint("checkpoint-2")
|
|
// ...
|
|
// ts.AddCheckpoint("checkpoint-3")
|
|
// ts.Timings()
|
|
type TimingStats struct {
|
|
StartTime time.Time
|
|
|
|
checkpoints []tsCheckpoint
|
|
}
|
|
|
|
type tsCheckpoint struct {
|
|
name string
|
|
time time.Time
|
|
}
|
|
|
|
func NewTimingStats() *TimingStats {
|
|
return &TimingStats{
|
|
StartTime: now(),
|
|
}
|
|
}
|
|
|
|
func (t *TimingStats) AddCheckpoint(name string) {
|
|
cp := tsCheckpoint{
|
|
name: name,
|
|
time: now(),
|
|
}
|
|
t.checkpoints = append(t.checkpoints, cp)
|
|
}
|
|
|
|
func (t *TimingStats) Timings() map[string]time.Duration {
|
|
timings := make(map[string]time.Duration)
|
|
prev := t.StartTime
|
|
for _, cp := range t.checkpoints {
|
|
timings[cp.name] = cp.time.Sub(prev)
|
|
prev = cp.time
|
|
}
|
|
return timings
|
|
}
|