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, ...) {
char tmp[256];
va_list args;
va_start(args, format);
if (phy_log_handler) {
char *args_msg = NULL;
if(vasprintf(&args_msg, format, args) > 0) {
phy_log_handler(log_level, callback_ctx, args_msg);
if(vsnprintf(tmp, 256, format, args) > 0) {
phy_log_handler(log_level, callback_ctx, tmp);
}
if (args_msg) {
free(args_msg);
}
}
}
va_end(args);
}

View File

@ -379,7 +379,9 @@ void phch_recv::run_thread()
{
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;

View File

@ -192,7 +192,9 @@ void phch_worker::set_tti(uint32_t tti_, uint32_t tx_tti_)
tti = tti_;
tx_tti = tx_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) {

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_workers = MAX_WORKERS;
}
this->log_phy_lib_h = (srslte::log*) log_vec[nof_workers];
srslte_phy_log_register_handler(this, srslte_phy_handler);
if (log_vec[nof_workers]) {
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;
start();
return true;

View File

@ -45,7 +45,9 @@ ue::ue()
ue::~ue()
{
for (uint32_t i = 0; i < phy_log.size(); i++) {
delete(phy_log[i]);
if (phy_log[i]) {
delete(phy_log[i]);
}
}
if (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*/
srslte::log_filter *lib_log = new srslte::log_filter;
char tmp[16];
sprintf(tmp, "PHY_LIB");
lib_log->init(tmp, logger, true);
phy_log.push_back(lib_log);
((srslte::log_filter*) phy_log[nof_phy_threads])->set_level(level(args->log.phy_lib_level));
if (level(args->log.phy_lib_level) != LOG_LEVEL_NONE) {
srslte::log_filter *lib_log = new srslte::log_filter;
char tmp[16];
sprintf(tmp, "PHY_LIB");
lib_log->init(tmp, logger, true);
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));
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));
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);
rlc_log.set_hex_limit(args->log.rlc_hex_limit);