IceLoggingStrategy.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package ArmarXCore::core::services::profiler
19 * @author Manfred Kroehnert ( manfred dot kroehnert at dot kit dot edu )
20 * @date 2015
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
25#include "IceLoggingStrategy.h"
26
27#include <map> // for _Rb_tree_const_iterator, etc
28#include <utility> // for pair
29
30#include <Ice/Config.h> // for Long
31#include <Ice/Handle.h> // for Handle
32#include <Ice/Object.h> // for Object
33#include <IceUtil/Handle.h> // for HandleBase
34
36#include "ArmarXCore/interface/core/Profiler.h"
37#include "ArmarXCore/interface/core/ThreadingIceBase.h" // for upCast
38#include <ArmarXCore/core/application/Application.h> // for Application
39
41 armarx::ProfilerListenerPrx profilerTopic) :
42 profilerListenerPrx(profilerTopic)
43{
44}
45
49
50void
52 uint64_t timestamp,
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)
58{
59 ProfilerEvent event = {processId,
60 Ice::Long(timestamp),
61 timestampUnit,
62 executableName,
63 eventName,
64 parentName,
65 functionName};
66 profilerListenerPrx->reportEvent(event);
67}
68
69void
71 const ProfilerStatechartTransition& transition)
72{
73 profilerListenerPrx->reportStatechartTransition(transition);
74}
75
76void
78 pid_t processId,
79 uint64_t timestamp,
80 const std::string& stateIdentifier,
81 const armarx::StateParameterMap& inputParameterMap)
82{
83 ProfilerStatechartParameters parameters = {
84 processId, Ice::Long(timestamp), stateIdentifier, inputParameterMap};
85 profilerListenerPrx->reportStatechartInputParameters(parameters);
86}
87
88void
90 pid_t processId,
91 uint64_t timestamp,
92 const std::string& stateIdentifier,
93 const armarx::StateParameterMap& localParameterMap)
94{
95 ProfilerStatechartParameters parameters = {
96 processId, Ice::Long(timestamp), stateIdentifier, localParameterMap};
97 profilerListenerPrx->reportStatechartLocalParameters(parameters);
98}
99
100void
102 pid_t processId,
103 uint64_t timestamp,
104 const std::string& stateIdentifier,
105 const armarx::StateParameterMap& outputParameterMap)
106{
107 ProfilerStatechartParameters parameters = {
108 processId, Ice::Long(timestamp), stateIdentifier, outputParameterMap};
109 profilerListenerPrx->reportStatechartOutputParameters(parameters);
110}
111
112void
114 pid_t processId,
115 uint64_t timestamp,
116 const TransitionIceBase& transition)
117{
119
120 ProfilerStatechartTransitionWithParameters profilerTransition =
122 processId, timestamp, transition);
123 profilerListenerPrx->reportStatechartTransitionWithParameters(profilerTransition);
124}
125
126void
128 uint64_t timestamp,
129 float cpuUsage)
130{
131 ProfilerProcessCpuUsage process = {
132 processId, Ice::Long(timestamp), ::armarx::Application::getInstance()->getName(), cpuUsage};
133 profilerListenerPrx->reportProcessCpuUsage(process);
134}
135
136void
138 u_int64_t timestamp,
139 int memoryUsage)
140{
141 ProfilerProcessMemoryUsage processMemoryUsage = {
142 processId,
143 Ice::Long(timestamp),
145 memoryUsage};
146 profilerListenerPrx->reportProcessMemoryUsage(processMemoryUsage);
147}
148
149#define ARMARX_ICE_LOGGING_BUFFER_SIZE 500
150
168
173
174armarx::StateParameterMap
176 const armarx::StateParameterMap& source)
177{
178 armarx::StateParameterMap destination;
179
180 for (armarx::StateParameterMap::const_iterator it = source.begin(); it != source.end(); it++)
181 {
182 destination[it->first] =
183 armarx::StateParameterIceBasePtr::dynamicCast(it->second->ice_clone());
184 }
185 return destination;
186}
187
188armarx::ProfilerStatechartTransitionWithParameters
190 pid_t processId,
191 uint64_t timestamp,
192 const armarx::TransitionIceBase& transition)
193{
194 StateIceBasePtr destinationState = StateIceBasePtr::dynamicCast(transition.destinationState);
195 ARMARX_CHECK_NOT_NULL(destinationState);
196
197 StateParameterMap inputCopy = copyDictionary(destinationState->inputParameters);
198 StateParameterMap localCopy = copyDictionary(destinationState->localParameters);
199 StateParameterMap outputCopy;
200 if (transition.sourceState)
201 {
202 outputCopy =
203 copyDictionary(StateIceBasePtr::dynamicCast(transition.sourceState)->outputParameters);
204 }
205
206 ProfilerStatechartTransitionWithParameters profilerTransition;
207 profilerTransition.processId = processId;
208 profilerTransition.timestamp = timestamp;
209
210 profilerTransition.sourceStateIdentifier =
211 transition.sourceState
212 ? StateIceBasePtr::dynamicCast(transition.sourceState)->globalStateIdentifier
213 : "";
214 profilerTransition.targetStateIdentifier = destinationState->globalStateIdentifier;
215 profilerTransition.targetStateType = destinationState->stateType;
216 profilerTransition.eventName = transition.evt->eventName;
217
218 profilerTransition.inputParameters = inputCopy;
219 profilerTransition.localParameters = localCopy;
220 profilerTransition.outputParameters = outputCopy;
221
222 return profilerTransition;
223}
224
225void
227 uint64_t timestamp,
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)
233{
234 ProfilerEvent event = {processId,
235 Ice::Long(timestamp),
236 executableName,
237 timestampUnit,
238 eventName,
239 parentName,
240 functionName};
241 {
242 std::unique_lock lock(profilerEventsMutex);
243 profilerEvents.push_back(event);
244 }
245}
246
247void
249 const ProfilerStatechartTransition& transition)
250{
251 std::unique_lock lock(profilerStatechartTransitionsMutex);
252 profilerStatechartTransitions.push_back(transition);
253}
254
255void
257 pid_t processId,
258 uint64_t timestamp,
259 const std::string& stateIdentifier,
260 const armarx::StateParameterMap& inputParameterMap)
261{
262 armarx::StateParameterMap copy = copyDictionary(inputParameterMap);
263
264 ProfilerStatechartParameters parameters = {
265 processId, Ice::Long(timestamp), stateIdentifier, copy};
266 {
267 std::unique_lock lock(profilerStatechartInputParametersMutex);
268 profilerStatechartInputParameters.push_back(parameters);
269 }
270}
271
272void
274 pid_t processId,
275 uint64_t timestamp,
276 const std::string& stateIdentifier,
277 const armarx::StateParameterMap& localParameterMap)
278{
279 armarx::StateParameterMap copy = copyDictionary(localParameterMap);
280 ProfilerStatechartParameters parameters = {
281 processId, Ice::Long(timestamp), stateIdentifier, copy};
282 {
283 std::unique_lock lock(profilerStatechartLocalParametersMutex);
284 profilerStatechartLocalParameters.push_back(parameters);
285 }
286}
287
288void
290 pid_t processId,
291 uint64_t timestamp,
292 const std::string& stateIdentifier,
293 const armarx::StateParameterMap& outputParameterMap)
294{
295 armarx::StateParameterMap copy = copyDictionary(outputParameterMap);
296 ProfilerStatechartParameters parameters = {
297 processId, Ice::Long(timestamp), stateIdentifier, copy};
298 {
299 std::unique_lock lock(profilerStatechartOutputParametersMutex);
300 profilerStatechartOutputParameters.push_back(parameters);
301 }
302}
303
304void
306 pid_t processId,
307 uint64_t timestamp,
308 const TransitionIceBase& transition)
309{
311
312 ProfilerStatechartTransitionWithParameters profilerTransition =
313 toProfilerTransition(processId, timestamp, transition);
314 {
316 profilerStatechartTransitionsWithParameters.push_back(profilerTransition);
317 }
318}
319
320void
322 uint64_t timestamp,
323 float cpuUsage)
324{
325 ProfilerProcessCpuUsage process = {
326 processId, Ice::Long(timestamp), ::armarx::Application::getInstance()->getName(), cpuUsage};
327 {
328 std::unique_lock lock(profilerCpuUsagesMutex);
329 profilerProcessCpuUsages.push_back(process);
330 }
331}
332
333void
335 uint64_t timestamp,
336 int memoryUsage)
337{
338 ProfilerProcessMemoryUsage processMemoryUsage = {
339 processId,
340 Ice::Long(timestamp),
342 memoryUsage};
343 {
344 std::unique_lock lock(profilerProcessMemoryUsagesMutex);
345 profilerProcessMemoryUsages.push_back(processMemoryUsage);
346 }
347}
348
349void
351{
352 if (!profilerEvents.empty())
353 {
354 ProfilerEventList eventsCopy;
355 {
356 std::unique_lock lock(profilerEventsMutex);
357 profilerEvents.swap(eventsCopy);
358 }
359 profilerListenerPrx->reportEventList(eventsCopy);
360 }
361
363 {
364 ProfilerStatechartTransitionList transitionsCopy;
365 {
366 std::unique_lock lock(profilerStatechartTransitionsMutex);
367 profilerStatechartTransitions.swap(transitionsCopy);
368 }
369 profilerListenerPrx->reportStatechartTransitionList(transitionsCopy);
370 }
371
373 {
374 ProfilerStatechartParametersList parametersCopy;
375 {
376 std::unique_lock lock(profilerStatechartInputParametersMutex);
377 profilerStatechartInputParameters.swap(parametersCopy);
378 }
379 profilerListenerPrx->reportStatechartInputParametersList(parametersCopy);
380 }
381
383 {
384 ProfilerStatechartParametersList parametersCopy;
385 {
386 std::unique_lock lock(profilerStatechartLocalParametersMutex);
387 profilerStatechartLocalParameters.swap(parametersCopy);
388 }
389 profilerListenerPrx->reportStatechartLocalParametersList(parametersCopy);
390 }
391
393 {
394 ProfilerStatechartParametersList parametersCopy;
395 {
396 std::unique_lock lock(profilerStatechartOutputParametersMutex);
397 profilerStatechartOutputParameters.swap(parametersCopy);
398 }
399 profilerListenerPrx->reportStatechartOutputParametersList(parametersCopy);
400 }
401
403 {
404 ProfilerStatechartTransitionWithParametersList transitionsWithParametersCopy;
405 {
407 profilerStatechartTransitionsWithParameters.swap(transitionsWithParametersCopy);
408 }
409 profilerListenerPrx->reportStatechartTransitionWithParametersList(
410 transitionsWithParametersCopy);
411 }
412
413 if (!profilerProcessCpuUsages.empty())
414 {
415 ProfilerProcessCpuUsageList cpuUsagesCopy;
416 {
417 std::unique_lock lock(profilerCpuUsagesMutex);
418 profilerProcessCpuUsages.swap(cpuUsagesCopy);
419 }
420 profilerListenerPrx->reportProcessCpuUsageList(cpuUsagesCopy);
421 }
422
423 if (!profilerProcessMemoryUsages.empty())
424 {
425 ProfilerProcessMemoryUsageList memoryUsageCopy;
426 {
427 std::unique_lock lock(profilerProcessMemoryUsagesMutex);
428 profilerProcessMemoryUsages.swap(memoryUsageCopy);
429 }
430
431 profilerListenerPrx->reportProcessMemoryUsageList(memoryUsageCopy);
432 }
433}
std::string timestamp()
#define ARMARX_ICE_LOGGING_BUFFER_SIZE
static ApplicationPtr getInstance()
Retrieve shared pointer to the application object.
The periodic task executes one thread method repeatedly using the time period specified in the constr...
void logStatechartTransitionWithParameters(pid_t processId, uint64_t timestamp, const TransitionIceBase &transition) override
void logStatechartOutputParameters(pid_t processId, uint64_t timestamp, const std::string &stateIdentifier, const armarx::StateParameterMap &outputParameterMap) override
ProfilerProcessMemoryUsageList profilerProcessMemoryUsages
void logStatechartInputParameters(pid_t processId, uint64_t timestamp, const std::string &stateIdentifier, const armarx::StateParameterMap &inputParameterMap) override
void 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) override
void logProcessCpuUsage(pid_t processId, uint64_t timestamp, float cpuUsage) override
void logStatechartLocalParameters(pid_t processId, uint64_t timestamp, const std::string &stateIdentifier, const armarx::StateParameterMap &localParameterMap) override
static armarx::StateParameterMap copyDictionary(const armarx::StateParameterMap &source)
ProfilerStatechartParametersList profilerStatechartOutputParameters
static ProfilerStatechartTransitionWithParameters toProfilerTransition(pid_t processId, uint64_t timestamp, const TransitionIceBase &transition)
void logStatechartTransition(const ProfilerStatechartTransition &transition) override
PeriodicTask< IceBufferedLoggingStrategy >::pointer_type publisherTask
void logProcessMemoryUsage(pid_t processId, u_int64_t timestamp, int memoryUsage) override
ProfilerProcessCpuUsageList profilerProcessCpuUsages
ProfilerStatechartTransitionWithParametersList profilerStatechartTransitionsWithParameters
IceBufferedLoggingStrategy(ProfilerListenerPrx profilerTopic)
ProfilerStatechartParametersList profilerStatechartInputParameters
ProfilerStatechartTransitionList profilerStatechartTransitions
ProfilerStatechartParametersList profilerStatechartLocalParameters
IceLoggingStrategy(ProfilerListenerPrx profilerTopic)
void logStatechartTransitionWithParameters(pid_t processId, uint64_t timestamp, const TransitionIceBase &transition) override
void logStatechartOutputParameters(pid_t processId, uint64_t timestamp, const std::string &stateIdentifier, const armarx::StateParameterMap &outputParameterMap) override
void logStatechartInputParameters(pid_t processId, uint64_t timestamp, const std::string &stateIdentifier, const armarx::StateParameterMap &inputParameterMap) override
void 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) override
void logProcessCpuUsage(pid_t processId, uint64_t timestamp, float cpuUsage) override
void logStatechartLocalParameters(pid_t processId, uint64_t timestamp, const std::string &stateIdentifier, const armarx::StateParameterMap &localParameterMap) override
void logStatechartTransition(const ProfilerStatechartTransition &transition) override
void logProcessMemoryUsage(pid_t processId, u_int64_t timestamp, int memoryUsage) override
#define ARMARX_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
void copyDictionary(const StringVariantContainerBaseMap &source, StringVariantContainerBaseMap &destination)
Clears the destination map and copies the parameters of the source in it.
#define ARMARX_TRACE
Definition trace.h:77