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
28
30#include "gazebo/util/system.hh"
31
33GZ_SINGLETON_DECLARE(GZ_UTIL_VISIBLE, gazebo, util, DiagnosticManager)
34
35namespace 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
54 #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
gazebo
Definition Diagnostics.hh:33
util
Definition Diagnostics.hh:33
Singleton template class.
Definition SingletonT.hh:34
A Time class, can be used to hold wall- or sim-time.
Definition Time.hh:48
A timer class, used to time things in real world walltime.
Definition Timer.hh:39
Information for use in an update event.
Definition UpdateInfo.hh:31
A diagnostic manager class.
Definition Diagnostics.hh:79
void Fini()
Finish reporting diagnostics for a world.
std::string Label(const int _index) const
Get a label for a timer.
common::Time Time(const int _index) const
Get the time of a timer instance.
void StopTimer(const std::string &_name)
Stop a currently running timer.
void Init(const std::string &_worldName)
Initialize to report diagnostics about a world.
boost::filesystem::path LogPath() const
Get the path in which logs are stored.
void Lap(const std::string &_name, const std::string &_prefix)
Output the current elapsed time of an active timer with a prefix string.
common::Time Time(const std::string &_label) const
Get a time based on a label.
int TimerCount() const
Get the number of timers.
void StartTimer(const std::string &_name)
Start a new timer instance.
A timer designed for diagnostics.
Definition Diagnostics.hh:160
const std::string Name() const
Get the name of the timer.
DiagnosticTimer(const std::string &_name)
Constructor.
virtual ~DiagnosticTimer()
Destructor.
void InsertData(const std::string &_name, const common::Time &_time)
Insert data for statistics computation.
virtual void Start()
Start the timer.
void Lap(const std::string &_prefix)
Output a lap time.
virtual void Stop()
Stop the timer.
#define GZ_SINGLETON_DECLARE(visibility, n1, n2, singletonType)
Helper to declare typed SingletonT.
Definition SingletonT.hh:58
Forward declarations for the common classes.
Definition Animation.hh:27