Fixed phy_log was allocating memory dynamically on every call even when not enabled

This commit is contained in:
Ismael Gomez 2018-06-28 10:29:18 +02:00
parent f01f7b4945
commit d81062145f
5 changed files with 34 additions and 21 deletions

View File

@ -46,16 +46,13 @@ void srslte_phy_log_register_handler(void *ctx, phy_log_handler_t handler) {
} }
void srslte_phy_log_print(phy_logger_level_t log_level, const char *format, ...) { void srslte_phy_log_print(phy_logger_level_t log_level, const char *format, ...) {
char tmp[256];
va_list args; va_list args;
va_start(args, format); va_start(args, format);
if (phy_log_handler) { if (phy_log_handler) {
char *args_msg = NULL; if(vsnprintf(tmp, 256, format, args) > 0) {
if(vasprintf(&args_msg, format, args) > 0) { phy_log_handler(log_level, callback_ctx, tmp);
phy_log_handler(log_level, callback_ctx, args_msg);
} }
if (args_msg) { }
free(args_msg);
}
}
va_end(args); va_end(args);
} }

View File

@ -379,7 +379,9 @@ void phch_recv::run_thread()
{ {
Debug("SYNC: state=%s\n", phy_state.to_string()); Debug("SYNC: state=%s\n", phy_state.to_string());
log_phy_lib_h->step(tti); if (log_phy_lib_h) {
log_phy_lib_h->step(tti);
}
sf_idx = tti%10; sf_idx = tti%10;

View File

@ -192,7 +192,9 @@ void phch_worker::set_tti(uint32_t tti_, uint32_t tx_tti_)
tti = tti_; tti = tti_;
tx_tti = tx_tti_; tx_tti = tx_tti_;
log_h->step(tti); log_h->step(tti);
log_phy_lib_h->step(tti); if (log_phy_lib_h) {
log_phy_lib_h->step(tti);
}
} }
void phch_worker::set_prach(cf_t *prach_ptr, float prach_power) { void phch_worker::set_prach(cf_t *prach_ptr, float prach_power) {

View File

@ -143,9 +143,13 @@ bool phy::init(srslte::radio_multi* radio_handler, mac_interface_phy *mac, rrc_i
nof_coworkers = SRSLTE_MIN(nof_workers - MAX_WORKERS, MAX_WORKERS); nof_coworkers = SRSLTE_MIN(nof_workers - MAX_WORKERS, MAX_WORKERS);
nof_workers = MAX_WORKERS; nof_workers = MAX_WORKERS;
} }
this->log_phy_lib_h = (srslte::log*) log_vec[nof_workers]; if (log_vec[nof_workers]) {
srslte_phy_log_register_handler(this, srslte_phy_handler); this->log_phy_lib_h = (srslte::log*) log_vec[nof_workers];
srslte_phy_log_register_handler(this, srslte_phy_handler);
} else {
this->log_phy_lib_h = NULL;
}
initiated = false; initiated = false;
start(); start();
return true; return true;

View File

@ -45,7 +45,9 @@ ue::ue()
ue::~ue() ue::~ue()
{ {
for (uint32_t i = 0; i < phy_log.size(); i++) { for (uint32_t i = 0; i < phy_log.size(); i++) {
delete(phy_log[i]); if (phy_log[i]) {
delete(phy_log[i]);
}
} }
if (usim) { if (usim) {
delete usim; delete usim;
@ -95,13 +97,17 @@ bool ue::init(all_args_t *args_) {
} }
/* here we add a log layer to handle logging from the phy library*/ /* here we add a log layer to handle logging from the phy library*/
srslte::log_filter *lib_log = new srslte::log_filter; if (level(args->log.phy_lib_level) != LOG_LEVEL_NONE) {
char tmp[16]; srslte::log_filter *lib_log = new srslte::log_filter;
sprintf(tmp, "PHY_LIB"); char tmp[16];
lib_log->init(tmp, logger, true); sprintf(tmp, "PHY_LIB");
phy_log.push_back(lib_log); lib_log->init(tmp, logger, true);
((srslte::log_filter*) phy_log[nof_phy_threads])->set_level(level(args->log.phy_lib_level)); phy_log.push_back(lib_log);
((srslte::log_filter*) phy_log[nof_phy_threads])->set_level(level(args->log.phy_lib_level));
} else {
phy_log.push_back(NULL);
}
mac_log.set_level(level(args->log.mac_level)); mac_log.set_level(level(args->log.mac_level));
rlc_log.set_level(level(args->log.rlc_level)); rlc_log.set_level(level(args->log.rlc_level));
@ -112,7 +118,9 @@ bool ue::init(all_args_t *args_) {
usim_log.set_level(level(args->log.usim_level)); usim_log.set_level(level(args->log.usim_level));
for (int i=0;i<nof_phy_threads + 1;i++) { for (int i=0;i<nof_phy_threads + 1;i++) {
((srslte::log_filter*) phy_log[i])->set_hex_limit(args->log.phy_hex_limit); if (phy_log[i]) {
((srslte::log_filter*) phy_log[i])->set_hex_limit(args->log.phy_hex_limit);
}
} }
mac_log.set_hex_limit(args->log.mac_hex_limit); mac_log.set_hex_limit(args->log.mac_hex_limit);
rlc_log.set_hex_limit(args->log.rlc_hex_limit); rlc_log.set_hex_limit(args->log.rlc_hex_limit);