diff options
-rw-r--r-- | host/lib/usrp/mpmd/mpmd_impl.hpp | 5 | ||||
-rw-r--r-- | host/lib/usrp/mpmd/mpmd_mboard_impl.cpp | 66 | ||||
-rw-r--r-- | mpm/python/usrp_mpm/mpmlog.py | 2 |
3 files changed, 72 insertions, 1 deletions
diff --git a/host/lib/usrp/mpmd/mpmd_impl.hpp b/host/lib/usrp/mpmd/mpmd_impl.hpp index e71e83af6..f24f6d3fc 100644 --- a/host/lib/usrp/mpmd/mpmd_impl.hpp +++ b/host/lib/usrp/mpmd/mpmd_impl.hpp @@ -130,6 +130,11 @@ class mpmd_mboard_impl const uhd::device_addr_t mb_args ); + /*! Read out the log buffer from the MPM device and send it to native + * logging system. + */ + void dump_logs(const bool dump_to_null=false); + /************************************************************************* * Private attributes ************************************************************************/ diff --git a/host/lib/usrp/mpmd/mpmd_mboard_impl.cpp b/host/lib/usrp/mpmd/mpmd_mboard_impl.cpp index 59983414a..bd37e5ffb 100644 --- a/host/lib/usrp/mpmd/mpmd_mboard_impl.cpp +++ b/host/lib/usrp/mpmd/mpmd_mboard_impl.cpp @@ -27,6 +27,8 @@ namespace { //! Duration of a latency measurement test constexpr size_t MPMD_MEAS_LATENCY_DURATION = 1000; + using log_buf_t = std::vector<std::map<std::string, std::string>>; + /************************************************************************* * Helper functions @@ -91,6 +93,61 @@ namespace { << ", n = " << ctr); } + /*! Forward entries from a list of dictionaries to UHD's native logging + * system. + */ + void forward_logs(log_buf_t&& log_buf) + { + for (const auto &log_record : log_buf) { + if (log_record.count("levelname") == 0 or \ + log_record.count("message") == 0) { + UHD_LOG_ERROR("MPMD", + "Invalid logging structure returned from MPM device!"); + continue; + } + if (log_record.at("levelname") == "TRACE") { + UHD_LOG_TRACE( + log_record.at("name"), + log_record.at("message") + ); + } + else if (log_record.at("levelname") == "DEBUG") { + UHD_LOG_DEBUG( + log_record.at("name"), + log_record.at("message") + ); + } + else if (log_record.at("levelname") == "INFO") { + UHD_LOG_INFO( + log_record.at("name"), + log_record.at("message") + ); + } + else if (log_record.at("levelname") == "WARNING") { + UHD_LOG_WARNING( + log_record.at("name"), + log_record.at("message") + ); + } + else if (log_record.at("levelname") == "ERROR") { + UHD_LOG_ERROR( + log_record.at("name"), + log_record.at("message") + ); + } + else if (log_record.at("levelname") == "CRITICAL") { + UHD_LOG_FATAL( + log_record.at("name"), + log_record.at("message") + ); + } else { + UHD_LOG_ERROR("MPMD", + "Invalid log level returned from MPM device: " + "`" << log_record.at("levelname") << "'"); + } + } + } + } using namespace uhd; @@ -304,6 +361,15 @@ uhd::task::sptr mpmd_mboard_impl::claim_device_and_make_task( }); } +void mpmd_mboard_impl::dump_logs(const bool dump_to_null) +{ + if (dump_to_null) { + rpc->request_with_token<log_buf_t>("get_log_buf"); + } else { + forward_logs(rpc->request_with_token<log_buf_t>("get_log_buf")); + } +} + /***************************************************************************** * Factory diff --git a/mpm/python/usrp_mpm/mpmlog.py b/mpm/python/usrp_mpm/mpmlog.py index cca202c9a..b1cc9beac 100644 --- a/mpm/python/usrp_mpm/mpmlog.py +++ b/mpm/python/usrp_mpm/mpmlog.py @@ -28,7 +28,7 @@ RESET = str('\x1b[0m') TRACE = 1 DEFAULT_LOG_LEVEL = DEBUG -DEFAULT_LOG_BUF_SIZE = 100 +DEFAULT_LOG_BUF_SIZE = 100 # In number of log records class ColorStreamHandler(logging.StreamHandler): """ |