ScopedTimer.h
Go to the documentation of this file.
00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
00002 
00003 // -- BEGIN LICENSE BLOCK ----------------------------------------------
00004 // This file is part of FZIs ic_workspace.
00005 //
00006 // This program is free software licensed under the LGPL
00007 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
00008 // You can find a copy of this license in LICENSE folder in the top
00009 // directory of the source code.
00010 //
00011 // © Copyright 2014 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00012 //
00013 // -- END LICENSE BLOCK ------------------------------------------------
00014 
00015 //----------------------------------------------------------------------
00022 //----------------------------------------------------------------------
00023 #ifndef ICL_CORE_LOGGING_SCOPED_TIMER_H_INCLUDED
00024 #define ICL_CORE_LOGGING_SCOPED_TIMER_H_INCLUDED
00025 
00026 #include <boost/preprocessor/cat.hpp>
00027 
00028 #include "icl_core/TimeStamp.h"
00029 #include "icl_core/TimeSpan.h"
00030 #include "icl_core_logging/LogLevel.h"
00031 #include "icl_core_logging/LoggingMacros_SLOGGING.h"
00032 
00033 namespace icl_core {
00034 namespace logging {
00035 
00041 template <typename TStreamName>
00042 class ScopedTimer
00043 {
00044 public:
00062   ScopedTimer(const std::string& description = "ScopedTimer",
00063               const LogLevel level = eLL_DEBUG,
00064               const std::string& filename = __FILE__,
00065               const std::size_t line = __LINE__,
00066               const std::string& classname = "",
00067               const std::string& objectname = "")
00068     : m_description(description),
00069       m_level(level),
00070       m_filename(filename),
00071       m_line(line),
00072       m_classname(classname),
00073       m_objectname(objectname),
00074       m_start_time(TimeStamp::now()),
00075       m_active(true)
00076   { }
00077 
00079   void print() const
00080   {
00081     ::icl_core::logging::LogStream& stream = TStreamName::instance();
00082     SLOGGING_LOG_FLCO(stream, m_level, m_filename.c_str(), m_line, m_classname.c_str(), m_objectname.c_str(),
00083                       "" << m_description << ": "
00084                       << (TimeStamp::now() - m_start_time).toNSec() << " ns" << endl);
00085   }
00086 
00088   void print(const std::string& extra_description) const
00089   {
00090     ::icl_core::logging::LogStream& stream = TStreamName::instance();
00091     SLOGGING_LOG_FLCO(stream, m_level, m_filename.c_str(), m_line, m_classname.c_str(), m_objectname.c_str(),
00092                       "" << m_description << " (" << extra_description << "): "
00093                       << (TimeStamp::now() - m_start_time).toNSec() << " ns" << endl);
00094   }
00095 
00099   inline void stop()
00100   {
00101     if (m_active)
00102     {
00103       print();
00104     }
00105     m_active = false;
00106   }
00107 
00111   ~ScopedTimer()
00112   {
00113     if (m_active)
00114     {
00115       print();
00116     }
00117   }
00118 
00119 private:
00120   const std::string m_description;
00121   const LogLevel m_level;
00122   const std::string m_filename;
00123   const std::size_t m_line;
00124   const std::string m_classname;
00125   const std::string m_objectname;
00126   const TimeStamp m_start_time;
00127   bool m_active;
00128 };
00129 
00130 }
00131 }
00132 
00133 #define LOGGING_SCOPED_TIMER_VFLCO(streamname, varname, description, level, filename, line, classname, objectname) \
00134   ::icl_core::logging::ScopedTimer<streamname> varname(description, level, filename, line, classname, objectname)
00135 #define LOGGING_SCOPED_TIMER_VCO(streamname, varname, description, level, classname, objectname) \
00136   LOGGING_SCOPED_TIMER_VFLCO(streamname, varname, description, level, __FILE__, __LINE__, classname, objectname)
00137 #define LOGGING_SCOPED_TIMER_VC(streamname, varname, description, level, classname) \
00138   LOGGING_SCOPED_TIMER_VFLCO(streamname, varname, description, level, __FILE__, __LINE__, classname, "")
00139 #define LOGGING_SCOPED_TIMER_V(streamname, varname, description, level) \
00140   LOGGING_SCOPED_TIMER_VFLCO(streamname, varname, description, level, __FILE__, __LINE__, "", "")
00141 
00142 #define LOGGING_SCOPED_TIMER_FLCO(streamname, description, level, filename, line, classname, objectname) \
00143   LOGGING_SCOPED_TIMER_VFLCO(streamname, BOOST_PP_CAT(scoped_timer_, line), description, level, filename, line, classname, objectname)
00144 #define LOGGING_SCOPED_TIMER_CO(streamname, description, level, classname, objectname) \
00145   LOGGING_SCOPED_TIMER_FLCO(streamname, description, level, __FILE__, __LINE__, classname, objectname)
00146 #define LOGGING_SCOPED_TIMER_C(streamname, description, level, classname) \
00147   LOGGING_SCOPED_TIMER_FLCO(streamname, description, level, __FILE__, __LINE__, classname, "")
00148 #define LOGGING_SCOPED_TIMER(streamname, description, level) \
00149   LOGGING_SCOPED_TIMER_FLCO(streamname, description, level, __FILE__, __LINE__, "", "")
00150 
00151 #define LOGGING_SCOPED_TIMER_ERROR(streamname, description)   LOGGING_SCOPED_TIMER(streamname, description, ::icl_core::logging::eLL_ERROR)
00152 #define LOGGING_SCOPED_TIMER_WARNING(streamname, description) LOGGING_SCOPED_TIMER(streamname, description, ::icl_core::logging::eLL_WARNING)
00153 #define LOGGING_SCOPED_TIMER_INFO(streamname, description)    LOGGING_SCOPED_TIMER(streamname, description, ::icl_core::logging::eLL_INFO)
00154 #ifdef _IC_DEBUG_
00155 # define LOGGING_SCOPED_TIMER_DEBUG(streamname, description)   LOGGING_SCOPED_TIMER(streamname, description, ::icl_core::logging::eLL_DEBUG)
00156 # define LOGGING_SCOPED_TIMER_TRACE(streamname, description)   LOGGING_SCOPED_TIMER(streamname, description, ::icl_core::logging::eLL_TRACE)
00157 #else
00158 # define LOGGING_SCOPED_TIMER_DEBUG(streamname, description) (void)0
00159 # define LOGGING_SCOPED_TIMER_TRACE(streamname, description) (void)0
00160 #endif
00161 
00162 #define LOGGING_SCOPED_TIMER_ERROR_C(streamname, description, classname)   LOGGING_SCOPED_TIMER_C(streamname, description, ::icl_core::logging::eLL_ERROR,   classname)
00163 #define LOGGING_SCOPED_TIMER_WARNING_C(streamname, description, classname) LOGGING_SCOPED_TIMER_C(streamname, description, ::icl_core::logging::eLL_WARNING, classname)
00164 #define LOGGING_SCOPED_TIMER_INFO_C(streamname, description, classname)    LOGGING_SCOPED_TIMER_C(streamname, description, ::icl_core::logging::eLL_INFO,    classname)
00165 #ifdef _IC_DEBUG_
00166 # define LOGGING_SCOPED_TIMER_DEBUG_C(streamname, description, classname)   LOGGING_SCOPED_TIMER_C(streamname, description, ::icl_core::logging::eLL_DEBUG,   classname)
00167 # define LOGGING_SCOPED_TIMER_TRACE_C(streamname, description, classname)   LOGGING_SCOPED_TIMER_C(streamname, description, ::icl_core::logging::eLL_TRACE,   classname)
00168 #else
00169 # define LOGGING_SCOPED_TIMER_DEBUG_C(streamname, description, classname) (void)0
00170 # define LOGGING_SCOPED_TIMER_TRACE_C(streamname, description, classname) (void)0
00171 #endif
00172 
00173 #define LOGGING_SCOPED_TIMER_ERROR_CO(streamname, description, classname, objectname)   LOGGING_SCOPED_TIMER_CO(streamname, description, ::icl_core::logging::eLL_ERROR,   classname, objectname)
00174 #define LOGGING_SCOPED_TIMER_WARNING_CO(streamname, description, classname, objectname) LOGGING_SCOPED_TIMER_CO(streamname, description, ::icl_core::logging::eLL_WARNING, classname, objectname)
00175 #define LOGGING_SCOPED_TIMER_INFO_CO(streamname, description, classname, objectname)    LOGGING_SCOPED_TIMER_CO(streamname, description, ::icl_core::logging::eLL_INFO,    classname, objectname)
00176 #ifdef _IC_DEBUG_
00177 # define LOGGING_SCOPED_TIMER_DEBUG_CO(streamname, description, classname, objectname)   LOGGING_SCOPED_TIMER_CO(streamname, description, ::icl_core::logging::eLL_DEBUG,   classname, objectname)
00178 # define LOGGING_SCOPED_TIMER_TRACE_CO(streamname, description, classname, objectname)   LOGGING_SCOPED_TIMER_CO(streamname, description, ::icl_core::logging::eLL_TRACE,   classname, objectname)
00179 #else
00180 # define LOGGING_SCOPED_TIMER_DEBUG_CO(streamname, description, classname, objectname) (void)0
00181 # define LOGGING_SCOPED_TIMER_TRACE_CO(streamname, description, classname, objectname) (void)0
00182 #endif
00183 
00184 #define LOGGING_SCOPED_TIMER_ERROR_V(streamname, varname, description)   LOGGING_SCOPED_TIMER_V(streamname, varname, description, ::icl_core::logging::eLL_ERROR)
00185 #define LOGGING_SCOPED_TIMER_WARNING_V(streamname, varname, description) LOGGING_SCOPED_TIMER_V(streamname, varname, description, ::icl_core::logging::eLL_WARNING)
00186 #define LOGGING_SCOPED_TIMER_INFO_V(streamname, varname, description)    LOGGING_SCOPED_TIMER_V(streamname, varname, description, ::icl_core::logging::eLL_INFO)
00187 #ifdef _IC_DEBUG_
00188 # define LOGGING_SCOPED_TIMER_DEBUG_V(streamname, varname, description)   LOGGING_SCOPED_TIMER_V(streamname, varname, description, ::icl_core::logging::eLL_DEBUG)
00189 # define LOGGING_SCOPED_TIMER_TRACE_V(streamname, varname, description)   LOGGING_SCOPED_TIMER_V(streamname, varname, description, ::icl_core::logging::eLL_TRACE)
00190 #else
00191 # define LOGGING_SCOPED_TIMER_DEBUG_V(streamname, varname, description) (void)0
00192 # define LOGGING_SCOPED_TIMER_TRACE_V(streamname, varname, description) (void)0
00193 #endif
00194 
00195 #define LOGGING_SCOPED_TIMER_ERROR_VC(streamname, varname, description, classname)   LOGGING_SCOPED_TIMER_VC(streamname, varname, description, ::icl_core::logging::eLL_ERROR,   classname)
00196 #define LOGGING_SCOPED_TIMER_WARNING_VC(streamname, varname, description, classname) LOGGING_SCOPED_TIMER_VC(streamname, varname, description, ::icl_core::logging::eLL_WARNING, classname)
00197 #define LOGGING_SCOPED_TIMER_INFO_VC(streamname, varname, description, classname)    LOGGING_SCOPED_TIMER_VC(streamname, varname, description, ::icl_core::logging::eLL_INFO,    classname)
00198 #ifdef _IC_DEBUG_
00199 # define LOGGING_SCOPED_TIMER_DEBUG_VC(streamname, varname, description, classname)   LOGGING_SCOPED_TIMER_VC(streamname, varname, description, ::icl_core::logging::eLL_DEBUG,   classname)
00200 # define LOGGING_SCOPED_TIMER_TRACE_VC(streamname, varname, description, classname)   LOGGING_SCOPED_TIMER_VC(streamname, varname, description, ::icl_core::logging::eLL_TRACE,   classname)
00201 #else
00202 # define LOGGING_SCOPED_TIMER_DEBUG_VC(streamname, varname, description, classname) (void)0
00203 # define LOGGING_SCOPED_TIMER_TRACE_VC(streamname, varname, description, classname) (void)0
00204 #endif
00205 
00206 #define LOGGING_SCOPED_TIMER_ERROR_VCO(streamname, varname, description, classname, objectname)   LOGGING_SCOPED_TIMER_VCO(streamname, varname, description, ::icl_core::logging::eLL_ERROR,   classname, objectname)
00207 #define LOGGING_SCOPED_TIMER_WARNING_VCO(streamname, varname, description, classname, objectname) LOGGING_SCOPED_TIMER_VCO(streamname, varname, description, ::icl_core::logging::eLL_WARNING, classname, objectname)
00208 #define LOGGING_SCOPED_TIMER_INFO_VCO(streamname, varname, description, classname, objectname)    LOGGING_SCOPED_TIMER_VCO(streamname, varname, description, ::icl_core::logging::eLL_INFO,    classname, objectname)
00209 #ifdef _IC_DEBUG_
00210 # define LOGGING_SCOPED_TIMER_DEBUG_VCO(streamname, varname, description, classname, objectname)   LOGGING_SCOPED_TIMER_VCO(streamname, varname, description, ::icl_core::logging::eLL_DEBUG,   classname, objectname)
00211 # define LOGGING_SCOPED_TIMER_TRACE_VCO(streamname, varname, description, classname, objectname)   LOGGING_SCOPED_TIMER_VCO(streamname, varname, description, ::icl_core::logging::eLL_TRACE,   classname, objectname)
00212 #else
00213 # define LOGGING_SCOPED_TIMER_DEBUG_VCO(streamname, varname, description, classname, objectname) (void)0
00214 # define LOGGING_SCOPED_TIMER_TRACE_VCO(streamname, varname, description, classname, objectname) (void)0
00215 #endif
00216 
00217 #endif


schunk_svh_driver
Author(s): Georg Heppner
autogenerated on Fri Aug 28 2015 12:59:19