Diagnostics.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 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 
33 GZ_SINGLETON_DECLARE(GZ_UTIL_VISIBLE, gazebo, util, DiagnosticManager)
34 
35 namespace gazebo
36 {
37  namespace util
38  {
39  // Forward declare private data class
40  class DiagnosticManagerPrivate;
41 
42  // Forward declare private data class
43  class DiagnosticTimerPrivate;
44 
49 
50 #ifdef ENABLE_DIAGNOSTICS
51  #define DIAG_TIMER_START(_name) \
55  gazebo::util::DiagnosticManager::Instance()->StartTimer(_name);
56 
62  #define DIAG_TIMER_LAP(_name, _prefix) \
63  gazebo::util::DiagnosticManager::Instance()->Lap(_name, _prefix);
64 
67  #define DIAG_TIMER_STOP(_name) \
68  gazebo::util::DiagnosticManager::Instance()->StopTimer(_name);
69 #else
70  #define DIAG_TIMER_START(_name) ((void) 0)
71  #define DIAG_TIMER_LAP(_name, _prefix) ((void)0)
72  #define DIAG_TIMER_STOP(_name) ((void) 0)
73 #endif
74 
77  class GZ_UTIL_VISIBLE DiagnosticManager :
78  public SingletonT<DiagnosticManager>
79  {
81  private: DiagnosticManager();
82 
84  private: virtual ~DiagnosticManager();
85 
88  public: void Init(const std::string &_worldName);
89 
92  public: void Fini();
93 
97  public: void StartTimer(const std::string &_name);
98 
101  public: void StopTimer(const std::string &_name);
102 
108  public: void Lap(const std::string &_name, const std::string &_prefix);
109 
112  public: int TimerCount() const;
113 
117  public: common::Time Time(const int _index) const;
118 
122  public: common::Time Time(const std::string &_label) const;
123 
127  public: std::string Label(const int _index) const;
128 
131  public: boost::filesystem::path LogPath() const;
132 
135  private: void Update(const common::UpdateInfo &_info);
136 
142  private: void AddTime(const std::string &_name,
143  const common::Time &_wallTime,
144  const common::Time &_elapsedtime);
145 
146  // Singleton implementation
147  private: friend class SingletonT<DiagnosticManager>;
148 
150  private: friend class DiagnosticTimer;
151 
154  private: std::unique_ptr<DiagnosticManagerPrivate> dataPtr;
155  };
156 
159  class GZ_UTIL_VISIBLE DiagnosticTimer : public common::Timer
160  {
163  public: explicit DiagnosticTimer(const std::string &_name);
164 
166  public: virtual ~DiagnosticTimer();
167 
170  public: void Lap(const std::string &_prefix);
171 
172  // Documentation inherited
173  public: virtual void Start();
174 
175  // Documentation inherited
176  public: virtual void Stop();
177 
180  public: const std::string Name() const;
181 
183  public: void InsertData(const std::string &_name,
184  const common::Time &_time);
185 
188  private: std::unique_ptr<DiagnosticTimerPrivate> dataPtr;
189  };
191  }
192 }
193 #endif
util
Definition: Diagnostics.hh:33
Forward declarations for the common classes.
Definition: Animation.hh:26
Singleton template class.
Definition: SingletonT.hh:33
A diagnostic manager class.
Definition: Diagnostics.hh:77
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: Diagnostics.hh:159
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
#define GZ_SINGLETON_DECLARE(visibility, n1, n2, singletonType)
Helper to declare typed SingletonT.
Definition: SingletonT.hh:61
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:47