28 static constexpr int livePlotPollFrequencyHz = 30;
31 std::shared_ptr<armem::gui::model::MemoryViewerModel>
model)
34 _model = std::move(
model);
42 _workerThread->quit();
43 _workerThread->wait();
49 LivePlotController::startWorker()
51 _workerThread =
new QThread();
53 _worker->moveToThread(_workerThread);
57 connect(_workerThread, &QThread::finished, _worker, &QObject::deleteLater);
58 connect(_workerThread, &QThread::finished, _workerThread, &QObject::deleteLater);
63 _workerThread->start();
69 return bool(_model->debugObserver());
75 std::lock_guard lock(_valuesMutex);
76 return std::find(_values.begin(), _values.end(),
id) != _values.end();
86 std::lock_guard lock(_valuesMutex);
87 return std::all_of(ids.begin(),
90 { return std::find(_values.begin(), _values.end(), id) != _values.end(); });
97 std::lock_guard lock(_valuesMutex);
100 auto it = std::find(_values.begin(), _values.end(),
id);
101 if (enable && it == _values.end())
103 _values.push_back(
id);
104 _usedChannels.insert(
107 else if (not enable && it != _values.end())
119 std::vector<LivePlotController::MemoryValueID>
122 std::lock_guard lock(_valuesMutex);
139 LivePlotController::removeAllChannels()
149 std::lock_guard lock(_valuesMutex);
150 channels = std::move(_usedChannels);
151 _usedChannels.clear();
155 for (
const std::string& channel :
channels)
159 observer->removeDebugChannel(channel);
173 _model = std::move(
model);
180 _timer =
new QTimer(
this);
181 _timer->setInterval(1000 / livePlotPollFrequencyHz);
182 connect(_timer, &QTimer::timeout,
this, &This::onPoll);
191 _timer->deleteLater();
194 _memoryToDebugObserver.reset();
195 _debugObserverHelper.reset();
203 if (not _model->debugObserver())
208 _debugObserverHelper =
209 std::make_unique<armarx::DebugObserverHelper>(_model->debugObserver(),
true);
212 .memoryNameSystem = _model->mns(),
213 .debugObserver = *_debugObserverHelper,
215 _memoryToDebugObserver = std::make_unique<armem::client::util::MemoryToDebugObserver>(
231 _memoryToDebugObserver.reset();
232 _debugObserverHelper.reset();
237 LivePlotWorker::onPoll()
239 if (not _memoryToDebugObserver)
244 std::map<std::string, std::set<std::string>> current;
247 current = _memoryToDebugObserver->pollOnce(_controller->
valuesSnapshot());
249 catch (
const std::exception& e)
253 <<
"Failed to send memory values to the debug observer: " << e.what();
259 <<
"Failed to send memory values to the debug observer (unknown error).";
263 removeStaleDatafields(current);
264 _lastPushed = std::move(current);
268 LivePlotWorker::removeStaleDatafields(
269 const std::map<std::string, std::set<std::string>>& current)
277 static const std::set<std::string>
empty;
278 for (
const auto& [channel, lastFields] : _lastPushed)
280 const auto it = current.find(channel);
281 const std::set<std::string>& currentFields = it != current.end() ? it->second :
empty;
283 for (
const std::string& field : lastFields)
285 if (currentFields.find(field) == currentFields.end())
289 observer->removeDebugDatafield(channel, field);
297 if (currentFields.empty())
301 observer->removeDebugChannel(channel);
SpamFilterDataPtr deactivateSpam(float deactivationDurationSec=10.0f, const std::string &identifier="", bool deactivate=true) const
disables the logging for the current line for the given amount of seconds.
void setTag(const LogTag &tag)
static std::string makeChannelName(const armem::MemoryID &memoryID)
Streams selected memory values to the DebugObserver for live plotting.
LivePlotController(std::shared_ptr< armem::gui::model::MemoryViewerModel > model)
bool allPlotted(const std::vector< MemoryValueID > &ids) const
bool isPlotted(const MemoryValueID &id) const
~LivePlotController() override
void setPlotted(const std::vector< MemoryValueID > &ids, bool enable)
armem::client::util::MemoryValueID MemoryValueID
bool hasDebugObserver() const
std::vector< MemoryValueID > valuesSnapshot() const
Background worker that does the (blocking) memory queries and DebugObserver calls.
LivePlotWorker(std::shared_ptr< armem::gui::model::MemoryViewerModel > model, LivePlotController *controller)
#define ARMARX_INFO
The normal logging level.
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugObserverInterface > DebugObserverInterfacePrx
bool empty(const std::string &s)