diff --git a/lib/include/srsran/interfaces/e2_metrics_interface.h b/lib/include/srsran/interfaces/e2_metrics_interface.h new file mode 100644 index 000000000..0328c56d8 --- /dev/null +++ b/lib/include/srsran/interfaces/e2_metrics_interface.h @@ -0,0 +1,31 @@ +/** + * + * \section COPYRIGHT + * + * Copyright 2013-2021 Software Radio Systems Limited + * + * By using this file, you agree to the terms and conditions set + * forth in the LICENSE file which can be found at the top level of + * the distribution. + * + */ + +#include "srsran/common/common.h" +#include "srsran/common/interfaces_common.h" +#include "srsran/interfaces/enb_metrics_interface.h" +#include "srsran/srsran.h" + +#ifndef SRSRAN_E2_INTERFACES_H +#define SRSRAN_E2_INTERFACES_H + +namespace srsenb { + +class e2_interface_metrics +{ +public: + virtual bool pull_metrics(enb_metrics_t* m) = 0; +}; + +} // namespace srsenb + +#endif // SRSRAN_ENB_INTERFACES_H diff --git a/srsenb/hdr/metrics_e2.h b/srsenb/hdr/metrics_e2.h new file mode 100644 index 000000000..63aea1842 --- /dev/null +++ b/srsenb/hdr/metrics_e2.h @@ -0,0 +1,48 @@ +/** + * + * \section COPYRIGHT + * + * Copyright 2013-2021 Software Radio Systems Limited + * + * By using this file, you agree to the terms and conditions set + * forth in the LICENSE file which can be found at the top level of + * the distribution. + * + */ + +/****************************************************************************** + * File: metrics_stdout.h + * Description: Metrics class printing to stdout. + *****************************************************************************/ + +#ifndef SRSENB_METRICS_E2_H +#define SRSENB_METRICS_E2_H + +#include "srsran/interfaces/e2_metrics_interface.h" +#include "srsran/interfaces/enb_metrics_interface.h" +#include +#include +#include +#include + +#define METRICS_BUFFER_SIZE 20 +namespace srsenb { + +class metrics_e2 : public srsran::metrics_listener, public e2_interface_metrics +{ +public: + metrics_e2(enb_metrics_interface* enb_) : do_print(false) {} + void set_metrics(const enb_metrics_t& m, const uint32_t period_usec); + bool pull_metrics(enb_metrics_t* m) override; + void stop(){}; + +private: + std::atomic do_print = {false}; + uint8_t n_reports = 0; + std::queue metrics_queue; + enb_metrics_interface* enb = nullptr; +}; + +} // namespace srsenb + +#endif // SRSENB_METRICS_STDOUT_H diff --git a/srsenb/src/metrics_e2.cc b/srsenb/src/metrics_e2.cc new file mode 100644 index 000000000..ffc0f897f --- /dev/null +++ b/srsenb/src/metrics_e2.cc @@ -0,0 +1,38 @@ +/** + * + * \section COPYRIGHT + * + * Copyright 2013-2021 Software Radio Systems Limited + * + * By using this file, you agree to the terms and conditions set + * forth in the LICENSE file which can be found at the top level of + * the distribution. + * + */ + +#include "srsenb/hdr/metrics_e2.h" +#include "srsran/phy/utils/vector.h" + +using namespace srsenb; + +void metrics_e2::set_metrics(const enb_metrics_t& m, const uint32_t period_usec) +{ + if (metrics_queue.size() > METRICS_BUFFER_SIZE) { + metrics_queue.pop(); + metrics_queue.push(m); + } else { + metrics_queue.push(m); + } +} + +bool metrics_e2::pull_metrics(enb_metrics_t* m) +{ + if (enb != nullptr) { + if (!metrics_queue.empty()) { + *m = metrics_queue.front(); + metrics_queue.pop(); + return true; + } + } + return false; +}