From 21aad77c9ca07f4271136b9241f5adb00a6bb908 Mon Sep 17 00:00:00 2001 From: Andrej Rode Date: Tue, 7 Feb 2017 16:37:25 -0800 Subject: utils: introduce new logging API and remove msg API --- host/utils/latency/include/Responder.hpp | 5 +-- host/utils/latency/lib/Responder.cpp | 62 +++++++++++--------------------- 2 files changed, 22 insertions(+), 45 deletions(-) (limited to 'host/utils/latency') diff --git a/host/utils/latency/include/Responder.hpp b/host/utils/latency/include/Responder.hpp index a9f616a24..7ee910500 100644 --- a/host/utils/latency/include/Responder.hpp +++ b/host/utils/latency/include/Responder.hpp @@ -24,7 +24,6 @@ #include #include -#include using namespace std; @@ -141,9 +140,6 @@ class Responder // Main entry point after constructor. int run(); - // Public method to inject UHD messages in the main ncurses window. - void print_uhd_late_handler(uhd::msg::type_t type, const std::string& msg); - int get_return_code(){return _return_code;} protected: @@ -151,6 +147,7 @@ class Responder // These 2 variables are used for ncurses output. WINDOW* _window; std::stringstream _ss; + std::stringstream _ss_cerr; // struct which holds all arguments as constants settable from outside the class const Options _opt; diff --git a/host/utils/latency/lib/Responder.cpp b/host/utils/latency/lib/Responder.cpp index e5be9e275..ba278f338 100644 --- a/host/utils/latency/lib/Responder.cpp +++ b/host/utils/latency/lib/Responder.cpp @@ -23,51 +23,33 @@ #include #include #include +#include #include #include +#include #include #include #include const std::string _eth_file("eths_info.txt"); -// UHD screen handler during initialization. Error messages will be printed to log file -static std::string uhd_error_msgs; -static void screen_handler(uhd::msg::type_t type, const std::string& msg) -{ - printw( msg.c_str() ); - //printw("\n"); - refresh(); - if(type == uhd::msg::error){ - uhd_error_msgs.append(msg); - uhd_error_msgs.append("\n"); - } -} -// UHD screen handler during test run. Error messages will be printed to log file -static int s_late_count = 0; -static Responder* s_responder; // needed here to have a way to inject uhd msg into Responder. -// function is only called by UHD, if s_responder points to a valid instance. -// this instance sets the function to be the output callback for UHD. -static void _late_handler(uhd::msg::type_t type, const std::string& msg) -{ - s_responder->print_uhd_late_handler(type, msg); -} +// Redirect output to stderr +struct cerr_redirect { + cerr_redirect( std::streambuf * new_buffer ) + : old( std::cerr.rdbuf( new_buffer ) ) + { } -void Responder::print_uhd_late_handler(uhd::msg::type_t type, const std::string& msg) -{ - if (msg == "L") // This is just a test - { - ++s_late_count; - } - if(type == uhd::msg::error){ - uhd_error_msgs.append(msg); - uhd_error_msgs.append("\n"); - // Only print error messages. There will be very many 'L's due to the way the test works. - print_msg(msg); + ~cerr_redirect( ) { + std::cerr.rdbuf( old ); } -} + +private: + std::streambuf * old; +}; + + // Catch keyboard interrupts for clean manual abort static bool s_stop_signal_called = false; @@ -132,7 +114,9 @@ Responder::Responder( Options& opt) _last_overrun_count(0) { time( &_dbginfo.start_time ); // for debugging - s_responder = this; + + // Disable logging to console + uhd::log::set_console_level(uhd::log::off); if (uhd::set_thread_priority_safe(_opt.rt_priority, _opt.realtime) == false) // try to set realtime scheduling { @@ -141,7 +125,6 @@ Responder::Responder( Options& opt) _return_code = calculate_dependent_values(); - uhd::msg::register_handler(&screen_handler); // used to print USRP initialization status // From this point on, everything is written to a ncurses window! create_ncurses_window(); @@ -180,7 +163,9 @@ Responder::Responder( Options& opt) } // set up handlers for test run - uhd::msg::register_handler(&_late_handler); // capture UHD output. + // uhd::msg::register_handler(&_late_handler); // capture UHD output. + + cerr_redirect(_ss_cerr.rdbuf()); register_stop_signal_handler(); } @@ -1211,11 +1196,6 @@ Responder::write_log_file() write_debug_info(logs); - if(uhd_error_msgs.length() > 0) - { - logs << endl << "%% UHD ERROR MESSAGES %%" << endl; - logs << uhd_error_msgs; - } } } catch(...) -- cgit v1.2.3