Profiler.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 #include <ArmarXCore/interface/statechart/StatechartIce.h>
28 
29 #include <IceUtil/Time.h>
30 
31 #include <memory>
32 #include <string>
33 #include <mutex>
34 #include <map>
35 #include <set>
36 
37 namespace armarx::Profiler
38 {
39  class Profiler;
40  using ProfilerPtr = std::shared_ptr<Profiler>;
41  using ProfilerSet = std::set<ProfilerPtr>;
42 
43  class LoggingStrategy;
44  using LoggingStrategyPtr = std::shared_ptr<LoggingStrategy>;
45 
88  class Profiler
89  {
90  public:
94  enum EventType
95  {
100  };
101 
102  using EventTypeMap = std::map<Profiler::EventType, std::string>;
103 
109  static std::string GetEventName(Profiler::EventType eventType);
110 
111  Profiler();
112  ~Profiler();
113 
114  void setName(const std::string& profilerName);
115 
116  void setLoggingStrategy(LoggingStrategyPtr loggingStrategy);
117 
118  void logProcessCpuUsage(float cpuUsage);
119  void logProcessMemoryUsage(int memoryUsage);
120  void logEvent(Profiler::EventType eventType, const std::string& parentName, const std::string& functionName);
121  void logStatechartTransition(const std::string& parentStateIdentifier, const StateIceBasePtr& sourceState, const StateIceBasePtr& destinationState, const std::string& eventName);
122  void logStatechartInputParameters(const std::string& stateIdentifier, const armarx::StateParameterMap& inputParameterMap);
123  void logStatechartLocalParameters(const std::string& stateIdentifier, const armarx::StateParameterMap& localParameterMap);
124  void logStatechartOutputParameters(const std::string& stateIdentifier, const armarx::StateParameterMap& outputParameterMap);
125 
126  void logStatechartTransitionWithParameters(const TransitionIceBase& transition);
127 
131  inline void reset();
132  protected:
133  std::string profilerName;
134 
135  private:
140  static const EventTypeMap& GetEventTypeMap();
141 
145  LoggingStrategyPtr logger;
146 
150  std::mutex loggerMutex;
151 
155  const std::string timestampUnit{"us"};
156  };
157 }
armarx::Profiler::Profiler::reset
void reset()
reset reinitializes armarx::Profiler::Profiler::startTime with the current time.
armarx::Profiler::Profiler::logProcessCpuUsage
void logProcessCpuUsage(float cpuUsage)
Definition: Profiler.cpp:111
armarx::Profiler
Definition: ManagedIceObject.h:72
armarx::Profiler::Profiler::eFunctionBreak
@ eFunctionBreak
Definition: Profiler.h:98
armarx::Profiler::Profiler::logStatechartTransition
void logStatechartTransition(const std::string &parentStateIdentifier, const StateIceBasePtr &sourceState, const StateIceBasePtr &destinationState, const std::string &eventName)
Definition: Profiler.cpp:77
armarx::Profiler::Profiler::logEvent
void logEvent(Profiler::EventType eventType, const std::string &parentName, const std::string &functionName)
Definition: Profiler.cpp:70
armarx::Profiler::ProfilerSet
std::set< ProfilerPtr > ProfilerSet
Definition: Profiler.h:41
armarx::Profiler::LoggingStrategy
A brief description.
Definition: LoggingStrategy.h:50
armarx::Profiler::Profiler::logStatechartInputParameters
void logStatechartInputParameters(const std::string &stateIdentifier, const armarx::StateParameterMap &inputParameterMap)
Definition: Profiler.cpp:93
armarx::Profiler::Profiler::eFunctionStart
@ eFunctionStart
Definition: Profiler.h:96
armarx::Profiler::Profiler::GetEventName
static std::string GetEventName(Profiler::EventType eventType)
getEventName maps enum values from armarx::Profiler::Profiler::EventType to strings
Definition: Profiler.cpp:31
armarx::Profiler::Profiler::logStatechartLocalParameters
void logStatechartLocalParameters(const std::string &stateIdentifier, const armarx::StateParameterMap &localParameterMap)
Definition: Profiler.cpp:99
armarx::Profiler::LoggingStrategyPtr
std::shared_ptr< LoggingStrategy > LoggingStrategyPtr
Definition: LoggingStrategy.h:42
armarx::Profiler::Profiler::logProcessMemoryUsage
void logProcessMemoryUsage(int memoryUsage)
Definition: Profiler.cpp:117
armarx::Profiler::Profiler::setName
void setName(const std::string &profilerName)
Definition: Profiler.cpp:50
armarx::Profiler::Profiler::eNumberEventTypes
@ eNumberEventTypes
Definition: Profiler.h:99
armarx::Profiler::Profiler::~Profiler
~Profiler()
Definition: Profiler.cpp:45
armarx::Profiler::Profiler::eFunctionReturn
@ eFunctionReturn
Definition: Profiler.h:97
armarx::statechartmodel::StateParameterMap
QMap< QString, StateParameterPtr > StateParameterMap
Definition: StateParameter.h:46
armarx::Profiler::Profiler
The armarx::Profiler::Profiler class can be used for timing executions within the ArmarX framework.
Definition: Profiler.h:88
armarx::Profiler::Profiler::logStatechartOutputParameters
void logStatechartOutputParameters(const std::string &stateIdentifier, const armarx::StateParameterMap &outputParameterMap)
Definition: Profiler.cpp:105
armarx::Profiler::Profiler::Profiler
Profiler()
Definition: Profiler.cpp:38
armarx::Profiler::Profiler::setLoggingStrategy
void setLoggingStrategy(LoggingStrategyPtr loggingStrategy)
Definition: Profiler.cpp:57
armarx::Profiler::Profiler::profilerName
std::string profilerName
Definition: Profiler.h:133
armarx::Profiler::Profiler::logStatechartTransitionWithParameters
void logStatechartTransitionWithParameters(const TransitionIceBase &transition)
Definition: Profiler.cpp:135
armarx::Profiler::Profiler::EventTypeMap
std::map< Profiler::EventType, std::string > EventTypeMap
Definition: Profiler.h:102
armarx::Profiler::ProfilerPtr
std::shared_ptr< Profiler > ProfilerPtr
Definition: ManagedIceObject.h:75
armarx::Profiler::Profiler::EventType
EventType
The EventType enum provides symbolic names for the different events which can be logged via armarx::P...
Definition: Profiler.h:94