Commit 5d1854f6 authored by Alejandro Homs Puron's avatar Alejandro Homs Puron

Merge branch 'add_no_lima_debug' into 'master'

Add LIMA_NO_DEBUG

See merge request !70
parents dd69c7e7 e453af33
Pipeline #7357 failed with stages
in 9 minutes and 17 seconds
......@@ -258,6 +258,9 @@ if(LIMA_ENABLE_SPS_IMAGE)
target_include_directories(limacore PRIVATE "${CMAKE_SOURCE_DIR}/third-party/Sps/Include")
endif()
# Set LIMA_NO_DEBUG if the build type is not debug
target_compile_definitions(limacore PUBLIC $<$<NOT:$<CONFIG:DEBUG>>:LIMA_NO_DEBUG>)
# add all include paths coming from saving format options
target_include_directories(limacore PRIVATE ${extra_includes} ${saving_includes})
......
......@@ -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();
......@@ -236,15 +236,15 @@ std::ostream& operator <<(std::ostream& os,
class LIMACORE_API DebProxy
{
public:
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();
template <class T>
const DebProxy& operator <<(const T& o) const;
template <class T>
const DebProxy& operator <<(const T& o) const;
bool isActive() const;
......@@ -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,16 @@ 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)
{
#ifdef LIMA_NO_DEBUG
DebParams::checkInit();
#endif
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 +487,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();
}
......@@ -509,21 +501,22 @@ inline DebProxy DebObj::write(DebType type, ConstStr file_name, int line_nr)
#define DEB_GLOBAL_NAMESPC(mod, name_space) \
inline lima::DebParams& getDebParams() \
{ \
static lima::DebParams *deb_params = NULL; \
EXEC_ONCE(deb_params = new lima::DebParams(lima::mod, NULL, \
name_space)); \
static lima::DebParams *deb_params = NULL; \
EXEC_ONCE(deb_params = new lima::DebParams(lima::mod, NULL,\
name_space)); \
return *deb_params; \
}
#define DEB_GLOBAL(mod) \
DEB_GLOBAL_NAMESPC(mod, NULL)
#define DEB_STRUCT_NAMESPC(mod, struct_name, name_space) \
#define DEB_STRUCT_NAMESPC(mod, struct_name, name_space) \
static lima::DebParams& getDebParams() \
{ \
static lima::DebParams *deb_params = NULL; \
EXEC_ONCE(deb_params = new lima::DebParams(lima::mod, struct_name, \
name_space)); \
static lima::DebParams *deb_params = NULL; \
EXEC_ONCE(deb_params = new lima::DebParams(lima::mod, \
struct_name, \
name_space)); \
return *deb_params; \
} \
\
......@@ -532,7 +525,7 @@ inline DebProxy DebObj::write(DebType type, ConstStr file_name, int line_nr)
m_deb_obj_name = obj_name; \
} \
\
lima::ConstStr getDebObjName() const \
lima::ConstStr getDebObjName() const \
{ \
if (m_deb_obj_name.empty()) \
return NULL; \
......@@ -548,21 +541,21 @@ inline DebProxy DebObj::write(DebType type, ConstStr file_name, int line_nr)
#define DEB_CLASS(mod, class_name) \
DEB_CLASS_NAMESPC(mod, class_name, NULL)
#ifndef NO_LIMA_DEBUG
#ifndef LIMA_NO_DEBUG
#define DEB_GLOBAL_FUNCT() \
lima::DebObj deb(getDebParams(), false, __FUNCTION__, \
lima::DebObj deb(getDebParams(), false, __FUNCTION__, \
NULL, __FILE__, __LINE__)
#define DEB_CONSTRUCTOR() \
DEB_MEMBER_FUNCT()
#define DEB_DESTRUCTOR() \
lima::DebObj deb(getDebParams(), true, __FUNCTION__, \
lima::DebObj deb(getDebParams(), true, __FUNCTION__, \
getDebObjName(), __FILE__, __LINE__)
#define DEB_MEMBER_FUNCT() \
lima::DebObj deb(getDebParams(), false, __FUNCTION__, \
lima::DebObj deb(getDebParams(), false, __FUNCTION__, \
getDebObjName(), __FILE__, __LINE__)
#define DEB_PTR() \
......@@ -574,19 +567,75 @@ 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_OBJ_NAME(o) \
((o)->getDebObjName())
#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_CHECK_ANY(type) deb.checkAny(type)
#define DEB_EVENT(event) DEB_MSG((event).getDebType())
#else // LIMA_NO_DEBUG
// Mock implementation of the DebProxy
class LIMACORE_API DebSink
{
public:
DebSink() {};
template <class T>
const DebSink& operator <<(const T&) const {return *this;}
};
#define DEB_GLOBAL_FUNCT()
#define DEB_CONSTRUCTOR()
#define DEB_DESTRUCTOR()
#define DEB_MEMBER_FUNCT()
#define DEB_PTR() NULL
#define DEB_FROM_PTR(deb_ptr)
#define DEB_STATIC_FUNCT()
#define DEB_SET_OBJ_NAME(n)
#define DEB_MSG(type) \
DebProxy(NULL, type, __FUNCTION__, __FILE__, __LINE__)
#define DEB_NO_MSG() \
DebSink()
#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_NO_MSG()
#define DEB_PARAM() DEB_NO_MSG()
#define DEB_RETURN() DEB_NO_MSG()
#define DEB_ALWAYS() DEB_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))
#define DEB_EVENT(event) DEB_MSG((event).getDebType())
#endif // LIMA_NO_DEBUG
#define DEB_HEX(x) DebHex(x)
......@@ -605,44 +654,22 @@ 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)
#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)
/*------------------------------------------------------------------
* DebParams checkTypeFlags
*------------------------------------------------------------------*/
#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
#ifdef LIMA_NO_DEBUG
inline void lima::DebParams::checkTypeFlags(Flags& type_flags)
{
if (type_flags & DEB_IGNORED_TYPE_FLAGS) {
DEB_WARNING() << "Ignored type flags: Trace|Funct|Param|Return";
type_flags &= ~DEB_IGNORED_TYPE_FLAGS;
}
}
#else
inline void lima::DebParams::checkTypeFlags(Flags&)
{}
#endif
#endif // DEBUG_H
......@@ -24,6 +24,7 @@
#include "lima/LimaCompatibility.h"
#include "lima/Timestamp.h"
#include "lima/Debug.h"
#include <string>
#include <ostream>
......@@ -60,17 +61,11 @@ class LIMACORE_API Event
Event(Layer l, Severity s, Domain d, Code c,const std::string &e);
virtual ~Event();
virtual std::string getMsgStr();
virtual std::string getMsgStr() const;
DebProxy getDebug(DebObj& deb) const;
DebType getDebType() const;
};
#ifndef NO_LIMA_DEBUG
#define DEB_EVENT(event) (event).getDebug(deb)
#else
#define DEB_EVENT(event) deb
#endif
std::ostream& operator <<(std::ostream& os, const Event& event);
......
......@@ -125,7 +125,7 @@ LIMACORE_API std::ostream& operator <<(std::ostream& os, const Exception& e);
#define LIMA_HW_EXC(err_type, err_desc) \
LIMA_EXC(Hardware, err_type, err_desc)
#ifndef NO_LIMA_DEBUG
#ifndef LIMA_NO_DEBUG
#define LIMA_EXC_DEB(layer, err_type, deb_err_type) \
Exception(layer, err_type, "", __FILE__, __FUNCTION__, __LINE__,\
new DebProxy(DEB_MSG(deb_err_type)))
......
......@@ -25,6 +25,7 @@
#include <ctime>
#include <iomanip>
#include <cstring>
#include <unistd.h>
#ifdef __unix
#include <sys/time.h>
......@@ -138,6 +139,7 @@ void DebParams::checkInit()
void DebParams::setTypeFlags(Flags type_flags)
{
checkInit();
checkTypeFlags(type_flags);
s_type_flags = type_flags;
}
......@@ -150,6 +152,7 @@ DebParams::Flags DebParams::getTypeFlags()
void DebParams::enableTypeFlags(Flags type_flags)
{
checkInit();
checkTypeFlags(type_flags);
s_type_flags |= type_flags;
}
......@@ -245,7 +248,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 +410,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 +444,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 +453,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,22 +467,22 @@ 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 (deb && (m = funct_name)) {
bool need_tilde = deb->m_destructor && (m[0] != '~');
ConstStr destruct = need_tilde ? "~" : "";
os << csep << destruct << m;
csep = "::";
}
if (string(csep) == "::")
if (strcmp(csep, "::") == 0)
sep = " ";
}
......
......@@ -44,7 +44,7 @@ Event::~Event()
{
}
string Event::getMsgStr()
string Event::getMsgStr() const
{
ostringstream os;
......@@ -100,30 +100,23 @@ string Event::getMsgStr()
return os.str();
}
DebProxy Event::getDebug(DebObj& deb_obj) const
DebType Event::getDebType() const
{
#ifndef NO_LIMA_DEBUG
DEB_FROM_PTR(&deb_obj);
switch (severity) {
case Event::Fatal:
return DEB_FATAL();
return DebTypeFatal;
case Event::Error:
return DEB_ERROR();
return DebTypeError;
case Event::Warning:
return DEB_WARNING();
return DebTypeWarning;
default:
return DEB_TRACE();
return DebTypeTrace;
}
#else
return DebProxy();
#endif
}
ostream& lima::operator <<(ostream& os, const Event& event)
{
Event& noconst_event = const_cast<Event&>(event);
return os << "<" << noconst_event.getMsgStr() << ">";
return os << "<" << event.getMsgStr() << ">";
}
......
......@@ -410,8 +410,7 @@ class CMakeOptions:
class GitHelper:
not_submodules = (
'git', 'python', 'tests', 'test', 'cbf', 'lz4', 'fits', 'gz',
'tiff', 'hdf5'
'python', 'tests', 'cbf', 'lz4', 'fits', 'gz', 'tiff', 'hdf5',
)
submodule_map = {
......@@ -484,7 +483,7 @@ def build_install_lima(cfg):
cmake_cmd = cmake_opts.get_build_options()
exec_cmd(cmake_cmd, ('CMake could not build Lima. ' +
'Pleae contact lima@esrf.fr for help.'))
'Please contact lima@esrf.fr for help.'))
if not cfg.is_install_required():
return
......
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