mirror of
https://github.com/turbot/steampipe.git
synced 2026-02-15 13:00:08 -05:00
29 lines
628 B
Go
29 lines
628 B
Go
package utils
|
|
|
|
import "time"
|
|
|
|
type LifecycleEvent struct {
|
|
Event string
|
|
Time time.Time
|
|
}
|
|
|
|
// LifecycleTimer records the time for lifecycle events
|
|
type LifecycleTimer struct {
|
|
events []*LifecycleEvent
|
|
}
|
|
|
|
func NewLifecycleTimer() *LifecycleTimer {
|
|
return &LifecycleTimer{}
|
|
}
|
|
|
|
// GetDuration returns the duration between first and the last event
|
|
func (r LifecycleTimer) GetDuration() time.Duration {
|
|
lastEvent := r.events[len(r.events)-1]
|
|
firstEvent := r.events[0]
|
|
return lastEvent.Time.Sub(firstEvent.Time)
|
|
}
|
|
|
|
func (r *LifecycleTimer) Add(event string) {
|
|
r.events = append(r.events, &LifecycleEvent{event, time.Now()})
|
|
}
|