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 
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 
89  public: void Fini();
90 
94  public: void StartTimer(const std::string &_name);
95 
98  public: void StopTimer(const std::string &_name);
99 
105  public: void Lap(const std::string &_name, const std::string &_prefix);
106 
109  public: int TimerCount() const;
110 
114  public: common::Time Time(const int _index) const;
115 
119  public: common::Time Time(const std::string &_label) const;
120 
124  public: std::string Label(const int _index) const;
125 
128  public: boost::filesystem::path LogPath() const;
129 
132  private: void Update(const common::UpdateInfo &_info);
133 
139  private: void AddTime(const std::string &_name,
140  const common::Time &_wallTime,
141  const common::Time &_elapsedtime);
142 
143  // Singleton implementation
144  private: friend class SingletonT<DiagnosticManager>;
145 
147  private: friend class DiagnosticTimer;
148 
151  private: std::unique_ptr<DiagnosticManagerPrivate> dataPtr;
152  };
153 
156  class GZ_UTIL_VISIBLE DiagnosticTimer : public common::Timer
157  {
160  public: explicit DiagnosticTimer(const std::string &_name);
161 
163  public: virtual ~DiagnosticTimer();
164 
167  public: void Lap(const std::string &_prefix);
168 
169  // Documentation inherited
170  public: virtual void Start();
171 
172  // Documentation inherited
173  public: virtual void Stop();
174 
177  public: const std::string Name() const;
178 
180  public: void InsertData(const std::string &_name,
181  const common::Time &_time);
182 
185  private: std::unique_ptr<DiagnosticTimerPrivate> dataPtr;
186  };
188  }
189 }
190 #endif
Forward declarations for the common classes.
Definition: Animation.hh:26
Singleton template class.
Definition: SingletonT.hh:33
A diagnostic manager class.
Definition: 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: Diagnostics.hh:156
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