diff options
author | Martin Braun <martin.braun@ettus.com> | 2017-04-20 16:10:06 -0700 |
---|---|---|
committer | Martin Braun <martin.braun@ettus.com> | 2017-04-24 14:19:10 -0700 |
commit | 0f30ef70f08b745755fdf362e05901039434a242 (patch) | |
tree | d66e3c3e8c6406451560249de510fd7199a4403d /host/lib | |
parent | c4da30c0ce4d37d0f2bd9dd2883e45ed0919cd2c (diff) | |
download | uhd-0f30ef70f08b745755fdf362e05901039434a242.tar.gz uhd-0f30ef70f08b745755fdf362e05901039434a242.tar.bz2 uhd-0f30ef70f08b745755fdf362e05901039434a242.zip |
log: Moved fastpath logging to its own thread
Diffstat (limited to 'host/lib')
-rw-r--r-- | host/lib/usrp/n230/n230_resource_manager.cpp | 2 | ||||
-rw-r--r-- | host/lib/utils/log.cpp | 49 |
2 files changed, 50 insertions, 1 deletions
diff --git a/host/lib/usrp/n230/n230_resource_manager.cpp b/host/lib/usrp/n230/n230_resource_manager.cpp index 4de5f77ec..61a80ae43 100644 --- a/host/lib/usrp/n230/n230_resource_manager.cpp +++ b/host/lib/usrp/n230/n230_resource_manager.cpp @@ -488,7 +488,7 @@ bool n230_resource_manager::_radio_data_loopback_self_test(wb_iface::sptr iface) const uint32_t rb_rx = uint32_t(rb_word64 & 0xffffffff); test_fail = word32 != rb_tx or word32 != rb_rx; if (test_fail){ - UHD_LOG_FASTPATH(boost::format("mismatch (exp:%x, got:%x and %x)... ") % word32 % rb_tx % rb_rx) + UHD_LOG_ERROR("N230", str(boost::format("mismatch (exp:%x, got:%x and %x)... ") % word32 % rb_tx % rb_rx)); break; //exit loop on any failure } } diff --git a/host/lib/utils/log.cpp b/host/lib/utils/log.cpp index c77e082ef..10baaf3f4 100644 --- a/host/lib/utils/log.cpp +++ b/host/lib/utils/log.cpp @@ -179,6 +179,9 @@ public: log_resource(void): global_level(uhd::log::off), _exit(false), +#ifndef UHD_LOG_FASTPATH_DISABLE + _fastpath_queue(10), +#endif _log_queue(10) { //allow override from macro definition @@ -231,6 +234,7 @@ public: // Launch log message consumer _pop_task = std::make_shared<std::thread>(std::thread([this](){this->pop_task();})); + _pop_fastpath_task = std::make_shared<std::thread>(std::thread([this](){this->pop_fastpath_task();})); } ~log_resource(void){ @@ -240,6 +244,11 @@ public: std::lock_guard<std::mutex> l(_logmap_mutex); _loggers.clear(); } + _pop_task.reset(); +#ifndef UHD_LOG_FASTPATH_DISABLE + _pop_fastpath_task->join(); + _pop_fastpath_task.reset(); +#endif } void push(const uhd::log::logging_info& log_info) @@ -247,6 +256,15 @@ public: _log_queue.push_with_haste(log_info); } + void push_fastpath(const std::string &message) + { + // Never wait. If the buffer is full, we just don't see the message. + // Too bad. +#ifndef UHD_LOG_FASTPATH_DISABLE + _fastpath_queue.push_with_haste(message); +#endif + } + void pop_task() { uhd::log::logging_info log_info; @@ -278,6 +296,25 @@ public: } } + void pop_fastpath_task() + { +#ifndef UHD_LOG_FASTPATH_DISABLE + while (!_exit) { + std::string msg; + if (_fastpath_queue.pop_with_timed_wait(msg, 1)){ + std::cerr << msg << std::flush; + } + } + + // Exit procedure: Clear the queue + std::string msg; + while (_fastpath_queue.pop_with_haste(msg)) { + std::cerr << msg << std::flush; + } +#endif + } + + void add_logger(const std::string &key, uhd::log::log_fn_t logger_fn) { std::lock_guard<std::mutex> l(_logmap_mutex); @@ -286,6 +323,9 @@ public: private: std::shared_ptr<std::thread> _pop_task; +#ifndef UHD_LOG_FASTPATH_DISABLE + std::shared_ptr<std::thread> _pop_fastpath_task; +#endif uhd::log::severity_level _get_log_level(const std::string &log_level_str, const uhd::log::severity_level &previous_level){ if (std::isdigit(log_level_str[0])) { @@ -316,6 +356,9 @@ private: std::atomic<bool> _exit; std::map<std::string, uhd::log::log_fn_t> _loggers; uhd::transport::bounded_buffer<uhd::log::logging_info> _log_queue; +#ifndef UHD_LOG_FASTPATH_DISABLE + uhd::transport::bounded_buffer<std::string> _fastpath_queue; +#endif }; UHD_SINGLETON_FCN(log_resource, log_rs); @@ -351,6 +394,12 @@ uhd::_log::log::~log(void) } } +void uhd::_log::log_fastpath(const std::string &msg) +{ +#ifndef UHD_LOG_FASTPATH_DISABLE + log_rs().push_fastpath(msg); +#endif +} /*********************************************************************** * Public API calls |