Skip to content

Commit

Permalink
Print gap between collector ticks. (viamrobotics#710)
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronCasas authored Apr 11, 2022
1 parent 9a2cb30 commit 8e79f2f
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions data/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,26 +100,32 @@ func (c *collector) Collect() error {
}

func (c *collector) capture() {
_, span := trace.StartSpan(c.cancelCtx, "data::collector::capture")
defer span.End()

ticker := time.NewTicker(c.interval)
defer ticker.Stop()
var wg sync.WaitGroup
lastTick := time.Now()

for {
select {
case <-c.cancelCtx.Done():
wg.Wait()
close(c.queue)
return
case <-ticker.C:
c.getAndPushNextReading()
currTick := time.Now()
diff := currTick.Sub(lastTick).Microseconds()
if diff > 1800 {
c.logger.Debugf("took %d microseconds between ticks", diff)
}
lastTick = currTick
wg.Add(1)
go c.getAndPushNextReading(&wg)
}
}
}

func (c *collector) getAndPushNextReading() {
_, span := trace.StartSpan(c.cancelCtx, "data::collector::getAndPushNextReading")
defer span.End()
func (c *collector) getAndPushNextReading(wg *sync.WaitGroup) {
defer wg.Done()

timeRequested := timestamppb.New(time.Now().UTC())
reading, err := c.capturer.Capture(c.cancelCtx, c.params)
Expand Down

0 comments on commit 8e79f2f

Please sign in to comment.