JeVois  1.0
JeVois Smart Embedded Machine Vision Toolkit
Debugging helper classes, functions and macros

Classes

class  jevois::Log< Level >
 Logger class. More...
 
class  jevois::trace::TraceObject
 Helper class for tracing, issues one message on construction, and another on destruction. More...
 
class  jevois::timed_lock_guard
 Acquire a lock object on a std::timed_mutex, or LFATAL after 1 second of waiting. More...
 
class  jevois::Profiler
 Simple profiler class. More...
 
class  jevois::Timer
 Simple timer class. More...
 

Macros

#define LDEBUG(msg)
 Convenience macro for users to print out console or syslog messages, DEBUG level. More...
 
#define PLDEBUG(msg)
 Like LDEBUG but appends errno and strerror(errno), to be used when some system call fails. More...
 
#define LINFO(msg)
 Convenience macro for users to print out console or syslog messages, INFO level. More...
 
#define PLINFO(msg)
 Like LINFO but appends errno and strerror(errno), to be used when some system call fails. More...
 
#define LERROR(msg)
 Convenience macro for users to print out console or syslog messages, ERROR level. More...
 
#define PLERROR(msg)
 Like LERROR but appends errno and strerror(errno), to be used when some system call fails. More...
 
#define LFATAL(msg)
 Convenience macro for users to print out console or syslog messages, FATAL level. More...
 
#define PLFATAL(msg)
 Like LDEBUG but appends errno and strerror(errno), to be used when some system call fails. More...
 
#define JEVOIS_ASSERT(cond)
 Test whether something is true and issue an LFATAL if not. More...
 
#define JEVOIS_TRACE(level)
 Trace object. More...
 
#define JEVOIS_TIMED_LOCK(mtx)
 Helper macro to create a timed_lock_guard object. More...
 

Functions

void jevois::warnAndRethrowException ()
 Convenience function to catch an exception, issue some LERROR (depending on type), and rethrow it. More...
 
std::string jevois::warnAndIgnoreException ()
 Convenience function to catch an exception, issue some LERROR (depending on type), and ignore it. More...
 
void jevois::logSetEngine (Engine *e)
 Set an Engine so that all log messages will be forwarded to its serial ports. More...
 
std::string jevois::getSysInfoCPU ()
 Get CPU info: frequency, thermal, load. More...
 
std::string jevois::getSysInfoMem ()
 Get memory info. More...
 
std::string jevois::getSysInfoVersion ()
 Get O.S. version info. More...
 

Variables

int jevois::logLevel = LOG_INFO
 Current log level. More...
 
int jevois::traceLevel = 0
 Current trace level. More...
 

Macro Definition Documentation

#define JEVOIS_ASSERT (   cond)

Test whether something is true and issue an LFATAL if not.

Definition at line 221 of file Log.H.

#define JEVOIS_TIMED_LOCK (   mtx)

Helper macro to create a timed_lock_guard object.

Creates a timed_lock_guard over std::timed_mutex mtx, which will throw if mtx cannot be locked before timeout. The guard will unlock the mutex upon destruction.

Definition at line 292 of file Log.H.

Referenced by jevois::Camera::Camera(), jevois::Engine::mainLoop(), jevois::Engine::postInit(), jevois::Gadget::setFormat(), jevois::Camera::setFormat(), jevois::Engine::setFormat(), jevois::Gadget::streamOff(), jevois::Engine::streamOff(), jevois::Camera::streamOn(), jevois::Gadget::streamOn(), jevois::Engine::streamOn(), and jevois::Engine::~Engine().

#define JEVOIS_TRACE (   level)

Trace object.

Use this as you do with, e.g., std::lock_guard. Issues one LDEBUG() message on construction, and one on destruction. Typically, you would hence invoke JEVOIS_TRACE as the first command in each of the functions you want to trace.

Definition at line 260 of file Log.H.

Referenced by jevois::Camera::abortStream(), jevois::Gadget::abortStream(), jevois::Component::absolutePath(), jevois::Component::addSubComponent(), jevois::Camera::Camera(), jevois::Component::Component(), jevois::Component::descriptor(), jevois::Camera::done(), jevois::Engine::Engine(), jevois::Gadget::Gadget(), jevois::Gadget::get(), jevois::Camera::get(), jevois::Component::getParamString(), jevois::Component::getParamStringUnique(), jevois::Component::getParamVal(), jevois::Component::getParamValUnique(), jevois::Component::getSubComponent(), jevois::Component::initialized(), jevois::Component::isTopLevel(), jevois::Engine::mainLoop(), jevois::Component::removeSubComponent(), jevois::Gadget::send(), jevois::Gadget::setFormat(), jevois::Camera::setFormat(), jevois::Engine::setFormat(), jevois::Component::setParamString(), jevois::Component::setParamStringUnique(), jevois::Component::setParamVal(), jevois::Component::setParamValUnique(), jevois::Component::setPath(), jevois::Camera::streamOff(), jevois::Gadget::streamOff(), jevois::Engine::streamOff(), jevois::Camera::streamOn(), jevois::Gadget::streamOn(), jevois::Engine::streamOn(), jevois::Camera::~Camera(), jevois::Component::~Component(), jevois::Engine::~Engine(), and jevois::Gadget::~Gadget().

#define LDEBUG (   msg)

Convenience macro for users to print out console or syslog messages, DEBUG level.

This macro is intended to be used with a stream-oriented syntax for everything that is passed as argument to the macro. The syntax is a bit strange at first but you will rapidly get used to it. This allows any datatype that has an operator<< defined to be printed out in a log (contrary to printf-style syntax). For example:

1 int x = 3; std::string str = "hello"; jevois::StepRange<int> rng(0, 5, 100);
2 LDEBUG("x=" << x << " and str=" << str << " and rng=" << rng);
Note
This is the preferred way to issue messages. Do you use printf, do not use cout<<"blah", etc.

By design, your log message will not be evaluated if the current log level is below (stronger than) the debug level. This means that you should not be afraid of wasting CPU computing messages that will not be output; for example:

1 LDEBUG("CPU-intensive function says: " << cpu_intensive_function());

will not run the cpu-intensive function if the current log level is LOG_ERR (it will still run one "if" statement to check the current log level). This also means that you should never assume that your log message will be evaluated. For example:

1 int x = 42;
2 LDEBUG("x = " << (x++) ); // x may now be 43 or 42 depending on current log level...
Note
Because LDEBUG() may be used for debugging of many fast loops, including through the use of JEVOIS_TRACE(level), it will be compiled in only if JEVOIS_LDEBUG_ENABLE is defined during build (typicaly, this is done as an option passed to cmake), otherwise it will simply be commented out so that no CPU is wasted.

Definition at line 148 of file Log.H.

Referenced by jevois::Manager::addComponent(), jevois::ParameterRegistry::addParameter(), jevois::Component::addSubComponent(), jevois::Camera::Camera(), jevois::Camera::done(), jevois::Serial::flush(), jevois::VideoDisplay::get(), jevois::Gadget::get(), jevois::Camera::get(), jevois::Engine::mainLoop(), jevois::Engine::parseCommand(), jevois::Camera::readRegister(), jevois::ParameterRegistry::removeParameter(), jevois::VideoDisplay::send(), jevois::Gadget::send(), jevois::VideoDisplay::setFormat(), jevois::Camera::setFormat(), jevois::Engine::setFormat(), jevois::Timer::stop(), jevois::Profiler::stop(), jevois::Camera::streamOff(), jevois::Gadget::streamOff(), jevois::Engine::streamOff(), jevois::Camera::streamOn(), jevois::Gadget::streamOn(), jevois::Camera::writeRegister(), and jevois::Component::~Component().

#define LFATAL (   msg)

Convenience macro for users to print out console or syslog messages, FATAL level.

Usage syntax is the same as for LDEBUG(msg)

Note
After printing the message, this also throws std::runtime_error

Definition at line 205 of file Log.H.

Referenced by jevois::ParameterRegistry::addParameter(), jevois::rawimage::byteSwap(), jevois::Camera::Camera(), jevois::rawimage::convertCvBGRtoRawImage(), jevois::rawimage::convertCvRGBAtoRawImage(), jevois::rawimage::convertToCvBGR(), jevois::rawimage::convertToCvGray(), jevois::rawimage::convertToCvRGB(), jevois::rawimage::convertToCvRGBA(), jevois::rawimage::cvImage(), jevois::Camera::done(), jevois::DynamicLoader::DynamicLoader(), jevois::Engine::findVideoMapping(), jevois::Gadget::Gadget(), jevois::MovieOutput::get(), jevois::MovieInput::get(), jevois::Gadget::get(), jevois::Manager::getComponent(), jevois::Component::getSubComponent(), jevois::Engine::getVideoMapping(), jevois::Engine::getVideoMappingIdx(), jevois::rawimage::hFlipYUYV(), jevois::DynamicLoader::load(), main(), jevois::MovieInput::MovieInput(), jevois::rawimage::paste(), jevois::rawimage::pasteGreyToYUYV(), jevois::Serial::postInit(), jevois::Profiler::Profiler(), jevois::MovieInput::readRegister(), jevois::RawImage::require(), jevois::rawimage::roipaste(), jevois::MovieOutput::run(), jevois::Engine::runScriptFromFile(), jevois::VideoDisplay::send(), jevois::MovieOutput::send(), jevois::Gadget::send(), jevois::Module::sendSerial(), jevois::Serial::setBlocking(), jevois::Camera::setFormat(), jevois::Engine::setFormat(), jevois::Component::setParamsFromFile(), jevois::Component::setParamsFromStream(), jevois::Timer::stop(), jevois::Profiler::stop(), jevois::Timer::Timer(), jevois::Serial::toggleDTR(), jevois::rawimage::unpackCvRGBAtoGrayRawImage(), jevois::v4l2BytesPerPix(), jevois::MovieInput::writeRegister(), and jevois::rawimage::writeText().

#define PLDEBUG (   msg)

Like LDEBUG but appends errno and strerror(errno), to be used when some system call fails.

Usage syntax is the same as for LDEBUG(msg)

Definition at line 156 of file Log.H.

#define PLERROR (   msg)

Like LERROR but appends errno and strerror(errno), to be used when some system call fails.

Usage syntax is the same as for LDEBUG(msg)

Definition at line 194 of file Log.H.

Referenced by jevois::Camera::~Camera(), jevois::Gadget::~Gadget(), and jevois::VideoBuf::~VideoBuf().

#define PLFATAL (   msg)

Like LDEBUG but appends errno and strerror(errno), to be used when some system call fails.

Usage syntax is the same as for LDEBUG(msg)

Note
After printing the message, this also throws std::runtime_error

Definition at line 214 of file Log.H.

Referenced by jevois::Camera::Camera(), jevois::Gadget::Gadget(), and jevois::VideoBuf::VideoBuf().

#define PLINFO (   msg)

Like LINFO but appends errno and strerror(errno), to be used when some system call fails.

Usage syntax is the same as for LDEBUG(msg)

Definition at line 177 of file Log.H.

Function Documentation

std::string jevois::getSysInfoCPU ( )

Get CPU info: frequency, thermal, load.

Definition at line 38 of file SysInfo.C.

References jevois::to_string().

Referenced by jevois::Engine::parseCommand().

std::string jevois::getSysInfoMem ( )

Get memory info.

Definition at line 64 of file SysInfo.C.

Referenced by jevois::Engine::parseCommand().

std::string jevois::getSysInfoVersion ( )

Get O.S. version info.

Definition at line 72 of file SysInfo.C.

Referenced by jevois::Engine::parseCommand().

void jevois::logSetEngine ( Engine e)

Set an Engine so that all log messages will be forwarded to its serial ports.

This function is not intended for general use, Engine uses it internally when users set one of its parameters to enable forwarding of log messages to serial ports.

Definition at line 112 of file Log.C.

Referenced by jevois::Engine::postInit(), and jevois::Engine::~Engine().

std::string jevois::warnAndIgnoreException ( )

Convenience function to catch an exception, issue some LERROR (depending on type), and ignore it.

User code can use this function as follows, to log some trace of the exception that was thrown, and then swallow (ignore) the exception. Use this sparingly, swallowing exceptions often defeats the whole logic of using exceptions in the first place. Example use:

try { do_something_risky_and_we_dont_care_if_it_fails(); } catch (...) { jevois::warnAndIgnoreException(); }

Note that the message that is logged to console is also returned as a string (without the "Ignoring uncaught..." part), in case one wants to report it in some other way (e.g., in a GUI).

Definition at line 200 of file Log.C.

References LERROR.

Referenced by jevois::Engine::mainLoop(), TutorialEdgeDetectionX4::process(), jevois::Engine::runScriptFromFile(), jevois::Engine::sendSerial(), jevois::Camera::~Camera(), jevois::Gadget::~Gadget(), and jevois::MovieOutput::~MovieOutput().

void jevois::warnAndRethrowException ( )

Convenience function to catch an exception, issue some LERROR (depending on type), and rethrow it.

User code that is not going to swallow exceptions can use this function as follows, to log some trace of the exception that was thrown:

try { do_something_risky(); } catch (...) { jevois::warnAndRethrowException(); }
Note
This function throws! So obviously it only makes sense to use it inside a catch block.

Definition at line 181 of file Log.C.

References LERROR.

Variable Documentation

int jevois::logLevel = LOG_INFO

Current log level.

The log level is set by changing the value of this global variable. The default value is LOG_INFO.

The possible log values are defined in sys/syslog.h and here we only handle the following with different amounts of messages: LOG_CRIT, LOG_ERR, LOG_INFO, LOG_DEBUG.

Definition at line 26 of file Log.C.

Referenced by main().

int jevois::traceLevel = 0

Current trace level.

Higher levels yield more verbosity in tracing. Note that this has effect only if JEVOIS_TRACE_ENABLE is specified as a compile option, and the trace messages are issued at the LDEBUG log level, so JEVOIS_LDEBUG_ENABLE must also be specified at compile time.

Definition at line 27 of file Log.C.

Referenced by jevois::trace::TraceObject::TraceObject(), and jevois::trace::TraceObject::~TraceObject().