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 
44 
45 #ifdef ENABLE_DIAGNOSTICS
46  #define DIAG_TIMER_START(_name) \
50  gazebo::util::DiagnosticManager::Instance()->StartTimer(_name);
51 
57  #define DIAG_TIMER_LAP(_name, _prefix) \
58  gazebo::util::DiagnosticManager::Instance()->Lap(_name, _prefix);
59 
62  #define DIAG_TIMER_STOP(_name) \
63  gazebo::util::DiagnosticManager::Instance()->StopTimer(_name);
64 #else
65  #define DIAG_TIMER_START(_name) ((void) 0)
66  #define DIAG_TIMER_LAP(_name, _prefix) ((void)0)
67  #define DIAG_TIMER_STOP(_name) ((void) 0)
68 #endif
69 
73  public SingletonT<DiagnosticManager>
74  {
76  private: DiagnosticManager();
77 
79  private: virtual ~DiagnosticManager();
80 
83  public: void Init(const std::string &_worldName);
84 
88  public: void StartTimer(const std::string &_name);
89 
92  public: void StopTimer(const std::string &_name);
93 
99  public: void Lap(const std::string &_name, const std::string &_prefix);
100 
104  public: int GetTimerCount() const GAZEBO_DEPRECATED(7.0);
105 
108  public: int TimerCount() const;
109 
114  public: common::Time GetTime(int _index) const GAZEBO_DEPRECATED(7.0);
115 
119  public: common::Time Time(const int _index) const;
120 
125  public: common::Time GetTime(const std::string &_label) const
126  GAZEBO_DEPRECATED(7.0);
127 
131  public: common::Time Time(const std::string &_label) const;
132 
137  public: std::string GetLabel(int _index) const GAZEBO_DEPRECATED(7.0);
138 
142  public: std::string Label(const int _index) const;
143 
147  public: boost::filesystem::path GetLogPath() const GAZEBO_DEPRECATED(7.0);
148 
151  public: boost::filesystem::path LogPath() const;
152 
155  private: void Update(const common::UpdateInfo &_info);
156 
162  private: void AddTime(const std::string &_name,
163  const common::Time &_wallTime,
164  const common::Time &_elapsedtime);
165 
166  // Singleton implementation
167  private: friend class SingletonT<DiagnosticManager>;
168 
170  private: friend class DiagnosticTimer;
171 
174  private: std::unique_ptr<DiagnosticManagerPrivate> dataPtr;
175  };
176 
180  {
183  public: DiagnosticTimer(const std::string &_name);
184 
186  public: virtual ~DiagnosticTimer();
187 
190  public: void Lap(const std::string &_prefix);
191 
192  // Documentation inherited
193  public: virtual void Start();
194 
195  // Documentation inherited
196  public: virtual void Stop();
197 
201  public: const std::string GetName() const GAZEBO_DEPRECATED(7.0);
202 
205  public: const std::string Name() const;
206 
209  private: std::unique_ptr<DiagnosticTimerPrivate> dataPtr;
210  };
212  }
213 }
214 #endif
#define GAZEBO_DEPRECATED(version)
Definition: CommonTypes.hh:48
Singleton template class.
Definition: SingletonT.hh:33
A diagnostic manager class.
Definition: util/Diagnostics.hh:72
Information for use in an update event.
Definition: UpdateInfo.hh:30
#define GZ_UTIL_VISIBLE
Definition: system.hh:234
A timer class, used to time things in real world walltime.
Definition: Timer.hh:38
A timer designed for diagnostics.
Definition: util/Diagnostics.hh:179
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