##

Diagnostics.hh
Go to the documentation of this file.
/*
* Copyright (C) 2012 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef _GAZEBO_UTIL_DIAGNOSTICMANAGER_HH_
#define _GAZEBO_UTIL_DIAGNOSTICMANAGER_HH_
#include <string>
#include <boost/filesystem.hpp>
#include "gazebo/gazebo_config.h"
#include "gazebo/common/UpdateInfo.hh"
#include "gazebo/common/SingletonT.hh"
#include "gazebo/common/Timer.hh"
#include "gazebo/util/UtilTypes.hh"
#include "gazebo/util/system.hh"
GZ_SINGLETON_DECLARE(GZ_UTIL_VISIBLE, gazebo, util, DiagnosticManager)
namespace gazebo
{
namespace util
{
// Forward declare private data class
class DiagnosticManagerPrivate;
// Forward declare private data class
class DiagnosticTimerPrivate;
#ifdef ENABLE_DIAGNOSTICS
#define DIAG_TIMER_START(_name) \
gazebo::util::DiagnosticManager::Instance()->StartTimer(_name);
#define DIAG_TIMER_LAP(_name, _prefix) \
gazebo::util::DiagnosticManager::Instance()->Lap(_name, _prefix);
#define DIAG_TIMER_STOP(_name) \
gazebo::util::DiagnosticManager::Instance()->StopTimer(_name);
#else
#define DIAG_TIMER_START(_name) ((void) 0)
#define DIAG_TIMER_LAP(_name, _prefix) ((void)0)
#define DIAG_TIMER_STOP(_name) ((void) 0)
#endif
class GZ_UTIL_VISIBLE DiagnosticManager :
public SingletonT<DiagnosticManager>
{
private: DiagnosticManager();
private: virtual ~DiagnosticManager();
public: void Init(const std::string &_worldName);
public: void Fini();
public: void StartTimer(const std::string &_name);
public: void StopTimer(const std::string &_name);
public: void Lap(const std::string &_name, const std::string &_prefix);
public: int TimerCount() const;
public: common::Time Time(const int _index) const;
public: common::Time Time(const std::string &_label) const;
public: std::string Label(const int _index) const;
public: boost::filesystem::path LogPath() const;
private: void Update(const common::UpdateInfo &_info);
private: void AddTime(const std::string &_name,
const common::Time &_wallTime,
const common::Time &_elapsedtime);
// Singleton implementation
private: friend class SingletonT<DiagnosticManager>;
private: friend class DiagnosticTimer;
private: std::unique_ptr<DiagnosticManagerPrivate> dataPtr;
};
class GZ_UTIL_VISIBLE DiagnosticTimer : public common::Timer
{
public: explicit DiagnosticTimer(const std::string &_name);
public: virtual ~DiagnosticTimer();
public: void Lap(const std::string &_prefix);
// Documentation inherited
public: virtual void Start();
// Documentation inherited
public: virtual void Stop();
public: const std::string Name() const;
public: void InsertData(const std::string &_name,
const common::Time &_time);
private: std::unique_ptr<DiagnosticTimerPrivate> dataPtr;
};
}
}
#endif
UpdateInfo.hh
Timer.hh
gazebo
Forward declarations for the common classes.
Definition: Animation.hh:26
gazebo::common::Time
A Time class, can be used to hold wall- or sim-time. stored as sec and nano-sec.
Definition: Time.hh:47
SingletonT
Singleton template class.
Definition: SingletonT.hh:33
system.hh
util
util
Definition: Diagnostics.hh:33
gazebo
gazebo
Definition: Diagnostics.hh:33
gazebo::common::Timer
A timer class, used to time things in real world walltime.
Definition: Timer.hh:38
UtilTypes.hh
gazebo::msgs::Init
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
gazebo::util::DiagnosticTimer
A timer designed for diagnostics.
Definition: Diagnostics.hh:159
gazebo::util::DiagnosticManager
A diagnostic manager class.
Definition: Diagnostics.hh:77
GZ_SINGLETON_DECLARE
#define GZ_SINGLETON_DECLARE(visibility, n1, n2, singletonType)
Helper to declare typed SingletonT.
Definition: SingletonT.hh:61
gazebo::common::UpdateInfo
Information for use in an update event.
Definition: UpdateInfo.hh:30
SingletonT.hh