Class
List
Hierarchy
Modules
Common
Events
Math
Messages
Physics
Rendering
Sensors
Transport
Links
Gazebo Website
Wiki
Tutorials
Download
Report Documentation Issues
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
gazebo
common
Diagnostics.hh
Go to the documentation of this file.
1
/*
2
* Copyright 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
/* Desc: A diagnostic class
18
* Author: Nate Koenig
19
* Date: 2 Feb 2011
20
*/
21
22
#ifndef _DIAGNOSTICMANAGER_HH_
23
#define _DIAGNOSTICMANAGER_HH_
24
25
#include <map>
26
#include <string>
27
28
#include "
common/SingletonT.hh
"
29
#include "
common/Timer.hh
"
30
31
namespace
gazebo
32
{
33
namespace
common
34
{
37
39
#define DIAG_TIMER(name) DiagnosticManager::Instance()->CreateTimer(name);
40
41
class
DiagnosticTimer
;
42
typedef
boost::shared_ptr< DiagnosticTimer >
DiagnosticTimerPtr
;
43
46
class
DiagnosticManager
:
public
SingletonT
<DiagnosticManager>
47
{
49
private
:
DiagnosticManager
();
50
52
private
:
virtual
~
DiagnosticManager
();
53
57
public
:
DiagnosticTimerPtr
CreateTimer
(
const
std::string &_name);
58
61
public
:
void
TimerStart
(
DiagnosticTimer
*_timer);
62
65
public
:
void
TimerStop
(
DiagnosticTimer
*_timer);
66
69
public
:
int
GetTimerCount
()
const
;
70
74
public
:
Time
GetTime
(
int
_index)
const
;
75
79
public
:
Time
GetTime
(
const
std::string &_label)
const
;
80
84
public
: std::string
GetLabel
(
int
_index)
const
;
85
88
public
:
void
SetEnabled
(
bool
_e) {this->enabled = _e;}
89
92
public
:
inline
bool
GetEnabled
()
const
{
return
this->enabled;}
93
95
private
:
bool
enabled;
96
98
private
: std::map<std::string, Time> timers;
99
100
// Singleton implementation
101
private
:
friend
class
SingletonT
<
DiagnosticManager
>;
102
};
103
106
class
DiagnosticTimer
:
public
Timer
107
{
110
public
:
DiagnosticTimer
(
const
std::string &_name) :
Timer
()
111
{
112
this->
Start
();
113
this->name = _name;
114
this->diagManager->
TimerStart
(
this
);
115
}
116
118
public
:
virtual
~DiagnosticTimer
()
119
{
120
this->diagManager->
TimerStop
(
this
);
121
}
122
125
public
:
inline
const
std::string
GetName
()
const
126
{
return
this->name; }
127
129
private
: std::string name;
130
132
private
:
static
DiagnosticManager
*diagManager;
133
};
135
}
136
}
137
#endif