class mola::MetricChannelImpl
Overview
Concrete MetricChannel : a bounded, thread-safe rolling buffer of samples.
Modelled on ConsoleLogSink : a shared_ptr sink written to by producer threads and read by the GUI thread, a rolling buffer bounded by time, a lock-free version() change hint, and an atomic gate letting producers early-out cheaply while nobody is plotting.
#include <MetricsRegistry.h> class MetricChannelImpl: public mola::MetricChannel { public: // typedefs typedef std::shared_ptr<MetricChannelImpl> Ptr; // fields const std::string name; const std::string unit; const ImVec4 color; std::atomic<double> retention_seconds {10.0}; // construction MetricChannelImpl( std::string channelName, std::string channelUnit, ImVec4 channelColor, std::shared_ptr<std::atomic<bool>> anyWindowOpen ); // methods virtual void push(double t, double value); void copy_span(double t_min, std::vector<double>& xs, std::vector<double>& ys) const; uint64_t version() const; };
Inherited Members
public: // typedefs typedef std::shared_ptr<MetricChannel> Ptr; // methods MetricChannel& operator = (const MetricChannel&); MetricChannel& operator = (MetricChannel&&); virtual void push(double t, double value) = 0; void push(double value);
Fields
std::atomic<double> retention_seconds {10.0}
Rolling history length; the widest span among all plot windows currently showing this channel (capped by nothing here callers decide the cap; default 10 s, see MolaVizImGuiCore::plots_default_retention_seconds_).
Methods
virtual void push(double t, double value)
Appends one sample.
Parameters:
t |
Timestamp in seconds, using any monotonic clock consistent across calls for this channel. Using wall-clock time ( |
value |
Sample value. |
void copy_span(double t_min, std::vector<double>& xs, std::vector<double>& ys) const
Appends the samples with t >= t_min to the (caller-owned, reused) output buffers, oldest first. Both buffers use double ImPlot’s PlotLine()/PlotScatter() require the x and y arrays to share one type.
uint64_t version() const
Bumped on every push(). Lock-free, so the renderer can skip copy_span() when nothing changed since the last rendered frame.