From 10fc1855d6517c4371469acfc39d645d23b37417 Mon Sep 17 00:00:00 2001 From: Xavier Arteaga Date: Wed, 31 Jan 2018 12:43:22 +0100 Subject: [PATCH 1/2] Fixed Coverity INFO/DEBUG messages with too many arguments and a few more --- lib/examples/cell_measurement.c | 2 +- lib/examples/cell_search.c | 2 +- lib/examples/pdsch_enodeb.c | 2 +- lib/examples/pdsch_ue.c | 4 ++-- lib/src/phy/io/filesource.c | 4 +++- lib/src/phy/mimo/precoding.c | 18 ++++++++++++++---- lib/src/phy/mimo/test/pmi_select_test.c | 2 +- lib/src/phy/mimo/test/precoder_test.c | 4 ++-- lib/src/phy/phch/cqi.c | 2 +- lib/src/phy/phch/dci.c | 4 ++-- lib/src/phy/phch/pdcch.c | 4 ++-- lib/src/phy/phch/pdsch.c | 6 ++++-- lib/src/phy/phch/phich.c | 16 ++++++++-------- lib/src/phy/phch/sch.c | 2 +- lib/src/phy/phch/test/pbch_file_test.c | 2 +- lib/src/phy/phch/test/pcfich_file_test.c | 4 ++-- lib/src/phy/phch/test/pdcch_file_test.c | 4 ++-- lib/src/phy/phch/test/pdsch_pdcch_file_test.c | 2 +- lib/src/phy/phch/test/phich_file_test.c | 4 ++-- lib/src/phy/phch/uci.c | 8 ++++---- lib/src/phy/rf/rf_utils.c | 4 ++-- lib/src/phy/ue/ue_sync.c | 2 +- 22 files changed, 58 insertions(+), 44 deletions(-) diff --git a/lib/examples/cell_measurement.c b/lib/examples/cell_measurement.c index 71c0864c8..3185b74f1 100644 --- a/lib/examples/cell_measurement.c +++ b/lib/examples/cell_measurement.c @@ -239,7 +239,7 @@ int main(int argc, char **argv) { exit(-1); } - INFO("Stopping RF and flushing buffer...\n",0); + INFO("Stopping RF and flushing buffer...\n"); srslte_rf_stop_rx_stream(&rf); srslte_rf_flush_buffer(&rf); diff --git a/lib/examples/cell_search.c b/lib/examples/cell_search.c index 17e75369f..4ea89a0ca 100644 --- a/lib/examples/cell_search.c +++ b/lib/examples/cell_search.c @@ -220,7 +220,7 @@ int main(int argc, char **argv) { INFO("Setting sampling frequency %.2f MHz for PSS search\n", SRSLTE_CS_SAMP_FREQ/1000000); srslte_rf_set_rx_srate(&rf, SRSLTE_CS_SAMP_FREQ); - INFO("Starting receiver...\n", 0); + INFO("Starting receiver...\n"); srslte_rf_start_rx_stream(&rf, false); n = srslte_ue_cellsearch_scan(&cs, found_cells, NULL); diff --git a/lib/examples/pdsch_enodeb.c b/lib/examples/pdsch_enodeb.c index 2f0f4836f..c95fd50a9 100644 --- a/lib/examples/pdsch_enodeb.c +++ b/lib/examples/pdsch_enodeb.c @@ -858,7 +858,7 @@ int main(int argc, char **argv) { if (net_port > 0) { send_data = net_packet_ready; if (net_packet_ready) { - INFO("Transmitting packet\n",0); + INFO("Transmitting packet\n"); } } else { INFO("SF: %d, Generating %d random bits\n", sf_idx, pdsch_cfg.grant.mcs[0].tbs + pdsch_cfg.grant.mcs[1].tbs); diff --git a/lib/examples/pdsch_ue.c b/lib/examples/pdsch_ue.c index 2ad33ea02..8ef620b56 100644 --- a/lib/examples/pdsch_ue.c +++ b/lib/examples/pdsch_ue.c @@ -473,7 +473,7 @@ int main(int argc, char **argv) { exit(-1); } - INFO("Stopping RF and flushing buffer...\r",0); + INFO("Stopping RF and flushing buffer...\r"); } #endif @@ -606,7 +606,7 @@ int main(int argc, char **argv) { srslte_pbch_decode_reset(&ue_mib.pbch); - INFO("\nEntering main loop...\n\n", 0); + INFO("\nEntering main loop...\n\n"); /* Main loop */ while (!go_exit && (sf_cnt < prog_args.nof_subframes || prog_args.nof_subframes == -1)) { bool acks [SRSLTE_MAX_CODEWORDS] = {false}; diff --git a/lib/src/phy/io/filesource.c b/lib/src/phy/io/filesource.c index 048ecb584..1324bf2b0 100644 --- a/lib/src/phy/io/filesource.c +++ b/lib/src/phy/io/filesource.c @@ -50,7 +50,9 @@ void srslte_filesource_free(srslte_filesource_t *q) { } void srslte_filesource_seek(srslte_filesource_t *q, int pos) { - fseek(q->f, pos, SEEK_SET); + if (!fseek(q->f, pos, SEEK_SET)){ + perror("srslte_filesource_seek"); + } } int read_complex_f(FILE *f, _Complex float *y) { diff --git a/lib/src/phy/mimo/precoding.c b/lib/src/phy/mimo/precoding.c index a78c13056..6d50e3ed2 100644 --- a/lib/src/phy/mimo/precoding.c +++ b/lib/src/phy/mimo/precoding.c @@ -2205,7 +2205,9 @@ int srslte_precoding_pmi_select_2l_gen(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORT } /* Divide average by noise */ - sinr_list[i] /= count; + if (count) { + sinr_list[i] /= count; + } if (sinr_list[i] > max_sinr) { max_sinr = sinr_list[i]; @@ -2326,7 +2328,9 @@ int srslte_precoding_pmi_select_2l_sse(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORT } /* Divide average by noise */ - sinr_list[i] /= count; + if (count) { + sinr_list[i] /= count; + } if (sinr_list[i] > max_sinr) { max_sinr = sinr_list[i]; @@ -2473,7 +2477,9 @@ int srslte_precoding_pmi_select_2l_avx(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORT } /* Divide average by noise */ - sinr_list[i] /= count; + if (count) { + sinr_list[i] /= count; + } if (sinr_list[i] > max_sinr) { max_sinr = sinr_list[i]; @@ -2545,7 +2551,11 @@ float srslte_precoding_2x2_cn_gen(cf_t *h[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], u count++; } - return cn_avg/count; + if (count) { + cn_avg /= count; + } + + return cn_avg; } /* Computes the condition number for a given number of antennas, diff --git a/lib/src/phy/mimo/test/pmi_select_test.c b/lib/src/phy/mimo/test/pmi_select_test.c index c7e5b5c8e..a40723d34 100644 --- a/lib/src/phy/mimo/test/pmi_select_test.c +++ b/lib/src/phy/mimo/test/pmi_select_test.c @@ -124,7 +124,7 @@ int main(int argc, char **argv) { /* Condition number */ if (srslte_precoding_cn(h, 2, 2, nof_symbols, &cn)) { - ERROR("Test case %d condition number returned error\n"); + ERROR("Test case %d condition number returned error\n", c + 1); goto clean; } diff --git a/lib/src/phy/mimo/test/precoder_test.c b/lib/src/phy/mimo/test/precoder_test.c index ec022319f..1054545c3 100644 --- a/lib/src/phy/mimo/test/precoder_test.c +++ b/lib/src/phy/mimo/test/precoder_test.c @@ -42,7 +42,7 @@ int nof_symbols = 1000; uint32_t codebook_idx = 0; int nof_layers = 1, nof_tx_ports = 1, nof_rx_ports = 1, nof_re = 1; char *mimo_type_name = NULL; -char decoder_type_name [16] = "zf"; +char decoder_type_name [17] = "zf"; float snr_db = 100.0f; float scaling = 0.1f; @@ -56,7 +56,7 @@ void usage(char *prog) { printf("\t-g Scaling [Default %.1f]*\n", scaling); printf("\t-d decoder type [zf|mmse] [Default %s]\n", decoder_type_name); printf("\n"); - printf("* Performance test example:\n\t for snr in {0..20..1}; do ./precoding_test -m single -s $snr; done; \n\n", decoder_type_name); + printf("* Performance test example:\n\t for snr in {0..20..1}; do ./precoding_test -m single -s $snr; done; \n\n"); } void parse_args(int argc, char **argv) { diff --git a/lib/src/phy/phch/cqi.c b/lib/src/phy/phch/cqi.c index 3d8c3e27d..522cdf10b 100644 --- a/lib/src/phy/phch/cqi.c +++ b/lib/src/phy/phch/cqi.c @@ -383,7 +383,7 @@ bool srslte_ri_send(uint32_t I_cqi_pmi, uint32_t I_ri, uint32_t tti) { return false; } - if (M_ri) { + if (M_ri && N_p) { if ((tti - N_offset_p + N_offset_ri) % (N_p * M_ri) == 0) { return true; } diff --git a/lib/src/phy/phch/dci.c b/lib/src/phy/phch/dci.c index e4d6dd159..6766ca5f0 100644 --- a/lib/src/phy/phch/dci.c +++ b/lib/src/phy/phch/dci.c @@ -577,7 +577,7 @@ int dci_format0_unpack(srslte_dci_msg_t *msg, srslte_ra_ul_dci_t *data, uint32_t return SRSLTE_ERROR; } if (*y++ != 0) { - INFO("DCI message is Format1A\n", 0); + INFO("DCI message is Format1A\n"); return SRSLTE_ERROR; } if (*y++ == 0) { @@ -836,7 +836,7 @@ int dci_format1As_unpack(srslte_dci_msg_t *msg, srslte_ra_dl_dci_t *data, uint32 } if (*y++ != 1) { - INFO("DCI message is Format0\n", 0); + INFO("DCI message is Format0\n"); return SRSLTE_ERROR; } diff --git a/lib/src/phy/phch/pdcch.c b/lib/src/phy/phch/pdcch.c index ca8480bc6..969b53cf7 100644 --- a/lib/src/phy/phch/pdcch.c +++ b/lib/src/phy/phch/pdcch.c @@ -557,7 +557,7 @@ int srslte_pdcch_dci_encode(srslte_pdcch_t *q, uint8_t *data, uint8_t *e, uint32 srslte_pdcch_dci_encode_conv(q, data, nof_bits, tmp, rnti); - DEBUG("CConv output: ", 0); + DEBUG("CConv output: "); if (SRSLTE_VERBOSE_ISDEBUG()) { srslte_vec_fprint_b(stdout, tmp, 3 * (nof_bits + 16)); } @@ -617,7 +617,7 @@ int srslte_pdcch_encode(srslte_pdcch_t *q, srslte_dci_msg_t *msg, srslte_dci_loc srslte_scrambling_b_offset(&q->seq[nsubframe], q->e, 72 * location.ncce, e_bits); - DEBUG("Scrambling output: ", 0); + DEBUG("Scrambling output: "); if (SRSLTE_VERBOSE_ISDEBUG()) { srslte_vec_fprint_b(stdout, q->e, e_bits); } diff --git a/lib/src/phy/phch/pdsch.c b/lib/src/phy/phch/pdsch.c index fbf0860be..1cf4af4e2 100644 --- a/lib/src/phy/phch/pdsch.c +++ b/lib/src/phy/phch/pdsch.c @@ -29,6 +29,8 @@ #include #include #include +#include +#include #include "prb_dl.h" #include "srslte/phy/phch/pdsch.h" @@ -656,8 +658,8 @@ int srslte_pdsch_decode(srslte_pdsch_t *q, { uint32_t nof_tb = SRSLTE_RA_DL_GRANT_NOF_TB(&cfg->grant); - INFO("Decoding PDSCH SF: %d, RNTI: 0x%x, NofSymbols: %d, C_prb=%d, mimo_type=%d, nof_layers=%d, nof_tb=%d\n", - cfg->sf_idx, rnti, cfg->nbits[0].nof_re, cfg->grant.nof_prb, cfg->nof_layers, nof_tb); + INFO("Decoding PDSCH SF: %d, RNTI: 0x%x, NofSymbols: %d, C_prb=%d, mimo_type=%s, nof_layers=%d, nof_tb=%d\n", + cfg->sf_idx, rnti, cfg->nbits[0].nof_re, cfg->grant.nof_prb, srslte_mod_string(cfg->grant.mcs->mod), cfg->nof_layers, nof_tb); // Extract Symbols and Channel Estimates for (int j=0;jnof_rx_antennas;j++) { diff --git a/lib/src/phy/phch/phich.c b/lib/src/phy/phch/phich.c index 37b8e1b7a..6990d69e2 100644 --- a/lib/src/phy/phch/phich.c +++ b/lib/src/phy/phch/phich.c @@ -148,7 +148,7 @@ uint8_t srslte_phich_ack_decode(float bits[SRSLTE_PHICH_NBITS], float *distance) uint8_t index=0; if (SRSLTE_VERBOSE_ISINFO()) { - INFO("Received bits: ", 0); + INFO("Received bits: "); srslte_vec_fprint_f(stdout, bits, SRSLTE_PHICH_NBITS); } @@ -244,8 +244,8 @@ int srslte_phich_decode(srslte_phich_t *q, cf_t *sf_symbols[SRSLTE_MAX_PORTS], srslte_predecoding_diversity_multi(q_sf_symbols, q_ce, x, q->nof_rx_antennas, q->cell.nof_ports, SRSLTE_PHICH_MAX_NSYMB, 1.0f); srslte_layerdemap_diversity(x, q->d0, q->cell.nof_ports, SRSLTE_PHICH_MAX_NSYMB / q->cell.nof_ports); } - DEBUG("Recv!!: \n", 0); - DEBUG("d0: ", 0); + DEBUG("Recv!!: \n"); + DEBUG("d0: "); if (SRSLTE_VERBOSE_ISDEBUG()) srslte_vec_fprint_c(stdout, q->d0, SRSLTE_PHICH_MAX_NSYMB); @@ -265,7 +265,7 @@ int srslte_phich_decode(srslte_phich_t *q, cf_t *sf_symbols[SRSLTE_MAX_PORTS], memcpy(q->d, q->d0, SRSLTE_PHICH_MAX_NSYMB * sizeof(cf_t)); } - DEBUG("d: ", 0); + DEBUG("d: "); if (SRSLTE_VERBOSE_ISDEBUG()) srslte_vec_fprint_c(stdout, q->d, SRSLTE_PHICH_EXT_MSYMB); @@ -290,7 +290,7 @@ int srslte_phich_decode(srslte_phich_t *q, cf_t *sf_symbols[SRSLTE_MAX_PORTS], } } - DEBUG("z: ", 0); + DEBUG("z: "); if (SRSLTE_VERBOSE_ISDEBUG()) srslte_vec_fprint_c(stdout, q->z, SRSLTE_PHICH_NBITS); @@ -353,7 +353,7 @@ int srslte_phich_encode(srslte_phich_t *q, uint8_t ack, uint32_t ngroup, uint32_ srslte_mod_modulate(&q->mod, q->data, q->z, SRSLTE_PHICH_NBITS); - DEBUG("data: ", 0); + DEBUG("data: "); if (SRSLTE_VERBOSE_ISDEBUG()) srslte_vec_fprint_c(stdout, q->z, SRSLTE_PHICH_NBITS); @@ -370,7 +370,7 @@ int srslte_phich_encode(srslte_phich_t *q, uint8_t ack, uint32_t ngroup, uint32_ } } - DEBUG("d: ", 0); + DEBUG("d: "); if (SRSLTE_VERBOSE_ISDEBUG()) srslte_vec_fprint_c(stdout, q->d, SRSLTE_PHICH_EXT_MSYMB); @@ -397,7 +397,7 @@ int srslte_phich_encode(srslte_phich_t *q, uint8_t ack, uint32_t ngroup, uint32_ memcpy(q->d0, q->d, SRSLTE_PHICH_MAX_NSYMB * sizeof(cf_t)); } - DEBUG("d0: ", 0); + DEBUG("d0: "); if (SRSLTE_VERBOSE_ISDEBUG()) srslte_vec_fprint_c(stdout, q->d0, SRSLTE_PHICH_MAX_NSYMB); diff --git a/lib/src/phy/phch/sch.c b/lib/src/phy/phch/sch.c index a2da3195c..3a8285f73 100644 --- a/lib/src/phy/phch/sch.c +++ b/lib/src/phy/phch/sch.c @@ -494,7 +494,7 @@ static int decode_tb(srslte_sch_t *q, ((uint32_t) data[cb_segm->tbs/8+2]); if (par_rx == par_tx && par_rx) { - INFO("TB decoded OK\n",0); + INFO("TB decoded OK\n"); return SRSLTE_SUCCESS; } else { INFO("Error in TB parity: par_tx=0x%x, par_rx=0x%x\n", par_tx, par_rx); diff --git a/lib/src/phy/phch/test/pbch_file_test.c b/lib/src/phy/phch/test/pbch_file_test.c index 2ca12e4c9..6b79db422 100644 --- a/lib/src/phy/phch/test/pbch_file_test.c +++ b/lib/src/phy/phch/test/pbch_file_test.c @@ -154,7 +154,7 @@ int base_init() { return -1; } - DEBUG("Memory init OK\n",0); + DEBUG("Memory init OK\n"); return 0; } diff --git a/lib/src/phy/phch/test/pcfich_file_test.c b/lib/src/phy/phch/test/pcfich_file_test.c index e92d6c7ba..98ff829be 100644 --- a/lib/src/phy/phch/test/pcfich_file_test.c +++ b/lib/src/phy/phch/test/pcfich_file_test.c @@ -170,7 +170,7 @@ int base_init() { return -1; } - DEBUG("Memory init OK\n",0); + DEBUG("Memory init OK\n"); return 0; } @@ -232,7 +232,7 @@ int main(int argc, char **argv) { /* Get channel estimates for each port */ srslte_chest_dl_estimate(&chest, fft_buffer, ce, 0); - INFO("Decoding PCFICH\n", 0); + INFO("Decoding PCFICH\n"); n = srslte_pcfich_decode(&pcfich, fft_buffer, ce, srslte_chest_dl_get_noise_estimate(&chest), 0, &cfi, &cfi_corr); diff --git a/lib/src/phy/phch/test/pdcch_file_test.c b/lib/src/phy/phch/test/pdcch_file_test.c index 5482d9f98..2f0ae30cc 100644 --- a/lib/src/phy/phch/test/pdcch_file_test.c +++ b/lib/src/phy/phch/test/pdcch_file_test.c @@ -180,7 +180,7 @@ int base_init() { exit(-1); } - DEBUG("Memory init OK\n",0); + DEBUG("Memory init OK\n"); return 0; } @@ -244,7 +244,7 @@ int main(int argc, char **argv) { return -1; } if (rnti == SRSLTE_SIRNTI) { - INFO("Initializing common search space for SI-RNTI\n",0); + INFO("Initializing common search space for SI-RNTI\n"); nof_locations = srslte_pdcch_common_locations(&pdcch, locations, MAX_CANDIDATES, cfi); } else { INFO("Initializing user-specific search space for RNTI: 0x%x\n", rnti); diff --git a/lib/src/phy/phch/test/pdsch_pdcch_file_test.c b/lib/src/phy/phch/test/pdsch_pdcch_file_test.c index ba662bc49..76f48b959 100644 --- a/lib/src/phy/phch/test/pdsch_pdcch_file_test.c +++ b/lib/src/phy/phch/test/pdsch_pdcch_file_test.c @@ -148,7 +148,7 @@ int base_init() { srslte_ue_dl_set_rnti(&ue_dl, rnti); - DEBUG("Memory init OK\n",0); + DEBUG("Memory init OK\n"); return 0; } diff --git a/lib/src/phy/phch/test/phich_file_test.c b/lib/src/phy/phch/test/phich_file_test.c index 65f7ce9c0..45eec4921 100644 --- a/lib/src/phy/phch/test/phich_file_test.c +++ b/lib/src/phy/phch/test/phich_file_test.c @@ -194,7 +194,7 @@ int base_init() { return -1; } - DEBUG("Memory init OK\n",0); + DEBUG("Memory init OK\n"); return 0; } @@ -257,7 +257,7 @@ int main(int argc, char **argv) { /* Get channel estimates for each port */ srslte_chest_dl_estimate(&chest, fft_buffer, ce, 0); - INFO("Decoding PHICH\n", 0); + INFO("Decoding PHICH\n"); /* Receive all PHICH groups and sequence numbers */ for (ngroup=0;ngrouptmp_cqi, data, sizeof(uint8_t) * nof_bits); srslte_crc_attach(&q->crc, q->tmp_cqi, nof_bits); - DEBUG("cqi_crc_tx=", 0); + DEBUG("cqi_crc_tx="); if (SRSLTE_VERBOSE_ISDEBUG()) { srslte_vec_fprint_b(stdout, q->tmp_cqi, nof_bits+8); } srslte_convcoder_encode(&encoder, q->tmp_cqi, q->encoded_cqi, nof_bits + 8); - DEBUG("cconv_tx=", 0); + DEBUG("cconv_tx="); if (SRSLTE_VERBOSE_ISDEBUG()) { srslte_vec_fprint_b(stdout, q->encoded_cqi, 3 * (nof_bits + 8)); } @@ -400,14 +400,14 @@ int decode_cqi_long(srslte_uci_cqi_pusch_t *q, int16_t *q_bits, uint32_t Q, srslte_rm_conv_rx_s(q_bits, Q, q->encoded_cqi_s, 3 * (nof_bits + 8)); - DEBUG("cconv_rx=", 0); + DEBUG("cconv_rx="); if (SRSLTE_VERBOSE_ISDEBUG()) { srslte_vec_fprint_s(stdout, q->encoded_cqi_s, 3 * (nof_bits + 8)); } srslte_viterbi_decode_s(&q->viterbi, q->encoded_cqi_s, q->tmp_cqi, nof_bits + 8); - DEBUG("cqi_crc_rx=", 0); + DEBUG("cqi_crc_rx="); if (SRSLTE_VERBOSE_ISDEBUG()) { srslte_vec_fprint_b(stdout, q->tmp_cqi, nof_bits+8); } diff --git a/lib/src/phy/rf/rf_utils.c b/lib/src/phy/rf/rf_utils.c index ea016c721..4587ebdcb 100644 --- a/lib/src/phy/rf/rf_utils.c +++ b/lib/src/phy/rf/rf_utils.c @@ -117,7 +117,7 @@ int rf_mib_decoder(srslte_rf_t *rf, uint32_t nof_rx_antennas,cell_search_cfg_t * INFO("Setting sampling frequency %.2f MHz for PSS search\n", (float) srate/1000000); srslte_rf_set_rx_srate(rf, (float) srate); - INFO("Starting receiver...\n", 0); + INFO("Starting receiver...\n"); srslte_rf_start_rx_stream(rf, false); // Copy CFO estimate if provided and disable CP estimation during find @@ -174,7 +174,7 @@ int rf_cell_search(srslte_rf_t *rf, uint32_t nof_rx_antennas, INFO("Setting sampling frequency %.2f MHz for PSS search\n", SRSLTE_CS_SAMP_FREQ/1000000); srslte_rf_set_rx_srate(rf, SRSLTE_CS_SAMP_FREQ); - INFO("Starting receiver...\n", 0); + INFO("Starting receiver...\n"); srslte_rf_start_rx_stream(rf, false); /* Find a cell in the given N_id_2 or go through the 3 of them to find the strongest */ diff --git a/lib/src/phy/ue/ue_sync.c b/lib/src/phy/ue/ue_sync.c index 480835e6b..7ee97c21b 100644 --- a/lib/src/phy/ue/ue_sync.c +++ b/lib/src/phy/ue/ue_sync.c @@ -751,7 +751,7 @@ int srslte_ue_sync_zerocopy_multi(srslte_ue_sync_t *q, cf_t *input_buffer[SRSLTE break; case SRSLTE_SYNC_FOUND_NOSPACE: /* If a peak was found but there is not enough space for SSS/CP detection, discard a few samples */ - INFO("No space for SSS/CP detection. Realigning frame...\n",0); + INFO("No space for SSS/CP detection. Realigning frame...\n"); q->recv_callback(q->stream, dummy_offset_buffer, q->frame_len/2, NULL); srslte_sync_reset(&q->sfind); ret = SRSLTE_SUCCESS; From dbe0fa6f4ea8d811eef09973e294c3a5848df434 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Wed, 31 Jan 2018 13:28:45 +0100 Subject: [PATCH 2/2] calculate actual period for metrics logging --- lib/include/srslte/common/metrics_hub.h | 20 +++++++++++++------- srsue/hdr/metrics_csv.h | 3 +-- srsue/hdr/metrics_stdout.h | 2 +- srsue/src/main.cc | 2 -- srsue/src/metrics_csv.cc | 10 +++------- srsue/src/metrics_stdout.cc | 11 +++-------- 6 files changed, 21 insertions(+), 27 deletions(-) diff --git a/lib/include/srslte/common/metrics_hub.h b/lib/include/srslte/common/metrics_hub.h index 961e77cc8..05ab4c5fa 100644 --- a/lib/include/srslte/common/metrics_hub.h +++ b/lib/include/srslte/common/metrics_hub.h @@ -10,6 +10,7 @@ #include #include "srslte/common/threads.h" +#include "srslte/srslte.h" namespace srslte { @@ -24,7 +25,7 @@ template class metrics_listener { public: - virtual void set_metrics(metrics_t &m) = 0; + virtual void set_metrics(metrics_t &m, const uint32_t period_usec) = 0; virtual void stop() = 0; }; @@ -34,13 +35,12 @@ class metrics_hub : public periodic_thread public: metrics_hub() :m(NULL) - ,report_period_secs(1) + ,sleep_period_start() {} bool init(metrics_interface *m_, float report_period_secs_=1.0) { m = m_; - report_period_secs = report_period_secs_; // Start with user-default priority - start_periodic(report_period_secs*1e6, -2); + start_periodic(report_period_secs_*1e6, -2); return true; } void stop() { @@ -57,18 +57,24 @@ public: } private: - void run_period() { + void run_period(){ + // get current time and check how long we slept + gettimeofday(&sleep_period_start[2], NULL); + get_time_interval(sleep_period_start); + uint32_t period = sleep_period_start[0].tv_sec*1e6 + sleep_period_start[0].tv_usec; if (m) { metrics_t metric = {}; m->get_metrics(metric); for (uint32_t i=0;iset_metrics(metric); + listeners[i]->set_metrics(metric, period); } } + // store start of sleep period + gettimeofday(&sleep_period_start[1], NULL); } metrics_interface *m; std::vector*> listeners; - float report_period_secs; + struct timeval sleep_period_start[3]; }; } // namespace srslte diff --git a/srsue/hdr/metrics_csv.h b/srsue/hdr/metrics_csv.h index 39b17bf2d..72a9dc050 100644 --- a/srsue/hdr/metrics_csv.h +++ b/srsue/hdr/metrics_csv.h @@ -49,8 +49,7 @@ public: metrics_csv(std::string filename); ~metrics_csv(); - void set_periodicity(float metrics_report_period_sec); - void set_metrics(ue_metrics_t &m); + void set_metrics(ue_metrics_t &m, const uint32_t period_usec); void set_ue_handle(ue_metrics_interface *ue_); void stop(); diff --git a/srsue/hdr/metrics_stdout.h b/srsue/hdr/metrics_stdout.h index c4cc91441..cd19e7f16 100644 --- a/srsue/hdr/metrics_stdout.h +++ b/srsue/hdr/metrics_stdout.h @@ -48,7 +48,7 @@ public: void set_periodicity(float metrics_report_period_sec); void toggle_print(bool b); - void set_metrics(ue_metrics_t &m); + void set_metrics(ue_metrics_t &m, const uint32_t period_usec); void set_ue_handle(ue_metrics_interface *ue_); void stop() {}; diff --git a/srsue/src/main.cc b/srsue/src/main.cc index 444621c12..98966510c 100644 --- a/srsue/src/main.cc +++ b/srsue/src/main.cc @@ -447,13 +447,11 @@ int main(int argc, char *argv[]) metricshub.init(ue, args.expert.metrics_period_secs); metricshub.add_listener(&metrics_screen); metrics_screen.set_ue_handle(ue); - metrics_screen.set_periodicity(args.expert.metrics_period_secs); metrics_csv metrics_file(args.expert.metrics_csv_filename); if (args.expert.metrics_csv_enable) { metricshub.add_listener(&metrics_file); metrics_file.set_ue_handle(ue); - metrics_file.set_periodicity(args.expert.metrics_period_secs); } pthread_t input; diff --git a/srsue/src/metrics_csv.cc b/srsue/src/metrics_csv.cc index aaad3f38a..54702dc26 100644 --- a/srsue/src/metrics_csv.cc +++ b/srsue/src/metrics_csv.cc @@ -68,11 +68,7 @@ void metrics_csv::stop() } } -void metrics_csv::set_periodicity(float metrics_report_period_sec) { - this->metrics_report_period = metrics_report_period_sec; -} - -void metrics_csv::set_metrics(ue_metrics_t &metrics) +void metrics_csv::set_metrics(ue_metrics_t &metrics, const uint32_t period_usec) { if (file.is_open() && ue != NULL) { if(n_reports == 0) { @@ -85,7 +81,7 @@ void metrics_csv::set_metrics(ue_metrics_t &metrics) file << float_to_string(metrics.phy.dl.mcs, 2); file << float_to_string(metrics.phy.dl.sinr, 2); file << float_to_string(metrics.phy.dl.turbo_iters, 2); - file << float_to_string((float) metrics.mac.rx_brate/metrics_report_period, 2); + file << float_to_string((float) metrics.mac.rx_brate/period_usec*1e6, 2); if (metrics.mac.rx_pkts > 0) { file << float_to_string((float) 100*metrics.mac.rx_errors/metrics.mac.rx_pkts, 1); } else { @@ -93,7 +89,7 @@ void metrics_csv::set_metrics(ue_metrics_t &metrics) } file << float_to_string(metrics.phy.ul.mcs, 2); file << float_to_string((float) metrics.mac.ul_buffer, 2); - file << float_to_string((float) metrics.mac.tx_brate/metrics_report_period, 2); + file << float_to_string((float) metrics.mac.tx_brate/period_usec*1e6, 2); if (metrics.mac.tx_pkts > 0) { file << float_to_string((float) 100*metrics.mac.tx_errors/metrics.mac.tx_pkts, 1); } else { diff --git a/srsue/src/metrics_stdout.cc b/srsue/src/metrics_stdout.cc index 9f413b65f..c8f373284 100644 --- a/srsue/src/metrics_stdout.cc +++ b/srsue/src/metrics_stdout.cc @@ -50,7 +50,6 @@ char const * const prefixes[2][9] = metrics_stdout::metrics_stdout() :do_print(false) ,n_reports(10) - ,metrics_report_period(1.0) ,ue(NULL) { } @@ -65,11 +64,7 @@ void metrics_stdout::toggle_print(bool b) do_print = b; } -void metrics_stdout::set_periodicity(float metrics_report_period_sec) { - this->metrics_report_period = metrics_report_period_sec; -} - -void metrics_stdout::set_metrics(ue_metrics_t &metrics) +void metrics_stdout::set_metrics(ue_metrics_t &metrics, const uint32_t period_usec) { if(!do_print || ue == NULL) return; @@ -92,7 +87,7 @@ void metrics_stdout::set_metrics(ue_metrics_t &metrics) cout << float_to_string(metrics.phy.dl.mcs, 2); cout << float_to_string(metrics.phy.dl.sinr, 2); cout << float_to_string(metrics.phy.dl.turbo_iters, 2); - cout << float_to_eng_string((float) metrics.mac.rx_brate/metrics_report_period, 2); + cout << float_to_eng_string((float) metrics.mac.rx_brate/period_usec*1e6, 2); if (metrics.mac.rx_pkts > 0) { cout << float_to_string((float) 100*metrics.mac.rx_errors/metrics.mac.rx_pkts, 1) << "%"; } else { @@ -100,7 +95,7 @@ void metrics_stdout::set_metrics(ue_metrics_t &metrics) } cout << float_to_string(metrics.phy.ul.mcs, 2); cout << float_to_eng_string((float) metrics.mac.ul_buffer, 2); - cout << float_to_eng_string((float) metrics.mac.tx_brate/metrics_report_period, 2); + cout << float_to_eng_string((float) metrics.mac.tx_brate/period_usec*1e6, 2); if (metrics.mac.tx_pkts > 0) { cout << float_to_string((float) 100*metrics.mac.tx_errors/metrics.mac.tx_pkts, 1) << "%"; } else {