29#include <IceUtil/Time.h>
39#include <mongo/client/dbclient.h>
46 return "ProfilerStorage";
62 usingTopic(armarx::Profiler::PROFILER_TOPIC_NAME);
66 saveToLongtermMemoryTask =
69 this, &ProfilerStorage::saveTransitionsToLongtermMemory);
81 profilerDataSegmentPrx = longtermMemoryPrx->getProfilerDataSegment();
83 saveToLongtermMemoryTask->start();
84 saveTransitionsToLongtermMemoryTask->start();
96 saveToLongtermMemoryTask->stop();
97 saveTransitionsToLongtermMemoryTask->stop();
101 ProfilerStorage::saveToLongtermMemory()
103 IceUtil::Time t = IceUtil::Time::now();
107 size_t logSize = entityLog.size();
114 if ((logSize < 1000) && ((IceUtil::Time::now() - t).toMilliSeconds() < saveTimeout))
119 EntityBaseList entityLogCopy;
121 std::scoped_lock lock(entityLogMutex);
122 entityLog.swap(entityLogCopy);
124 t = IceUtil::Time::now();
125 profilerDataSegmentPrx->addEntityList(entityLogCopy);
127 <<
" [ms] to add " << entityLogCopy.size() <<
" Entities";
128 t = IceUtil::Time::now();
133 ProfilerStorage::saveTransitionsToLongtermMemory()
135 IceUtil::Time t = IceUtil::Time::now();
139 size_t logSize = transitionSnapshotList.size();
146 if ((logSize < 1000) && ((IceUtil::Time::now() - t).toMilliSeconds() < saveTimeout))
151 TransitionSnapshotList transitionSnapshotListCopy;
153 std::scoped_lock lock(transitionSnapshotListMutex);
154 transitionSnapshotList.swap(transitionSnapshotListCopy);
156 t = IceUtil::Time::now();
158 for (TransitionSnapshot& snapshot : transitionSnapshotListCopy)
160 std::string sourceSnapshot = profilerDataSegmentPrx->saveUniqueMemorySnapshot(
161 snapshot.sourceStateMemorySnapshot);
162 std::string targetSnapshot = profilerDataSegmentPrx->saveUniqueMemorySnapshot(
163 snapshot.targetStateMemorySnapshot);
164 EntityRefBasePtr sourceSnapshotRef =
165 profilerDataSegmentPrx->getEntityRefById(sourceSnapshot);
166 EntityRefBasePtr targetSnapshotRef =
167 profilerDataSegmentPrx->getEntityRefById(targetSnapshot);
169 new memoryx::ProfilerTransition(snapshot.transition.parentStateIdentifier,
170 snapshot.transition.sourceStateIdentifier,
171 snapshot.transition.targetStateIdentifier,
175 std::string entityId =
176 profilerDataSegmentPrx->saveOrUpdateTransition(profilerTransition);
179 <<
" [ms] to add " << transitionSnapshotListCopy.size()
181 t = IceUtil::Time::now();
198 std::scoped_lock lock(entityLogMutex);
204 const armarx::ProfilerStatechartTransition& transition,
205 const ::Ice::Current& context)
207 std::scoped_lock lock(transitionSnapshotListMutex);
208 TransitionSnapshot transitionSnapshot;
209 transitionSnapshot.transition = transition;
210 transitionSnapshot.sourceStateMemorySnapshot = memorySnapshot;
213 transitionSnapshot.targetStateMemorySnapshot = memorySnapshot;
214 transitionSnapshotList.push_back(transitionSnapshot);
219 const armarx::ProfilerStatechartParameters& inputParameters,
226 const armarx::ProfilerStatechartParameters& localParameters,
233 const armarx::ProfilerStatechartParameters& outputParameters,
240 const Ice::Current& context)
242 std::scoped_lock lock(entityLogMutex);
248 const Ice::Current& context)
250 std::scoped_lock lock(entityLogMutex);
257 memoryx::EntityBaseList eventEntities(events.size());
258 std::transform(events.begin(),
260 eventEntities.begin(),
261 [](
const armarx::ProfilerEvent& event)
262 { return new memoryx::ProfilerEvent(event); });
265 std::scoped_lock lock(entityLogMutex);
266 entityLog.insert(entityLog.end(), eventEntities.begin(), eventEntities.end());
272 const armarx::ProfilerStatechartTransitionList& transitions,
275 if (transitions.empty())
280 TransitionSnapshotList transitionSnapshots(transitions.size());
284 std::transform(transitions.begin(),
286 transitionSnapshots.begin(),
287 [](
const armarx::ProfilerStatechartTransition& transition)
289 TransitionSnapshot transitionSnapshot = {transition,
290 new ProfilerMemorySnapshot(),
291 new ProfilerMemorySnapshot()};
292 return transitionSnapshot;
295 transitionSnapshots.front().sourceStateMemorySnapshot = sourceMemorySnapshot;
297 transitionSnapshots.back().transition.targetStateIdentifier, workingMemoryPrx);
300 transitionSnapshots.back().targetStateMemorySnapshot = memorySnapshot;
303 std::scoped_lock lock(transitionSnapshotListMutex);
304 transitionSnapshotList.insert(transitionSnapshotList.end(),
305 transitionSnapshots.begin(),
306 transitionSnapshots.end());
312 const armarx::ProfilerStatechartParametersList& inputParametersList,
319 const armarx::ProfilerStatechartParametersList& localParametesList,
326 const armarx::ProfilerStatechartParametersList& outputParametersList,
335 memoryx::EntityBaseList eventEntities(processes.size());
336 std::transform(processes.begin(),
338 eventEntities.begin(),
339 [](
const armarx::ProfilerProcessCpuUsage& process)
340 { return new memoryx::ProfilerProcess(process); });
343 std::scoped_lock lock(entityLogMutex);
344 entityLog.insert(entityLog.end(), eventEntities.begin(), eventEntities.end());
350 const armarx::ProfilerProcessMemoryUsageList& memoryUsages,
353 memoryx::EntityBaseList eventEntities(memoryUsages.size());
354 std::transform(memoryUsages.begin(),
356 eventEntities.begin(),
357 [](
const armarx::ProfilerProcessMemoryUsage& memoryUsage)
358 { return new memoryx::ProfilerMemoryUsage(memoryUsage); });
361 std::scoped_lock lock(entityLogMutex);
362 entityLog.insert(entityLog.end(), eventEntities.begin(), eventEntities.end());
368 const std::string& stateName,
369 const WorkingMemoryInterfacePrx& workingMemoryProxy)
371 if (!workingMemoryProxy)
376 Ice::Context snapshot;
379 workingMemoryProxy->getObjectInstancesSegment()->getObjectInstanceByName(
"human"));
382 snapshot[
"human"] = humanInstance->getAttribute(
"name")->getValue()->getString();
383 if (humanInstance->hasAttribute(
"humanObject"))
385 snapshot[
"humanObject"] =
386 humanInstance->getAttribute(
"humanObject")->getValue()->getString();
389 if (humanInstance->hasAttribute(
"intention"))
391 snapshot[
"intention"] =
392 humanInstance->getAttribute(
"intention")->getValue()->getString();
397 workingMemoryProxy->getObjectInstancesSegment()->getObjectInstanceByName(
"taskObject"));
400 snapshot[
"taskObject"] = objectInstance->getAttribute(
"name")->getValue()->getString();
402 bool inHand = objectInstance->getAttribute(
"inHand")->getValue()->getBool();
403 snapshot[
"objectInHand"] = inHand ?
"true" :
"false";
436 const armarx::ProfilerStatechartTransitionWithParameters& transition,
437 const Ice::Current& context)
443 const armarx::ProfilerStatechartTransitionWithParametersList& transitions,
452 "SaveTimeout", 500,
"How often should the statistics be saved (ms)");
454 "CommonStorageName",
"CommonStorage",
"Name of the CommonStorage proxy to use");
456 "WorkingMemoryName",
"WorkingMemory",
"Name of the WorkingMemory proxy to use");
458 "LongtermMemoryName",
"LongtermMemory",
"Name of the LongtermMemory proxy to use");
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Property< PropertyType > getProperty(const std::string &name)
void setTag(const LogTag &tag)
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
void usingTopic(const std::string &name, bool orderedPublishing=false)
Registers a proxy for subscription after initialization.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
PropertyDefinition< PropertyType > & defineOptionalProperty(const std::string &name, PropertyType defaultValue, const std::string &description="", PropertyDefinitionBase::PropertyConstness constness=PropertyDefinitionBase::eConstant)
ProfilerStoragePropertyDefinitions(std::string prefix)
void reportProcessCpuUsage(const armarx::ProfilerProcessCpuUsage &process, const Ice::Current &context=Ice::emptyCurrent) override
void reportStatechartOutputParametersList(const armarx::ProfilerStatechartParametersList &outputParametersList, const Ice::Current &=Ice::emptyCurrent) override
void onInitComponent() override
std::string getCommonStorageName()
void reportStatechartTransitionWithParameters(const armarx::ProfilerStatechartTransitionWithParameters &transition, const ::Ice::Current &context=Ice::emptyCurrent) override
void reportProcessMemoryUsage(const armarx::ProfilerProcessMemoryUsage &memoryUsage, const Ice::Current &context=Ice::emptyCurrent) override
void reportStatechartTransitionWithParametersList(const armarx::ProfilerStatechartTransitionWithParametersList &transitions, const Ice::Current &=Ice::emptyCurrent) override
void onDisconnectComponent() override
void reportStatechartInputParametersList(const armarx::ProfilerStatechartParametersList &inputParametersList, const Ice::Current &=Ice::emptyCurrent) override
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
void reportStatechartOutputParameters(const armarx::ProfilerStatechartParameters &outputParameters, const Ice::Current &=Ice::emptyCurrent) override
void reportStatechartTransitionList(const armarx::ProfilerStatechartTransitionList &transitions, const Ice::Current &=Ice::emptyCurrent) override
std::string getLongtermMemoryName()
void reportStatechartLocalParametersList(const armarx::ProfilerStatechartParametersList &localParametesList, const Ice::Current &=Ice::emptyCurrent) override
void reportStatechartTransition(const armarx::ProfilerStatechartTransition &transition, const ::Ice::Current &context=Ice::emptyCurrent) override
void reportNetworkTraffic(const std::string &, const std::string &, Ice::Int, Ice::Int, const Ice::Current &context=Ice::emptyCurrent) override
reportNetworkTraffic
void reportEventList(const armarx::ProfilerEventList &events, const Ice::Current &=Ice::emptyCurrent) override
void onConnectComponent() override
static ProfilerMemorySnapshotPtr CreateProfilerMemorySnapshot(const std::string &stateName, const WorkingMemoryInterfacePrx &workingMemoryProxy)
void reportProcessMemoryUsageList(const armarx::ProfilerProcessMemoryUsageList &memoryUsages, const Ice::Current &=Ice::emptyCurrent) override
void reportEvent(const armarx::ProfilerEvent &profilerEvent, const Ice::Current &context=Ice::emptyCurrent) override
void onExitComponent() override
void reportStatechartInputParameters(const armarx::ProfilerStatechartParameters &inputParameters, const Ice::Current &=Ice::emptyCurrent) override
void reportStatechartLocalParameters(const armarx::ProfilerStatechartParameters &localParameters, const Ice::Current &=Ice::emptyCurrent) override
std::string getWorkingMemoryName()
void reportProcessCpuUsageList(const armarx::ProfilerProcessCpuUsageList &processes, const Ice::Current &=Ice::emptyCurrent) override
std::string getDefaultName() const override
#define ARMARX_WARNING_S
The logging level for unexpected behaviour, but not a serious problem.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
IceInternal::Handle< ProfilerMemorySnapshot > ProfilerMemorySnapshotPtr
IceInternal::Handle< ProfilerTransition > ProfilerTransitionPtr
IceInternal::Handle< ObjectInstance > ObjectInstancePtr