30 #include <Ice/Config.h>
31 #include <Ice/Handle.h>
32 #include <Ice/Object.h>
33 #include <IceUtil/Handle.h>
36 #include "ArmarXCore/interface/core/Profiler.h"
37 #include "ArmarXCore/interface/core/ThreadingIceBase.h"
41 armarx::ProfilerListenerPrx profilerTopic) :
42 profilerListenerPrx(profilerTopic)
53 const std::string& executableName,
54 const std::string& timestampUnit,
55 const std::string& eventName,
56 const std::string& parentName,
57 const std::string& functionName)
59 ProfilerEvent
event = {processId,
66 profilerListenerPrx->reportEvent(event);
71 const ProfilerStatechartTransition& transition)
73 profilerListenerPrx->reportStatechartTransition(transition);
80 const std::string& stateIdentifier,
83 ProfilerStatechartParameters parameters = {
84 processId,
Ice::Long(timestamp), stateIdentifier, inputParameterMap};
85 profilerListenerPrx->reportStatechartInputParameters(parameters);
92 const std::string& stateIdentifier,
95 ProfilerStatechartParameters parameters = {
96 processId,
Ice::Long(timestamp), stateIdentifier, localParameterMap};
97 profilerListenerPrx->reportStatechartLocalParameters(parameters);
104 const std::string& stateIdentifier,
107 ProfilerStatechartParameters parameters = {
108 processId,
Ice::Long(timestamp), stateIdentifier, outputParameterMap};
109 profilerListenerPrx->reportStatechartOutputParameters(parameters);
116 const TransitionIceBase& transition)
120 ProfilerStatechartTransitionWithParameters profilerTransition =
122 processId, timestamp, transition);
123 profilerListenerPrx->reportStatechartTransitionWithParameters(profilerTransition);
131 ProfilerProcessCpuUsage process = {
133 profilerListenerPrx->reportProcessCpuUsage(process);
141 ProfilerProcessMemoryUsage processMemoryUsage = {
146 profilerListenerPrx->reportProcessMemoryUsage(processMemoryUsage);
149 #define ARMARX_ICE_LOGGING_BUFFER_SIZE 500
152 armarx::ProfilerListenerPrx profilerTopic) :
153 profilerListenerPrx(profilerTopic)
171 publisherTask->stop();
180 for (armarx::StateParameterMap::const_iterator it =
source.begin(); it !=
source.end(); it++)
182 destination[it->first] =
183 armarx::StateParameterIceBasePtr::dynamicCast(it->second->ice_clone());
188 armarx::ProfilerStatechartTransitionWithParameters
192 const armarx::TransitionIceBase& transition)
194 StateIceBasePtr destinationState = StateIceBasePtr::dynamicCast(transition.destinationState);
200 if (transition.sourceState)
203 copyDictionary(StateIceBasePtr::dynamicCast(transition.sourceState)->outputParameters);
206 ProfilerStatechartTransitionWithParameters profilerTransition;
207 profilerTransition.processId = processId;
208 profilerTransition.timestamp = timestamp;
210 profilerTransition.sourceStateIdentifier =
211 transition.sourceState
212 ? StateIceBasePtr::dynamicCast(transition.sourceState)->globalStateIdentifier
214 profilerTransition.targetStateIdentifier = destinationState->globalStateIdentifier;
215 profilerTransition.targetStateType = destinationState->stateType;
216 profilerTransition.eventName = transition.evt->eventName;
218 profilerTransition.inputParameters = inputCopy;
219 profilerTransition.localParameters = localCopy;
220 profilerTransition.outputParameters = outputCopy;
222 return profilerTransition;
228 const std::string& executableName,
229 const std::string& timestampUnit,
230 const std::string& eventName,
231 const std::string& parentName,
232 const std::string& functionName)
234 ProfilerEvent
event = {processId,
242 std::unique_lock lock(profilerEventsMutex);
243 profilerEvents.push_back(event);
249 const ProfilerStatechartTransition& transition)
251 std::unique_lock lock(profilerStatechartTransitionsMutex);
252 profilerStatechartTransitions.push_back(transition);
259 const std::string& stateIdentifier,
264 ProfilerStatechartParameters parameters = {
267 std::unique_lock lock(profilerStatechartInputParametersMutex);
268 profilerStatechartInputParameters.push_back(parameters);
276 const std::string& stateIdentifier,
280 ProfilerStatechartParameters parameters = {
283 std::unique_lock lock(profilerStatechartLocalParametersMutex);
284 profilerStatechartLocalParameters.push_back(parameters);
292 const std::string& stateIdentifier,
296 ProfilerStatechartParameters parameters = {
299 std::unique_lock lock(profilerStatechartOutputParametersMutex);
300 profilerStatechartOutputParameters.push_back(parameters);
308 const TransitionIceBase& transition)
312 ProfilerStatechartTransitionWithParameters profilerTransition =
313 toProfilerTransition(processId, timestamp, transition);
315 std::unique_lock lock(profilerStatechartTransitionsWithParametersMutex);
316 profilerStatechartTransitionsWithParameters.push_back(profilerTransition);
325 ProfilerProcessCpuUsage process = {
328 std::unique_lock lock(profilerCpuUsagesMutex);
329 profilerProcessCpuUsages.push_back(process);
338 ProfilerProcessMemoryUsage processMemoryUsage = {
344 std::unique_lock lock(profilerProcessMemoryUsagesMutex);
345 profilerProcessMemoryUsages.push_back(processMemoryUsage);
352 if (!profilerEvents.empty())
354 ProfilerEventList eventsCopy;
356 std::unique_lock lock(profilerEventsMutex);
357 profilerEvents.swap(eventsCopy);
359 profilerListenerPrx->reportEventList(eventsCopy);
362 if (!profilerStatechartTransitions.empty())
364 ProfilerStatechartTransitionList transitionsCopy;
366 std::unique_lock lock(profilerStatechartTransitionsMutex);
367 profilerStatechartTransitions.swap(transitionsCopy);
369 profilerListenerPrx->reportStatechartTransitionList(transitionsCopy);
372 if (!profilerStatechartInputParameters.empty())
374 ProfilerStatechartParametersList parametersCopy;
376 std::unique_lock lock(profilerStatechartInputParametersMutex);
377 profilerStatechartInputParameters.swap(parametersCopy);
379 profilerListenerPrx->reportStatechartInputParametersList(parametersCopy);
382 if (!profilerStatechartLocalParameters.empty())
384 ProfilerStatechartParametersList parametersCopy;
386 std::unique_lock lock(profilerStatechartLocalParametersMutex);
387 profilerStatechartLocalParameters.swap(parametersCopy);
389 profilerListenerPrx->reportStatechartLocalParametersList(parametersCopy);
392 if (!profilerStatechartOutputParameters.empty())
394 ProfilerStatechartParametersList parametersCopy;
396 std::unique_lock lock(profilerStatechartOutputParametersMutex);
397 profilerStatechartOutputParameters.swap(parametersCopy);
399 profilerListenerPrx->reportStatechartOutputParametersList(parametersCopy);
402 if (!profilerStatechartTransitionsWithParameters.empty())
404 ProfilerStatechartTransitionWithParametersList transitionsWithParametersCopy;
406 std::unique_lock lock(profilerStatechartTransitionsWithParametersMutex);
407 profilerStatechartTransitionsWithParameters.swap(transitionsWithParametersCopy);
409 profilerListenerPrx->reportStatechartTransitionWithParametersList(
410 transitionsWithParametersCopy);
413 if (!profilerProcessCpuUsages.empty())
415 ProfilerProcessCpuUsageList cpuUsagesCopy;
417 std::unique_lock lock(profilerCpuUsagesMutex);
418 profilerProcessCpuUsages.swap(cpuUsagesCopy);
420 profilerListenerPrx->reportProcessCpuUsageList(cpuUsagesCopy);
423 if (!profilerProcessMemoryUsages.empty())
425 ProfilerProcessMemoryUsageList memoryUsageCopy;
427 std::unique_lock lock(profilerProcessMemoryUsagesMutex);
428 profilerProcessMemoryUsages.swap(memoryUsageCopy);
431 profilerListenerPrx->reportProcessMemoryUsageList(memoryUsageCopy);