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

master
Ismael Gomez 7 years ago
parent f01f7b4945
commit d81062145f

@ -46,15 +46,12 @@ 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);

@ -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());
if (log_phy_lib_h) {
log_phy_lib_h->step(tti); log_phy_lib_h->step(tti);
}
sf_idx = tti%10; sf_idx = tti%10;

@ -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);
if (log_phy_lib_h) {
log_phy_lib_h->step(tti); 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) {

@ -143,8 +143,12 @@ 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;
} }
if (log_vec[nof_workers]) {
this->log_phy_lib_h = (srslte::log*) log_vec[nof_workers]; this->log_phy_lib_h = (srslte::log*) log_vec[nof_workers];
srslte_phy_log_register_handler(this, srslte_phy_handler); srslte_phy_log_register_handler(this, srslte_phy_handler);
} else {
this->log_phy_lib_h = NULL;
}
initiated = false; initiated = false;
start(); start();

@ -45,8 +45,10 @@ 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++) {
if (phy_log[i]) {
delete(phy_log[i]); delete(phy_log[i]);
} }
}
if (usim) { if (usim) {
delete usim; delete usim;
} }
@ -95,12 +97,16 @@ 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*/
if (level(args->log.phy_lib_level) != LOG_LEVEL_NONE) {
srslte::log_filter *lib_log = new srslte::log_filter; srslte::log_filter *lib_log = new srslte::log_filter;
char tmp[16]; char tmp[16];
sprintf(tmp, "PHY_LIB"); sprintf(tmp, "PHY_LIB");
lib_log->init(tmp, logger, true); lib_log->init(tmp, logger, true);
phy_log.push_back(lib_log); phy_log.push_back(lib_log);
((srslte::log_filter*) phy_log[nof_phy_threads])->set_level(level(args->log.phy_lib_level)); ((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));
@ -112,8 +118,10 @@ 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++) {
if (phy_log[i]) {
((srslte::log_filter*) phy_log[i])->set_hex_limit(args->log.phy_hex_limit); ((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);
pdcp_log.set_hex_limit(args->log.pdcp_hex_limit); pdcp_log.set_hex_limit(args->log.pdcp_hex_limit);

Loading…
Cancel
Save