32 #include "../observers/variant/TimestampVariant.h"
46 return "ProfilerObserver";
52 usingTopic(armarx::Profiler::PROFILER_TOPIC_NAME);
58 offerChannel(
"activeStateChanged",
"Channel reporting the currently active state of statecharts with EnableProfiling property set");
59 offerDataField(
"activeStateChanged",
"activeState",
VariantType::String,
"Name of the currently active state");
65 setDataField(
"activeStateChanged",
"activeState",
"");
73 if (!existsChannel(
id))
75 offerChannel(
id,
"Network traffic");
78 offerOrUpdateDataField(
id, protocol +
"_inBytes",
Variant(inBytes),
"Incoming network traffic");
79 offerOrUpdateDataField(
id, protocol +
"_outBytes",
Variant(outBytes),
"Outgoing network traffic");
90 std::string stateIdentifier =
event.parentName;
93 createStateChannelIfRequired(stateIdentifier);
95 int microsecondsModifier = 0;
96 if (event.timestampUnit ==
"ms")
98 microsecondsModifier = 1000;
100 else if (event.timestampUnit ==
"us")
102 microsecondsModifier = 1;
108 setDataField(stateIdentifier,
"lastEnterTimestamp", timestamp);
113 setDataField(stateIdentifier,
"lastExitTimestamp", timestamp);
114 setDataField(stateIdentifier,
"activeSubstate",
Variant(
""));
117 setDataFieldFlatCopy(stateIdentifier,
"previousSubstate", lastActiveState);
120 updateChannel(stateIdentifier);
121 ARMARX_INFO <<
"Updating function info channel " << stateIdentifier;
132 std::string
id = process.processName +
std::to_string(process.processId);
136 createResourceChannelIfRequired(
id);
138 setDataField(
id,
"cpuUsage",
Variant(process.cpuUsage));
149 std::string
id = memoryUsage.processName +
std::to_string(memoryUsage.processId);
153 createResourceChannelIfRequired(
id);
155 setDataField(
id,
"memoryUsage",
Variant(memoryUsage.memoryUsage));
170 Variant activeSubstate(transition.targetStateIdentifier);
171 setDataField(
"activeStateChanged",
"activeState", activeSubstate);
172 updateChannel(
"activeStateChanged");
174 std::string stateIdentifier = transition.parentStateIdentifier;
175 createStateChannelIfRequired(stateIdentifier);
177 setDataField(stateIdentifier,
"activeSubstate", activeSubstate);
178 setDataField(stateIdentifier,
"previousSubstate",
Variant(transition.sourceStateIdentifier));
179 setDataField(stateIdentifier,
"lastEventName",
Variant(transition.eventName));
180 updateChannel(stateIdentifier);
181 ARMARX_INFO <<
"Updating Transition info channel " << stateIdentifier;
192 for (
auto& entry : parameterMap)
194 variantMap.
addElement(entry.first, entry.second->value);
203 createStateChannelIfRequired(inputParameters.stateIdentifier);
206 StateParameterToVariantMap(inputParameters.parameterMap, parameters);
207 setDataField(inputParameters.stateIdentifier,
"inputParameters", parameters);
209 updateChannel(inputParameters.stateIdentifier);
222 createStateChannelIfRequired(localParameters.stateIdentifier);
225 StateParameterToVariantMap(localParameters.parameterMap, parameters);
226 setDataField(localParameters.stateIdentifier,
"localParameters", parameters);
228 updateChannel(localParameters.stateIdentifier);
240 createStateChannelIfRequired(outputParameters.stateIdentifier);
243 StateParameterToVariantMap(outputParameters.parameterMap, parameters);
244 setDataField(outputParameters.stateIdentifier,
"outputParameters", parameters);
245 updateChannel(outputParameters.stateIdentifier);
254 const armarx::ProfilerStatechartTransitionWithParameters& outputParameters,
const Ice::Current&)
261 void armarx::ProfilerObserver::createStateChannelIfRequired(
const std::string& channelName)
263 std::unique_lock lock(channelCheckMutex);
264 if (existsChannel(channelName))
269 offerChannel(channelName,
"Statechart State Channel");
271 offerDataField(channelName,
"activeSubstate",
VariantType::String,
"Currently Active Substate");
272 offerDataField(channelName,
"previousSubstate",
VariantType::String,
"Last Active Substate");
273 offerDataField(channelName,
"lastEventName",
VariantType::String,
"Last Event/Transition Name");
277 offerDataField(channelName,
"lastEnterTimestamp",
VariantType::Timestamp,
"Timestamp of when onEnter() of the state was last called");
278 offerDataField(channelName,
"lastExitTimestamp",
VariantType::Timestamp,
"Timestamp of when onExit() or onBreak() of the state was last called");
282 void armarx::ProfilerObserver::createResourceChannelIfRequired(
const std::string& channelName)
284 std::unique_lock lock(channelCheckMutex);
285 if (existsChannel(channelName))
290 offerChannel(channelName,
"Resource Information");
292 offerDataField(channelName,
"cpuUsage",
VariantType::Float,
"Cpu Usage of process specified by the channelname");
293 offerDataField(channelName,
"memoryUsage",
VariantType::Int,
"Memory Usage of process specified by the channelname");
307 armarx::ProfilerStatechartTransition lastTransition = transitions.back();
308 setDataField(
"activeStateChanged",
"activeState",
Variant(lastTransition.targetStateIdentifier));
309 updateChannel(
"activeStateChanged");
315 auto compareFunction = [](
const ProfilerStatechartParameters & lhs,
const ProfilerStatechartParameters & rhs)
317 return lhs.stateIdentifier < rhs.stateIdentifier;
319 std::set<ProfilerStatechartParameters, decltype(compareFunction)> latestElements(inputParametersList.rbegin(), inputParametersList.rend(), compareFunction);
321 for (
const auto& element : latestElements)
323 reportStatechartInputParameters(element);
330 auto compareFunction = [](
const ProfilerStatechartParameters & lhs,
const ProfilerStatechartParameters & rhs)
332 return lhs.stateIdentifier < rhs.stateIdentifier;
334 std::set<ProfilerStatechartParameters, decltype(compareFunction)> latestElements(localParametersList.rbegin(), localParametersList.rend(), compareFunction);
336 for (
const auto& element : latestElements)
338 reportStatechartLocalParameters(element);
345 auto compareFunction = [](
const ProfilerStatechartParameters & lhs,
const ProfilerStatechartParameters & rhs)
347 return lhs.stateIdentifier < rhs.stateIdentifier;
349 std::set<ProfilerStatechartParameters, decltype(compareFunction)> latestElements(outputParametersList.rbegin(), outputParametersList.rend(), compareFunction);
351 for (
const auto& element : latestElements)
353 reportStatechartOutputParameters(element);
358 const armarx::ProfilerStatechartTransitionWithParametersList& outputParameters,
const Ice::Current&)
366 auto compareFunction = [](
const ProfilerProcessCpuUsage & lhs,
const ProfilerProcessCpuUsage & rhs)
368 return lhs.processId < rhs.processId;
370 std::set<ProfilerProcessCpuUsage, decltype(compareFunction)> latestElements(processes.rbegin(), processes.rend(), compareFunction);
372 for (
const auto& element : latestElements)
374 reportProcessCpuUsage(element);
381 auto compareFunction = [](
const ProfilerProcessMemoryUsage & lhs,
const ProfilerProcessMemoryUsage & rhs)
383 return lhs.processId < rhs.processId;
385 std::set<ProfilerProcessMemoryUsage, decltype(compareFunction)> latestElements(memoryUsages.rbegin(), memoryUsages.rend(), compareFunction);
387 for (
const auto& element : latestElements)
389 reportProcessMemoryUsage(element);