Commit 4187d911 authored by Alejandro Homs Puron's avatar Alejandro Homs Puron Committed by operator for beamline

Debug: refactor NO_LIMA_DEBUG code, activate it when build_type is not Debug

* NO_LIMA_DEBUG: include Fatal, Error, Warning and Always messages and
  ignore Trace, Funct, Param and Return ones
parent c119579d
......@@ -60,6 +60,11 @@ endif()
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
include(LimaTools)
# Logging, disable trace in Release builds
if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(-DNO_LIMA_DEBUG)
endif()
# Import pthread
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_package(Threads REQUIRED)
......
......@@ -51,7 +51,6 @@ enum DebType {
DebTypeAlways = 1 << 7,
};
enum DebFormat {
DebFmtDateTime = 1 << 0,
DebFmtThread = 1 << 1,
......@@ -158,6 +157,7 @@ class LIMACORE_API DebParams
bool checkModule() const;
bool checkType(DebType type) const;
static void checkTypeFlags(Flags& type_flags);
static void setTypeFlags(Flags type_flags);
static Flags getTypeFlags();
......@@ -238,8 +238,8 @@ class LIMACORE_API DebProxy
{
public:
DebProxy();
DebProxy(DebObj *deb_obj, DebType type, ConstStr file_name,
int line_nr);
DebProxy(DebObj *deb_obj, DebType type, ConstStr funct_name,
ConstStr file_name, int line_nr);
DebProxy(const DebProxy& p);
~DebProxy();
......@@ -252,20 +252,6 @@ class LIMACORE_API DebProxy
mutable AutoMutex *m_lock;
};
/*------------------------------------------------------------------
* class DebSink
*------------------------------------------------------------------*/
class LIMACORE_API DebSink
{
public:
DebSink() {};
template <class T>
const DebSink& operator <<(const T&) const {return *this;}
};
/*------------------------------------------------------------------
* class DebObj
*------------------------------------------------------------------*/
......@@ -299,7 +285,10 @@ class LIMACORE_API DebObj
ThreadData() : indent(-1) {}
} ThreadData;
void heading(DebType type, ConstStr file_name, int line_nr);
static void heading(DebType type, ConstStr funct_name,
ConstStr file_name, int line_nr,
DebObj *deb = NULL);
static ThreadData *getThreadData();
static void deleteThreadData(void *thread_data);
......@@ -398,7 +387,6 @@ inline bool DebParams::checkType(DebType type) const
return DebHasFlag(s_type_flags, type);
}
/*------------------------------------------------------------------
* class DebProxy inline functions
*------------------------------------------------------------------*/
......@@ -408,12 +396,12 @@ inline DebProxy::DebProxy()
{
}
inline DebProxy::DebProxy(DebObj *deb_obj, DebType type, ConstStr file_name,
int line_nr)
inline DebProxy::DebProxy(DebObj *deb_obj, DebType type, ConstStr funct_name,
ConstStr file_name, int line_nr)
{
AutoMutex lock(*DebParams::s_mutex);
deb_obj->heading(type, file_name, line_nr);
DebObj::heading(type, funct_name, file_name, line_nr, deb_obj);
m_lock = new AutoMutex(lock);
}
......@@ -495,7 +483,7 @@ inline DebParams& DebObj::getDebParams()
inline DebProxy DebObj::write(DebType type, ConstStr file_name, int line_nr)
{
if (checkAny(type))
return DebProxy(this, type, file_name, line_nr);
return DebProxy(this, type, m_funct_name, file_name, line_nr);
else
return DebProxy();
}
......@@ -506,6 +494,8 @@ inline DebProxy DebObj::write(DebType type, ConstStr file_name, int line_nr)
* debug macros
*------------------------------------------------------------------*/
#define DEB_NOP() do {} while (0)
#define DEB_GLOBAL_NAMESPC(mod, name_space) \
inline lima::DebParams& getDebParams() \
{ \
......@@ -575,19 +565,61 @@ inline DebProxy DebObj::write(DebType type, ConstStr file_name, int line_nr)
#define DEB_STATIC_FUNCT() \
DEB_GLOBAL_FUNCT()
#define DEB_SET_OBJ_NAME(n) \
#define DEB_SET_OBJ_NAME(n) \
setDebObjName(n)
#define DEB_MSG(type) deb.write(type, __FILE__, __LINE__)
#define DEB_MSG(type) deb.write(type, __FILE__, __LINE__)
#define DEB_FATAL() DEB_MSG(lima::DebTypeFatal)
#define DEB_ERROR() DEB_MSG(lima::DebTypeError)
#define DEB_WARNING() DEB_MSG(lima::DebTypeWarning)
#define DEB_TRACE() DEB_MSG(lima::DebTypeTrace)
#define DEB_PARAM() DEB_MSG(lima::DebTypeParam)
#define DEB_RETURN() DEB_MSG(lima::DebTypeReturn)
#define DEB_ALWAYS() DEB_MSG(lima::DebTypeAlways)
#define DEB_FATAL() DEB_MSG(lima::DebTypeFatal)
#define DEB_ERROR() DEB_MSG(lima::DebTypeError)
#define DEB_WARNING() DEB_MSG(lima::DebTypeWarning)
#define DEB_TRACE() DEB_MSG(lima::DebTypeTrace)
#define DEB_PARAM() DEB_MSG(lima::DebTypeParam)
#define DEB_RETURN() DEB_MSG(lima::DebTypeReturn)
#define DEB_ALWAYS() DEB_MSG(lima::DebTypeAlways)
#define DEB_OBJ_NAME(o) \
((o)->getDebObjName())
#define DEB_CHECK_ANY(type) deb.checkAny(type)
#else // NO_LIMA_DEBUG
#define DEB_GLOBAL_FUNCT() DEB_NOP()
#define DEB_CONSTRUCTOR() DEB_NOP()
#define DEB_DESTRUCTOR() DEB_NOP()
#define DEB_MEMBER_FUNCT() DEB_NOP()
#define DEB_PTR() NULL
#define DEB_FROM_PTR(deb_ptr) DEB_NOP()
#define DEB_STATIC_FUNCT() DEB_NOP()
#define DEB_SET_OBJ_NAME(n) DEB_NOP()
#define DEB_OUT_MSG(type) \
DebProxy(NULL, type, __FUNCTION__, __FILE__, __LINE__)
#define DEB_NO_MSG() \
DebProxy()
#define DEB_FATAL() DEB_OUT_MSG(lima::DebTypeFatal)
#define DEB_ERROR() DEB_OUT_MSG(lima::DebTypeError)
#define DEB_WARNING() DEB_OUT_MSG(lima::DebTypeWarning)
#define DEB_TRACE() DEB_NO_MSG()
#define DEB_PARAM() DEB_NO_MSG()
#define DEB_RETURN() DEB_NO_MSG()
#define DEB_ALWAYS() DEB_OUT_MSG(lima::DebTypeAlways)
#define DEB_OBJ_NAME(o) NULL
#define DEB_IGNORED_TYPE_FLAGS \
(lima::DebTypeTrace | lima::DebTypeFunct | lima::DebTypeParam | \
lima::DebTypeReturn)
#define DEB_CHECK_ANY(type) \
(((type) == lima::DebTypeFatal) || ((type) == lima::DebTypeError) || \
((type) == lima::DebTypeWarning) || ((type) == lima::DebTypeAlways))
#endif // NO_LIMA_DEBUG
#define DEB_HEX(x) DebHex(x)
......@@ -606,44 +638,19 @@ inline DebProxy DebObj::write(DebType type, ConstStr file_name, int line_nr)
#define DEB_VAR7(v1, v2, v3, v4, v5, v6, v7) \
DEB_VAR6(v1, v2, v3, v4, v5, v6) << ", " << #v7 << "=" << v7
#define DEB_OBJ_NAME(o) \
((o)->getDebObjName())
#define DEB_CHECK_ANY(type) deb.checkAny(type)
/*------------------------------------------------------------------
* DebParams checkTypeFlags
*------------------------------------------------------------------*/
#else //NO_LIMA_DEBUG
#define DEB_GLOBAL_FUNCT() lima::DebSink deb
#define DEB_CONSTRUCTOR() lima::DebSink deb
#define DEB_DESTRUCTOR() lima::DebSink deb
#define DEB_MEMBER_FUNCT() lima::DebSink deb
#define DEB_PTR() NULL
#define DEB_FROM_PTR(deb_ptr) lima::DebSink deb
#define DEB_STATIC_FUNCT() DEB_GLOBAL_FUNCT()
#define DEB_SET_OBJ_NAME(n)
#define DEB_MSG(type) deb
#define DEB_FATAL() deb
#define DEB_ERROR() deb
#define DEB_WARNING() deb
#define DEB_TRACE() deb
#define DEB_PARAM() deb
#define DEB_RETURN() deb
#define DEB_ALWAYS() deb
#define DEB_HEX(x) ""
#define DEB_VAR1(v1) ""
#define DEB_VAR2(v1, v2) ""
#define DEB_VAR3(v1, v2, v3) ""
#define DEB_VAR4(v1, v2, v3, v4) ""
#define DEB_VAR5(v1, v2, v3, v4, v5) ""
#define DEB_VAR6(v1, v2, v3, v4, v5, v6) ""
#define DEB_VAR7(v1, v2, v3, v4, v5, v6, v7) ""
#define DEB_OBJ_NAME(o)
#define DEB_CHECK_ANY(type) 0
#endif //NO_LIMA_DEBUG
inline void lima::DebParams::checkTypeFlags(Flags& type_flags)
{
#ifdef NO_LIMA_DEBUG
if (type_flags & DEB_IGNORED_TYPE_FLAGS) {
DEB_WARNING() << "Ignored type flags: Trace|Funct|Param|Return";
type_flags &= ~DEB_IGNORED_TYPE_FLAGS;
}
#endif
}
#endif // DEBUG_H
......@@ -62,14 +62,10 @@ class LIMACORE_API Event
virtual std::string getMsgStr();
DebProxy getDebug(DebObj& deb) const;
DebProxy getDebug(DebObj *deb) const;
};
#ifndef NO_LIMA_DEBUG
#define DEB_EVENT(event) (event).getDebug(deb)
#else
#define DEB_EVENT(event) deb
#endif
#define DEB_EVENT(event) (event).getDebug(DEB_PTR())
std::ostream& operator <<(std::ostream& os, const Event& event);
......
......@@ -138,6 +138,7 @@ void DebParams::checkInit()
void DebParams::setTypeFlags(Flags type_flags)
{
checkInit();
checkTypeFlags(type_flags);
s_type_flags = type_flags;
}
......@@ -150,6 +151,7 @@ DebParams::Flags DebParams::getTypeFlags()
void DebParams::enableTypeFlags(Flags type_flags)
{
checkInit();
checkTypeFlags(type_flags);
s_type_flags |= type_flags;
}
......@@ -245,7 +247,10 @@ void DebParams::getFlagsNameList(Flags flags,
void DebParams::setTypeFlagsNameList(const NameList& type_name_list)
{
checkInit();
setFlagsNameList(s_type_flags, *s_type_name_map, type_name_list);
Flags type_flags = 0;
setFlagsNameList(type_flags, *s_type_name_map, type_name_list);
checkTypeFlags(type_flags);
s_type_flags |= type_flags;
}
DebParams::NameList DebParams::getTypeFlagsNameList()
......@@ -404,7 +409,8 @@ ostream& lima::operator <<(ostream& os,
* DebObj functions
*------------------------------------------------------------------*/
void DebObj::heading(DebType type, ConstStr file_name, int line_nr)
void DebObj::heading(DebType type, ConstStr funct_name, ConstStr file_name,
int line_nr, DebObj *deb)
{
ostream& os = *DebParams::s_deb_stream;
DebParams::Flags& flags = DebParams::s_fmt_flags;
......@@ -437,7 +443,7 @@ void DebObj::heading(DebType type, ConstStr file_name, int line_nr)
sep = " ";
}
if (DebHasFlag(flags, DebFmtIndent)) {
if (DebHasFlag(flags, DebFmtIndent) && deb) {
ThreadData *thread_data = getThreadData();
if (thread_data->indent < 0)
thread_data->indent = 0;
......@@ -446,13 +452,13 @@ void DebObj::heading(DebType type, ConstStr file_name, int line_nr)
sep = " ";
}
if (DebHasFlag(flags, DebFmtModule)) {
os << "*" << DebParams::getModuleName(m_deb_params->m_mod)
if (DebHasFlag(flags, DebFmtModule) && deb) {
os << "*" << DebParams::getModuleName(deb->m_deb_params->m_mod)
<< "*";
sep = "";
}
if (DebHasFlag(flags, DebFmtObj) && ((m = m_obj_name))) {
if (DebHasFlag(flags, DebFmtObj) && deb && ((m = deb->m_obj_name))) {
os << sep << m;
sep = " ";
}
......@@ -460,17 +466,18 @@ void DebObj::heading(DebType type, ConstStr file_name, int line_nr)
if (DebHasFlag(flags, DebFmtFunct)) {
ConstStr csep = sep;
#ifndef WIN32
if ((m = m_deb_params->m_name_space)) {
if (deb && (m = deb->m_deb_params->m_name_space)) {
os << csep << m;
csep = "::";
}
if ((m = m_deb_params->m_class_name)) {
if (deb && (m = deb->m_deb_params->m_class_name)) {
os << csep << m;
csep = "::";
}
#endif
if ((m = m_funct_name)) {
bool need_tilde = m_destructor && (m[0] != '~');
if ((m = funct_name)) {
bool is_destructor = deb && deb->m_destructor;
bool need_tilde = is_destructor && (m[0] != '~');
ConstStr destruct = need_tilde ? "~" : "";
os << csep << destruct << m;
csep = "::";
......
......@@ -100,10 +100,9 @@ string Event::getMsgStr()
return os.str();
}
DebProxy Event::getDebug(DebObj& deb_obj) const
DebProxy Event::getDebug(DebObj *deb_obj) const
{
#ifndef NO_LIMA_DEBUG
DEB_FROM_PTR(&deb_obj);
DEB_FROM_PTR(deb_obj);
switch (severity) {
case Event::Fatal:
......@@ -115,9 +114,6 @@ DebProxy Event::getDebug(DebObj& deb_obj) const
default:
return DEB_TRACE();
}
#else
return DebProxy();
#endif
}
ostream& lima::operator <<(ostream& os, const Event& event)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment