From d37a07a47fe74e424aeab476bab2614f4d0cbf65 Mon Sep 17 00:00:00 2001 From: faluco Date: Mon, 1 Feb 2021 12:43:41 +0100 Subject: [PATCH] Replaced loggers in buffer_pool.h --- lib/include/srslte/common/buffer_pool.h | 33 ++++++++++++++----------- srsenb/hdr/enb.h | 2 -- srsenb/src/enb.cc | 5 +--- srsue/hdr/stack/ue_stack_lte.h | 13 +++++----- srsue/hdr/stack/ue_stack_nr.h | 7 +++--- srsue/src/stack/ue_stack_lte.cc | 3 +-- srsue/src/stack/ue_stack_nr.cc | 5 ++-- 7 files changed, 32 insertions(+), 36 deletions(-) diff --git a/lib/include/srslte/common/buffer_pool.h b/lib/include/srslte/common/buffer_pool.h index d01c90b1e..721109880 100644 --- a/lib/include/srslte/common/buffer_pool.h +++ b/lib/include/srslte/common/buffer_pool.h @@ -26,6 +26,7 @@ #include "srslte/common/common.h" #include "srslte/common/log.h" +#include "srslte/srslog/srslog.h" namespace srslte { @@ -164,8 +165,8 @@ class byte_buffer_pool public: // Singleton static methods static std::unique_ptr instance; - static byte_buffer_pool* get_instance(int capacity = -1); - static void cleanup(); + static byte_buffer_pool* get_instance(int capacity = -1); + static void cleanup(); byte_buffer_pool(int capacity = -1) { log = nullptr; @@ -178,7 +179,7 @@ public: { return pool->allocate(debug_name, blocking); } - void set_log(srslte::log* log) { this->log = log; } + void enable_logger(bool enabled) { print_to_log = enabled; } void deallocate(byte_buffer_t* b) { if (!b) { @@ -186,26 +187,30 @@ public: } b->clear(); if (!pool->deallocate(b)) { - if (log) { #ifdef SRSLTE_BUFFER_POOL_LOG_ENABLED - log->error("Deallocating PDU: Addr=0x%p, name=%s not found in pool\n", b, b->debug_name); + print_error("Error deallocating PDU: Addr=0x%p, name=%s not found in pool", (void*)b, b->debug_name); #else - log->error("Deallocating PDU: Addr=0x%p\n", b); + print_error("Error deallocating PDU: Addr=0x%p", (void*)b); #endif - } else { -#ifdef SRSLTE_BUFFER_POOL_LOG_ENABLED - printf("Error deallocating PDU: Addr=0x%p, name=%s not found in pool\n", b, b->debug_name); -#else - printf("Error deallocating PDU: Addr=0x%p\n", b); -#endif - } } b = nullptr; } void print_all_buffers() { pool->print_all_buffers(); } private: - srslte::log* log; + /// Formats and prints the input string and arguments into the configured output stream. + template + void print_error(const char* str, Args&&... args) + { + if (print_to_log) { + srslog::fetch_basic_logger("POOL", false).error(str, std::forward(args)...); + } else { + fmt::printf(std::string(str) + "\n", std::forward(args)...); + } + } + +private: + bool print_to_log = false; buffer_pool* pool; }; diff --git a/srsenb/hdr/enb.h b/srsenb/hdr/enb.h index d738d69cf..292af36d2 100644 --- a/srsenb/hdr/enb.h +++ b/srsenb/hdr/enb.h @@ -139,8 +139,6 @@ private: srslog::sink& log_sink; srslog::basic_logger& enb_log; - srslte::log_filter pool_log; - srslte::byte_buffer_pool* pool = nullptr; all_args_t args = {}; diff --git a/srsenb/src/enb.cc b/srsenb/src/enb.cc index d440b2584..349f4ee0f 100644 --- a/srsenb/src/enb.cc +++ b/srsenb/src/enb.cc @@ -30,7 +30,6 @@ enb::enb(srslog::sink& log_sink) : enb_log(srslog::fetch_basic_logger("ENB", log_sink, false)), pool(srslte::byte_buffer_pool::get_instance(ENB_POOL_SIZE)) { - // print build info std::cout << std::endl << get_build_string() << std::endl << std::endl; } @@ -56,9 +55,7 @@ int enb::init(const all_args_t& args_, srslte::logger* logger_) return SRSLTE_ERROR; } - pool_log.init("POOL", logger); - pool_log.set_level(srslte::LOG_LEVEL_ERROR); - pool->set_log(&pool_log); + pool->enable_logger(true); // Create layers if (args.stack.type == "lte") { diff --git a/srsue/hdr/stack/ue_stack_lte.h b/srsue/hdr/stack/ue_stack_lte.h index 0fe197f7b..64a6f2f63 100644 --- a/srsue/hdr/stack/ue_stack_lte.h +++ b/srsue/hdr/stack/ue_stack_lte.h @@ -161,7 +161,6 @@ private: srslte::log_ref rrc_log{"RRC"}; srslte::log_ref usim_log{"USIM"}; srslte::log_ref nas_log{"NAS"}; - srslte::log_ref pool_log{"POOL"}; srslog::basic_logger& stack_logger; srslog::basic_logger& mac_logger; srslog::basic_logger& rlc_logger; @@ -184,12 +183,12 @@ private: srslte::tprof tti_tprof; // stack components - srsue::mac mac; - srslte::mac_pcap mac_pcap; - srslte::nas_pcap nas_pcap; - srslte::rlc rlc; - srslte::pdcp pdcp; - srsue::rrc rrc; + srsue::mac mac; + srslte::mac_pcap mac_pcap; + srslte::nas_pcap nas_pcap; + srslte::rlc rlc; + srslte::pdcp pdcp; + srsue::rrc rrc; #ifdef HAVE_5GNR srsue::mac_nr mac_nr; srsue::rrc_nr rrc_nr; diff --git a/srsue/hdr/stack/ue_stack_nr.h b/srsue/hdr/stack/ue_stack_nr.h index 68d09626d..ba75623f4 100644 --- a/srsue/hdr/stack/ue_stack_nr.h +++ b/srsue/hdr/stack/ue_stack_nr.h @@ -62,9 +62,9 @@ public: void stop(); // GW srsue stack_interface_gw dummy interface - bool is_registered(){return true;}; - bool start_service_request(){return true;}; - + bool is_registered() { return true; }; + bool start_service_request() { return true; }; + bool get_metrics(stack_metrics_t* metrics); bool is_rrc_connected(); @@ -105,7 +105,6 @@ private: srslte::logger* logger = nullptr; srslte::log_ref rlc_log; srslte::log_ref pdcp_log; - srslte::log_ref pool_log; // stack components std::unique_ptr mac; diff --git a/srsue/src/stack/ue_stack_lte.cc b/srsue/src/stack/ue_stack_lte.cc index 48ad0576e..f7a2b262b 100644 --- a/srsue/src/stack/ue_stack_lte.cc +++ b/srsue/src/stack/ue_stack_lte.cc @@ -87,8 +87,7 @@ int ue_stack_lte::init(const stack_args_t& args_, srslte::logger* logger_) // init own log stack_logger.set_level(srslog::str_to_basic_level(args.log.stack_level)); stack_logger.set_hex_dump_max_size(args.log.stack_hex_limit); - pool_log->set_level(srslte::LOG_LEVEL_WARNING); - byte_buffer_pool::get_instance()->set_log(pool_log.get()); + byte_buffer_pool::get_instance()->enable_logger(true); // init layer logs srslte::logmap::register_log(std::unique_ptr{new srslte::log_filter{"MAC", logger, true}}); diff --git a/srsue/src/stack/ue_stack_nr.cc b/srsue/src/stack/ue_stack_nr.cc index e946e83d5..8ab61b03f 100644 --- a/srsue/src/stack/ue_stack_nr.cc +++ b/srsue/src/stack/ue_stack_nr.cc @@ -18,7 +18,7 @@ using namespace srslte; namespace srsue { ue_stack_nr::ue_stack_nr(srslte::logger* logger_) : - logger(logger_), thread("STACK"), task_sched(64, 2, 64), rlc_log("RLC"), pdcp_log("PDCP"), pool_log("POOL") + logger(logger_), thread("STACK"), task_sched(64, 2, 64), rlc_log("RLC"), pdcp_log("PDCP") { mac.reset(new mac_nr(&task_sched)); pdcp.reset(new srslte::pdcp(&task_sched, "PDCP")); @@ -26,8 +26,7 @@ ue_stack_nr::ue_stack_nr(srslte::logger* logger_) : rrc.reset(new rrc_nr(&task_sched)); // setup logging for pool, RLC and PDCP - pool_log->set_level(srslte::LOG_LEVEL_ERROR); - byte_buffer_pool::get_instance()->set_log(pool_log.get()); + byte_buffer_pool::get_instance()->enable_logger(true); ue_task_queue = task_sched.make_task_queue(); sync_task_queue = task_sched.make_task_queue();