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 
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 
105  public: int TimerCount() const;
106 
110  public: common::Time Time(const int _index) const;
111 
115  public: common::Time Time(const std::string &_label) const;
116 
120  public: std::string Label(const int _index) const;
121 
124  public: boost::filesystem::path LogPath() const;
125 
128  private: void Update(const common::UpdateInfo &_info);
129 
135  private: void AddTime(const std::string &_name,
136  const common::Time &_wallTime,
137  const common::Time &_elapsedtime);
138 
139  // Singleton implementation
140  private: friend class SingletonT<DiagnosticManager>;
141 
143  private: friend class DiagnosticTimer;
144 
147  private: std::unique_ptr<DiagnosticManagerPrivate> dataPtr;
148  };
149 
152  class GZ_UTIL_VISIBLE DiagnosticTimer : public common::Timer
153  {
156  public: DiagnosticTimer(const std::string &_name);
157 
159  public: virtual ~DiagnosticTimer();
160 
163  public: void Lap(const std::string &_prefix);
164 
165  // Documentation inherited
166  public: virtual void Start();
167 
168  // Documentation inherited
169  public: virtual void Stop();
170 
173  public: const std::string Name() const;
174 
177  private: std::unique_ptr<DiagnosticTimerPrivate> dataPtr;
178  };
180  }
181 }
182 #endif
Forward declarations for the common classes.
Definition: Animation.hh:33
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:152
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