diff --git a/components/camera/collector-diff.diff b/components/camera/collector-diff.diff new file mode 100644 index 00000000000..556b8c36291 --- /dev/null +++ b/components/camera/collector-diff.diff @@ -0,0 +1,51 @@ +diff --git a/data/collector.go b/data/collector.go +index 707014114..a7a2544ec 100644 +--- a/data/collector.go ++++ b/data/collector.go +@@ -78,6 +78,12 @@ type collector struct { + captureFunc CaptureFunc + target CaptureBufferedWriter + lastLoggedErrors map[string]int64 ++ ++ lastCaptureTime time.Time ++ captureCount int64 ++ captureMutex sync.Mutex ++ runningFrequency float64 ++ alpha float64 + } + + // Close closes the channels backing the Collector. It should always be called before disposing of a Collector to avoid +@@ -196,6 +202,25 @@ func (c *collector) getAndPushNextReading() { + return + } + ++ // debug freq calculation ++ c.captureMutex.Lock() ++ defer c.captureMutex.Unlock() ++ ++ if !c.lastCaptureTime.IsZero() { ++ elapsed := timeReceived.AsTime().Sub(c.lastCaptureTime).Seconds() ++ if elapsed > 0 { ++ frequency := 1.0 / elapsed ++ if c.runningFrequency == 0 { ++ c.runningFrequency = frequency ++ } else { ++ c.runningFrequency = c.alpha*frequency + (1-c.alpha)*c.runningFrequency ++ } ++ c.logger.Infow("capture frequency", "frequency_hz", frequency, "running_average_hz", c.runningFrequency) ++ } ++ } ++ c.lastCaptureTime = timeReceived.AsTime() ++ c.captureCount++ ++ + var msg v1.SensorData + switch v := reading.(type) { + case []byte: +@@ -279,6 +304,7 @@ func NewCollector(captureFunc CaptureFunc, params CollectorParams) (Collector, e + target: params.Target, + clock: c, + lastLoggedErrors: make(map[string]int64, 0), ++ alpha: 0.1, + }, nil + } + diff --git a/data/collector.go b/data/collector.go index 7070141147e..79c81197171 100644 --- a/data/collector.go +++ b/data/collector.go @@ -78,6 +78,8 @@ type collector struct { captureFunc CaptureFunc target CaptureBufferedWriter lastLoggedErrors map[string]int64 + + lastCaptureTime time.Time } // Close closes the channels backing the Collector. It should always be called before disposing of a Collector to avoid @@ -182,6 +184,8 @@ func (c *collector) getAndPushNextReading() { timeRequested := timestamppb.New(c.clock.Now().UTC()) reading, err := c.captureFunc(c.cancelCtx, c.params) timeReceived := timestamppb.New(c.clock.Now().UTC()) + latency := timeReceived.AsTime().Sub(timeRequested.AsTime()) + elapsed := timeReceived.AsTime().Sub(c.lastCaptureTime).Seconds() if c.cancelCtx.Err() != nil { return @@ -196,6 +200,21 @@ func (c *collector) getAndPushNextReading() { return } + // debug on success + if !c.lastCaptureTime.IsZero() { + if elapsed > 0 { + frequency := 1.0 / elapsed + c.logger.Infow("capture metrics", + "frequency_hz", frequency, + "latency_ms", latency.Milliseconds(), + "time_received", timeReceived.AsTime(), + ) + } else { + panic("oh no") + } + } + c.lastCaptureTime = timeReceived.AsTime() + var msg v1.SensorData switch v := reading.(type) { case []byte: diff --git a/web/cmd/server/main.go b/web/cmd/server/main.go index e8d3816d498..d17f178e0e1 100644 --- a/web/cmd/server/main.go +++ b/web/cmd/server/main.go @@ -3,12 +3,18 @@ package main import ( + "log" + "net/http" + "go.viam.com/utils" // registers all components. _ "go.viam.com/rdk/components/register" "go.viam.com/rdk/logging" + // registers all services. + _ "net/http/pprof" + _ "go.viam.com/rdk/services/register" "go.viam.com/rdk/web/server" ) @@ -16,5 +22,8 @@ import ( var logger = logging.NewDebugLogger("entrypoint") func main() { + go func() { + log.Println(http.ListenAndServe("0.0.0.0:6061", nil)) + }() utils.ContextualMain(server.RunServer, logger) }