26 #include <Ice/Config.h>
27 #include <Ice/Handle.h>
28 #include <Ice/Object.h>
29 #include <IceUtil/Handle.h>
34 #include "ArmarXCore/interface/core/Profiler.h"
35 #include "ArmarXCore/interface/core/ThreadingIceBase.h"
40 profilerListenerPrx(profilerTopic)
48 void armarx::Profiler::IceLoggingStrategy::logEvent(pid_t processId, uint64_t timestamp,
const std::string& executableName,
const std::string& timestampUnit,
const std::string& eventName,
const std::string& parentName,
const std::string& functionName)
50 ProfilerEvent
event = {processId,
Ice::Long(timestamp), timestampUnit, executableName, eventName, parentName, functionName};
51 profilerListenerPrx->reportEvent(event);
56 profilerListenerPrx->reportStatechartTransition(transition);
61 ProfilerStatechartParameters parameters = {processId,
Ice::Long(timestamp), stateIdentifier, inputParameterMap};
62 profilerListenerPrx->reportStatechartInputParameters(parameters);
67 ProfilerStatechartParameters parameters = {processId,
Ice::Long(timestamp), stateIdentifier, localParameterMap};
68 profilerListenerPrx->reportStatechartLocalParameters(parameters);
73 ProfilerStatechartParameters parameters = {processId,
Ice::Long(timestamp), stateIdentifier, outputParameterMap};
74 profilerListenerPrx->reportStatechartOutputParameters(parameters);
82 profilerListenerPrx->reportStatechartTransitionWithParameters(profilerTransition);
88 profilerListenerPrx->reportProcessCpuUsage(process);
94 profilerListenerPrx->reportProcessMemoryUsage(processMemoryUsage);
99 #define ARMARX_ICE_LOGGING_BUFFER_SIZE 500
102 profilerListenerPrx(profilerTopic)
119 publisherTask->stop();
126 for (armarx::StateParameterMap::const_iterator it =
source.begin(); it !=
source.end(); it++)
128 destination[it->first] = armarx::StateParameterIceBasePtr::dynamicCast(it->second->ice_clone());
133 armarx::ProfilerStatechartTransitionWithParameters
135 const armarx::TransitionIceBase& transition)
137 StateIceBasePtr destinationState = StateIceBasePtr::dynamicCast(transition.destinationState);
143 if (transition.sourceState)
145 outputCopy =
copyDictionary(StateIceBasePtr::dynamicCast(transition.sourceState)->outputParameters);
148 ProfilerStatechartTransitionWithParameters profilerTransition;
149 profilerTransition.processId = processId;
150 profilerTransition.timestamp = timestamp;
152 profilerTransition.sourceStateIdentifier = transition.sourceState ? StateIceBasePtr::dynamicCast(transition.sourceState)->globalStateIdentifier :
"";
153 profilerTransition.targetStateIdentifier = destinationState->globalStateIdentifier;
154 profilerTransition.targetStateType = destinationState->stateType;
155 profilerTransition.eventName = transition.evt->eventName;
157 profilerTransition.inputParameters = inputCopy;
158 profilerTransition.localParameters = localCopy;
159 profilerTransition.outputParameters = outputCopy;
161 return profilerTransition;
167 ProfilerEvent
event = { processId,
Ice::Long(timestamp), executableName, timestampUnit, eventName, parentName, functionName};
169 std::unique_lock lock(profilerEventsMutex);
170 profilerEvents.push_back(event);
176 std::unique_lock lock(profilerStatechartTransitionsMutex);
177 profilerStatechartTransitions.push_back(transition);
184 ProfilerStatechartParameters parameters = { processId,
Ice::Long(timestamp), stateIdentifier,
copy};
186 std::unique_lock lock(profilerStatechartInputParametersMutex);
187 profilerStatechartInputParameters.push_back(parameters);
194 ProfilerStatechartParameters parameters = { processId,
Ice::Long(timestamp), stateIdentifier,
copy};
196 std::unique_lock lock(profilerStatechartLocalParametersMutex);
197 profilerStatechartLocalParameters.push_back(parameters);
204 ProfilerStatechartParameters parameters = { processId,
Ice::Long(timestamp), stateIdentifier,
copy};
206 std::unique_lock lock(profilerStatechartOutputParametersMutex);
207 profilerStatechartOutputParameters.push_back(parameters);
215 ProfilerStatechartTransitionWithParameters profilerTransition = toProfilerTransition(processId, timestamp, transition);
217 std::unique_lock lock(profilerStatechartTransitionsWithParametersMutex);
218 profilerStatechartTransitionsWithParameters.push_back(profilerTransition);
227 std::unique_lock lock(profilerCpuUsagesMutex);
228 profilerProcessCpuUsages.push_back(process);
236 std::unique_lock lock(profilerProcessMemoryUsagesMutex);
237 profilerProcessMemoryUsages.push_back(processMemoryUsage);
243 if (!profilerEvents.empty())
245 ProfilerEventList eventsCopy;
247 std::unique_lock lock(profilerEventsMutex);
248 profilerEvents.swap(eventsCopy);
250 profilerListenerPrx->reportEventList(eventsCopy);
253 if (!profilerStatechartTransitions.empty())
255 ProfilerStatechartTransitionList transitionsCopy;
257 std::unique_lock lock(profilerStatechartTransitionsMutex);
258 profilerStatechartTransitions.swap(transitionsCopy);
260 profilerListenerPrx->reportStatechartTransitionList(transitionsCopy);
263 if (!profilerStatechartInputParameters.empty())
265 ProfilerStatechartParametersList parametersCopy;
267 std::unique_lock lock(profilerStatechartInputParametersMutex);
268 profilerStatechartInputParameters.swap(parametersCopy);
270 profilerListenerPrx->reportStatechartInputParametersList(parametersCopy);
273 if (!profilerStatechartLocalParameters.empty())
275 ProfilerStatechartParametersList parametersCopy;
277 std::unique_lock lock(profilerStatechartLocalParametersMutex);
278 profilerStatechartLocalParameters.swap(parametersCopy);
280 profilerListenerPrx->reportStatechartLocalParametersList(parametersCopy);
283 if (!profilerStatechartOutputParameters.empty())
285 ProfilerStatechartParametersList parametersCopy;
287 std::unique_lock lock(profilerStatechartOutputParametersMutex);
288 profilerStatechartOutputParameters.swap(parametersCopy);
290 profilerListenerPrx->reportStatechartOutputParametersList(parametersCopy);
293 if (!profilerStatechartTransitionsWithParameters.empty())
295 ProfilerStatechartTransitionWithParametersList transitionsWithParametersCopy;
297 std::unique_lock lock(profilerStatechartTransitionsWithParametersMutex);
298 profilerStatechartTransitionsWithParameters.swap(transitionsWithParametersCopy);
300 profilerListenerPrx->reportStatechartTransitionWithParametersList(transitionsWithParametersCopy);
303 if (!profilerProcessCpuUsages.empty())
305 ProfilerProcessCpuUsageList cpuUsagesCopy;
307 std::unique_lock lock(profilerCpuUsagesMutex);
308 profilerProcessCpuUsages.swap(cpuUsagesCopy);
310 profilerListenerPrx->reportProcessCpuUsageList(cpuUsagesCopy);
313 if (!profilerProcessMemoryUsages.empty())
315 ProfilerProcessMemoryUsageList memoryUsageCopy;
317 std::unique_lock lock(profilerProcessMemoryUsagesMutex);
318 profilerProcessMemoryUsages.swap(memoryUsageCopy);
321 profilerListenerPrx->reportProcessMemoryUsageList(memoryUsageCopy);