IceLoggingStrategy.h
Go to the documentation of this file.
1 #pragma once
2 
3 /*
4  * This file is part of ArmarX.
5  *
6  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
7  *
8  * ArmarX is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation.
11  *
12  * ArmarX is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  * @package ArmarXCore::core::services::profiler
21  * @author Manfred Kroehnert ( manfred dot kroehnert at dot kit dot edu )
22  * @date 2015
23  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
24  * GNU General Public License
25  */
26 
27 
28 #include <ArmarXCore/interface/core/Profiler.h>
29 
30 #include <stdint.h> // for uint64_t
31 #include <sys/types.h> // for pid_t, u_int64_t
32 #include <string> // for string, operator<<
33 #include <vector> // for vector
34 #include <mutex>
35 
36 #include "../../services/tasks/PeriodicTask.h" // for PeriodicTask, etc
37 #include "ArmarXCore/interface/statechart/StatechartIce.h"
38 #include "LoggingStrategy.h" // for LoggingStrategy
39 
40 namespace armarx::Profiler
41 {
42  class IceLoggingStrategy;
43 
44  using IceLoggingStrategyPtr = std::shared_ptr<IceLoggingStrategy>;
45 
46  /**
47  * @class IceLoggingStrategy
48  * @ingroup Profiling
49  * @brief IceLoggingStrategy publishes incoming log method calls directly on IceLoggingStrategy::profilerListenerPrx.
50  *
51  * Instances of this strategy object is used by armarx::Profiler.
52  */
54  virtual public LoggingStrategy
55  {
56  public:
57  IceLoggingStrategy(ProfilerListenerPrx profilerTopic);
58 
59  ~IceLoggingStrategy() override;
60 
61  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;
62 
63  void logStatechartTransition(const ProfilerStatechartTransition& transition) override;
64  void logStatechartInputParameters(pid_t processId, uint64_t timestamp, const std::string& stateIdentifier, const armarx::StateParameterMap& inputParameterMap) override;
65  void logStatechartLocalParameters(pid_t processId, uint64_t timestamp, const std::string& stateIdentifier, const armarx::StateParameterMap& localParameterMap) override;
66  void logStatechartOutputParameters(pid_t processId, uint64_t timestamp, const std::string& stateIdentifier, const armarx::StateParameterMap& outputParameterMap) override;
67 
68  void logStatechartTransitionWithParameters(pid_t processId, uint64_t timestamp, const TransitionIceBase& transition) override;
69 
70  void logProcessCpuUsage(pid_t processId, uint64_t timestamp, float cpuUsage) override;
71  void logProcessMemoryUsage(pid_t processId, u_int64_t timestamp, int memoryUsage) override;
72  protected:
73  ProfilerListenerPrx profilerListenerPrx;
74  };
75 
76 
77  /**
78  * @class IceBufferdLoggingStrategy
79  * @ingroup Profiling
80  * @brief IceBufferdLoggingStrategy buffers incoming log method calls and publishes them as collections on IceLoggingStrategy::profilerListenerPrx.
81  *
82  * Instances of this strategy object is used by armarx::Profiler.
83  */
85  virtual public LoggingStrategy
86  {
87  public:
88  IceBufferedLoggingStrategy(ProfilerListenerPrx profilerTopic);
89 
90  ~IceBufferedLoggingStrategy() override;
91 
92  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;
93 
94  void logStatechartTransition(const ProfilerStatechartTransition& transition) override;
95  void logStatechartInputParameters(pid_t processId, uint64_t timestamp, const std::string& stateIdentifier, const armarx::StateParameterMap& inputParameterMap) override;
96  void logStatechartLocalParameters(pid_t processId, uint64_t timestamp, const std::string& stateIdentifier, const armarx::StateParameterMap& localParameterMap) override;
97  void logStatechartOutputParameters(pid_t processId, uint64_t timestamp, const std::string& stateIdentifier, const armarx::StateParameterMap& outputParameterMap) override;
98 
99  void logStatechartTransitionWithParameters(pid_t processId, uint64_t timestamp, const TransitionIceBase& transition) override;
100 
101  void logProcessCpuUsage(pid_t processId, uint64_t timestamp, float cpuUsage) override;
102  void logProcessMemoryUsage(pid_t processId, u_int64_t timestamp, int memoryUsage) override;
103 
104  static ProfilerStatechartTransitionWithParameters toProfilerTransition(pid_t processId, uint64_t timestamp, const TransitionIceBase& transition);
105 
106  protected:
107  void publishData();
109 
110 
112  ProfilerEventList profilerEvents;
113 
115  ProfilerStatechartTransitionList profilerStatechartTransitions;
116 
118  ProfilerStatechartParametersList profilerStatechartInputParameters;
119 
121  ProfilerStatechartParametersList profilerStatechartLocalParameters;
122 
124  ProfilerStatechartParametersList profilerStatechartOutputParameters;
125 
127  ProfilerStatechartTransitionWithParametersList profilerStatechartTransitionsWithParameters;
128 
130  ProfilerProcessCpuUsageList profilerProcessCpuUsages;
131 
133  ProfilerProcessMemoryUsageList profilerProcessMemoryUsages;
134 
135  ProfilerListenerPrx profilerListenerPrx;
136 
138  };
139 }
armarx::Profiler::IceLoggingStrategy::logEvent
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
Definition: IceLoggingStrategy.cpp:48
armarx::Profiler::IceLoggingStrategy::logProcessCpuUsage
void logProcessCpuUsage(pid_t processId, uint64_t timestamp, float cpuUsage) override
Definition: IceLoggingStrategy.cpp:85
armarx::Profiler::IceBufferedLoggingStrategy::profilerProcessMemoryUsages
ProfilerProcessMemoryUsageList profilerProcessMemoryUsages
Definition: IceLoggingStrategy.h:133
armarx::Profiler::IceLoggingStrategy::~IceLoggingStrategy
~IceLoggingStrategy() override
Definition: IceLoggingStrategy.cpp:44
armarx::Profiler::IceLoggingStrategy::logStatechartInputParameters
void logStatechartInputParameters(pid_t processId, uint64_t timestamp, const std::string &stateIdentifier, const armarx::StateParameterMap &inputParameterMap) override
Definition: IceLoggingStrategy.cpp:59
armarx::Profiler
Definition: ManagedIceObject.h:72
armarx::Profiler::IceBufferedLoggingStrategy::IceBufferedLoggingStrategy
IceBufferedLoggingStrategy(ProfilerListenerPrx profilerTopic)
Definition: IceLoggingStrategy.cpp:101
armarx::Profiler::IceBufferedLoggingStrategy::profilerEventsMutex
std::mutex profilerEventsMutex
Definition: IceLoggingStrategy.h:111
armarx::Profiler::IceBufferedLoggingStrategy::profilerStatechartInputParameters
ProfilerStatechartParametersList profilerStatechartInputParameters
Definition: IceLoggingStrategy.h:118
armarx::Profiler::LoggingStrategy
A brief description.
Definition: LoggingStrategy.h:50
armarx::Profiler::IceBufferedLoggingStrategy::publisherTask
PeriodicTask< IceBufferedLoggingStrategy >::pointer_type publisherTask
Definition: IceLoggingStrategy.h:137
armarx::Profiler::IceLoggingStrategy
IceLoggingStrategy publishes incoming log method calls directly on IceLoggingStrategy::profilerListen...
Definition: IceLoggingStrategy.h:53
armarx::Profiler::IceBufferedLoggingStrategy::profilerProcessCpuUsages
ProfilerProcessCpuUsageList profilerProcessCpuUsages
Definition: IceLoggingStrategy.h:130
armarx::Profiler::IceLoggingStrategy::IceLoggingStrategy
IceLoggingStrategy(ProfilerListenerPrx profilerTopic)
Definition: IceLoggingStrategy.cpp:39
armarx::Profiler::IceBufferedLoggingStrategy::logStatechartLocalParameters
void logStatechartLocalParameters(pid_t processId, uint64_t timestamp, const std::string &stateIdentifier, const armarx::StateParameterMap &localParameterMap) override
Definition: IceLoggingStrategy.cpp:191
armarx::Profiler::IceBufferedLoggingStrategy::copyDictionary
static armarx::StateParameterMap copyDictionary(const armarx::StateParameterMap &source)
Definition: IceLoggingStrategy.cpp:122
armarx::Profiler::IceBufferedLoggingStrategy::profilerStatechartLocalParameters
ProfilerStatechartParametersList profilerStatechartLocalParameters
Definition: IceLoggingStrategy.h:121
armarx::Profiler::IceBufferedLoggingStrategy::profilerStatechartLocalParametersMutex
std::mutex profilerStatechartLocalParametersMutex
Definition: IceLoggingStrategy.h:120
armarx::Profiler::IceBufferedLoggingStrategy::profilerProcessMemoryUsagesMutex
std::mutex profilerProcessMemoryUsagesMutex
Definition: IceLoggingStrategy.h:132
armarx::Profiler::IceBufferedLoggingStrategy::profilerStatechartOutputParameters
ProfilerStatechartParametersList profilerStatechartOutputParameters
Definition: IceLoggingStrategy.h:124
armarx::Profiler::IceBufferedLoggingStrategy::logStatechartTransition
void logStatechartTransition(const ProfilerStatechartTransition &transition) override
Definition: IceLoggingStrategy.cpp:174
armarx::statechartmodel::StateParameterMap
QMap< QString, StateParameterPtr > StateParameterMap
Definition: StateParameter.h:46
armarx::Profiler::IceBufferedLoggingStrategy::toProfilerTransition
static ProfilerStatechartTransitionWithParameters toProfilerTransition(pid_t processId, uint64_t timestamp, const TransitionIceBase &transition)
Definition: IceLoggingStrategy.cpp:134
armarx::Profiler::IceBufferedLoggingStrategy::logStatechartTransitionWithParameters
void logStatechartTransitionWithParameters(pid_t processId, uint64_t timestamp, const TransitionIceBase &transition) override
Definition: IceLoggingStrategy.cpp:211
armarx::Profiler::IceLoggingStrategy::logStatechartTransitionWithParameters
void logStatechartTransitionWithParameters(pid_t processId, uint64_t timestamp, const TransitionIceBase &transition) override
Definition: IceLoggingStrategy.cpp:77
armarx::Profiler::IceLoggingStrategy::logStatechartOutputParameters
void logStatechartOutputParameters(pid_t processId, uint64_t timestamp, const std::string &stateIdentifier, const armarx::StateParameterMap &outputParameterMap) override
Definition: IceLoggingStrategy.cpp:71
armarx::Profiler::IceBufferedLoggingStrategy::profilerStatechartTransitions
ProfilerStatechartTransitionList profilerStatechartTransitions
Definition: IceLoggingStrategy.h:115
armarx::Profiler::IceBufferedLoggingStrategy::logStatechartInputParameters
void logStatechartInputParameters(pid_t processId, uint64_t timestamp, const std::string &stateIdentifier, const armarx::StateParameterMap &inputParameterMap) override
Definition: IceLoggingStrategy.cpp:180
boost::source
Vertex source(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:681
armarx::Profiler::IceBufferedLoggingStrategy::logStatechartOutputParameters
void logStatechartOutputParameters(pid_t processId, uint64_t timestamp, const std::string &stateIdentifier, const armarx::StateParameterMap &outputParameterMap) override
Definition: IceLoggingStrategy.cpp:201
LoggingStrategy.h
armarx::Profiler::IceBufferedLoggingStrategy::profilerStatechartTransitionsWithParametersMutex
std::mutex profilerStatechartTransitionsWithParametersMutex
Definition: IceLoggingStrategy.h:126
armarx::Profiler::IceLoggingStrategyPtr
std::shared_ptr< IceLoggingStrategy > IceLoggingStrategyPtr
Definition: IceLoggingStrategy.h:44
armarx::Profiler::IceBufferedLoggingStrategy::profilerCpuUsagesMutex
std::mutex profilerCpuUsagesMutex
Definition: IceLoggingStrategy.h:129
IceUtil::Handle
Definition: forward_declarations.h:29
armarx::Profiler::IceBufferedLoggingStrategy::logProcessMemoryUsage
void logProcessMemoryUsage(pid_t processId, u_int64_t timestamp, int memoryUsage) override
Definition: IceLoggingStrategy.cpp:232
armarx::Profiler::IceBufferedLoggingStrategy::profilerStatechartTransitionsWithParameters
ProfilerStatechartTransitionWithParametersList profilerStatechartTransitionsWithParameters
Definition: IceLoggingStrategy.h:127
armarx::Profiler::IceBufferedLoggingStrategy::logEvent
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
Definition: IceLoggingStrategy.cpp:165
armarx::Profiler::IceBufferedLoggingStrategy::profilerStatechartInputParametersMutex
std::mutex profilerStatechartInputParametersMutex
Definition: IceLoggingStrategy.h:117
armarx::Profiler::IceBufferedLoggingStrategy::profilerStatechartOutputParametersMutex
std::mutex profilerStatechartOutputParametersMutex
Definition: IceLoggingStrategy.h:123
armarx::Profiler::IceBufferedLoggingStrategy::publishData
void publishData()
Definition: IceLoggingStrategy.cpp:241
armarx::Profiler::IceBufferedLoggingStrategy::profilerEvents
ProfilerEventList profilerEvents
Definition: IceLoggingStrategy.h:112
armarx::Profiler::IceBufferedLoggingStrategy::profilerStatechartTransitionsMutex
std::mutex profilerStatechartTransitionsMutex
Definition: IceLoggingStrategy.h:114
armarx::Profiler::IceBufferedLoggingStrategy
Definition: IceLoggingStrategy.h:84
armarx::Profiler::IceLoggingStrategy::profilerListenerPrx
ProfilerListenerPrx profilerListenerPrx
Definition: IceLoggingStrategy.h:73
armarx::Profiler::IceBufferedLoggingStrategy::~IceBufferedLoggingStrategy
~IceBufferedLoggingStrategy() override
Definition: IceLoggingStrategy.cpp:117
armarx::Profiler::IceLoggingStrategy::logProcessMemoryUsage
void logProcessMemoryUsage(pid_t processId, u_int64_t timestamp, int memoryUsage) override
Definition: IceLoggingStrategy.cpp:91
armarx::Profiler::IceLoggingStrategy::logStatechartLocalParameters
void logStatechartLocalParameters(pid_t processId, uint64_t timestamp, const std::string &stateIdentifier, const armarx::StateParameterMap &localParameterMap) override
Definition: IceLoggingStrategy.cpp:65
armarx::Profiler::IceBufferedLoggingStrategy::profilerListenerPrx
ProfilerListenerPrx profilerListenerPrx
Definition: IceLoggingStrategy.h:135
armarx::Profiler::IceBufferedLoggingStrategy::logProcessCpuUsage
void logProcessCpuUsage(pid_t processId, uint64_t timestamp, float cpuUsage) override
Definition: IceLoggingStrategy.cpp:223
armarx::Profiler::IceLoggingStrategy::logStatechartTransition
void logStatechartTransition(const ProfilerStatechartTransition &transition) override
Definition: IceLoggingStrategy.cpp:54