util/Diagnostics.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2016 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 #ifndef _GAZEBO_UTIL_DIAGNOSTICMANAGER_HH_
18 #define _GAZEBO_UTIL_DIAGNOSTICMANAGER_HH_
19 
20 #include <string>
21 #include <boost/filesystem.hpp>
22 
23 #include "gazebo/gazebo_config.h"
24 
27 #include "gazebo/common/Timer.hh"
28 
29 #include "gazebo/util/UtilTypes.hh"
30 #include "gazebo/util/system.hh"
31 
32 namespace gazebo
33 {
34  namespace util
35  {
36  // Forward declare private data class
37  class DiagnosticManagerPrivate;
38 
39  // Forward declare private data class
40  class DiagnosticTimerPrivate;
41 
46 
47 #ifdef ENABLE_DIAGNOSTICS
48  #define DIAG_TIMER_START(_name) \
52  gazebo::util::DiagnosticManager::Instance()->StartTimer(_name);
53 
59  #define DIAG_TIMER_LAP(_name, _prefix) \
60  gazebo::util::DiagnosticManager::Instance()->Lap(_name, _prefix);
61 
64  #define DIAG_TIMER_STOP(_name) \
65  gazebo::util::DiagnosticManager::Instance()->StopTimer(_name);
66 #else
67  #define DIAG_TIMER_START(_name) ((void) 0)
68  #define DIAG_TIMER_LAP(_name, _prefix) ((void)0)
69  #define DIAG_TIMER_STOP(_name) ((void) 0)
70 #endif
71 
74  class GZ_UTIL_VISIBLE DiagnosticManager :
75  public SingletonT<DiagnosticManager>
76  {
78  private: DiagnosticManager();
79 
81  private: virtual ~DiagnosticManager();
82 
85  public: void Init(const std::string &_worldName);
86 
90  public: void StartTimer(const std::string &_name);
91 
94  public: void StopTimer(const std::string &_name);
95 
101  public: void Lap(const std::string &_name, const std::string &_prefix);
102 
106  public: int GetTimerCount() const GAZEBO_DEPRECATED(7.0);
107 
110  public: int TimerCount() const;
111 
116  public: common::Time GetTime(int _index) const GAZEBO_DEPRECATED(7.0);
117 
121  public: common::Time Time(const int _index) const;
122 
127  public: common::Time GetTime(const std::string &_label) const
128  GAZEBO_DEPRECATED(7.0);
129 
133  public: common::Time Time(const std::string &_label) const;
134 
139  public: std::string GetLabel(int _index) const GAZEBO_DEPRECATED(7.0);
140 
144  public: std::string Label(const int _index) const;
145 
149  public: boost::filesystem::path GetLogPath() const GAZEBO_DEPRECATED(7.0);
150 
153  public: boost::filesystem::path LogPath() const;
154 
157  private: void Update(const common::UpdateInfo &_info);
158 
164  private: void AddTime(const std::string &_name,
165  const common::Time &_wallTime,
166  const common::Time &_elapsedtime);
167 
168  // Singleton implementation
169  private: friend class SingletonT<DiagnosticManager>;
170 
172  private: friend class DiagnosticTimer;
173 
176  private: std::unique_ptr<DiagnosticManagerPrivate> dataPtr;
177  };
178 
181  class GZ_UTIL_VISIBLE DiagnosticTimer : public common::Timer
182  {
185  public: DiagnosticTimer(const std::string &_name);
186 
188  public: virtual ~DiagnosticTimer();
189 
192  public: void Lap(const std::string &_prefix);
193 
194  // Documentation inherited
195  public: virtual void Start();
196 
197  // Documentation inherited
198  public: virtual void Stop();
199 
203  public: const std::string GetName() const GAZEBO_DEPRECATED(7.0);
204 
207  public: const std::string Name() const;
208 
211  private: std::unique_ptr<DiagnosticTimerPrivate> dataPtr;
212  };
214  }
215 }
216 #endif
Forward declarations for the common classes.
Definition: Animation.hh:33
#define GAZEBO_DEPRECATED(version)
Definition: CommonTypes.hh:48
Singleton template class.
Definition: SingletonT.hh:33
A diagnostic manager class.
Definition: util/Diagnostics.hh:74
Information for use in an update event.
Definition: UpdateInfo.hh:30
A timer class, used to time things in real world walltime.
Definition: Timer.hh:38
A timer designed for diagnostics.
Definition: util/Diagnostics.hh:181
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:44