use metrics_hub in UE

master
Andre Puschmann 7 years ago
parent c7c2ab6ed5
commit 0636aa289c

@ -24,7 +24,7 @@ template<typename metrics_t>
class metrics_listener class metrics_listener
{ {
public: public:
virtual void set_metrics(metrics_t &m) = 0; virtual void set_metrics(metrics_t &m, float report_period_secs=1.0) = 0;
}; };
template<typename metrics_t> template<typename metrics_t>

@ -36,35 +36,25 @@
#include <stdint.h> #include <stdint.h>
#include <string> #include <string>
#include "srslte/common/metrics_hub.h"
#include "ue_metrics_interface.h" #include "ue_metrics_interface.h"
namespace srsue { namespace srsue {
class metrics_stdout class metrics_stdout : public srslte::metrics_listener<ue_metrics_t>
{ {
public: public:
metrics_stdout(); metrics_stdout();
bool init(ue_metrics_interface *u, float report_period_secs=1.0);
void stop();
void toggle_print(bool b); void toggle_print(bool b);
static void* metrics_thread_start(void *m); void set_metrics(ue_metrics_t &m, float report_period_secs);
void metrics_thread_run();
private: private:
void print_metrics();
void print_disconnect();
std::string float_to_string(float f, int digits); std::string float_to_string(float f, int digits);
std::string float_to_eng_string(float f, int digits); std::string float_to_eng_string(float f, int digits);
std::string int_to_eng_string(int f, int digits); std::string int_to_eng_string(int f, int digits);
ue_metrics_interface *ue_;
bool started;
bool do_print; bool do_print;
pthread_t metrics_thread;
ue_metrics_t metrics;
float metrics_report_period; // seconds
uint8_t n_reports; uint8_t n_reports;
}; };

@ -29,6 +29,7 @@
#include <stdint.h> #include <stdint.h>
#include "srslte/common/metrics_hub.h"
#include "upper/gw_metrics.h" #include "upper/gw_metrics.h"
#include "srslte/upper/rlc_metrics.h" #include "srslte/upper/rlc_metrics.h"
#include "mac/mac_metrics.h" #include "mac/mac_metrics.h"
@ -52,7 +53,7 @@ typedef struct {
}ue_metrics_t; }ue_metrics_t;
// UE interface // UE interface
class ue_metrics_interface class ue_metrics_interface : public srslte::metrics_interface<ue_metrics_t>
{ {
public: public:
virtual bool get_metrics(ue_metrics_t &m) = 0; virtual bool get_metrics(ue_metrics_t &m) = 0;

@ -38,6 +38,7 @@
#include "ue.h" #include "ue.h"
#include "metrics_stdout.h" #include "metrics_stdout.h"
#include "srslte/common/metrics_hub.h"
#include "srslte/version.h" #include "srslte/version.h"
using namespace std; using namespace std;
@ -320,13 +321,13 @@ void parse_args(all_args_t *args, int argc, char *argv[]) {
static bool running = true; static bool running = true;
static bool do_metrics = false; static bool do_metrics = false;
metrics_stdout metrics_screen;
void sig_int_handler(int signo) { void sig_int_handler(int signo) {
running = false; running = false;
} }
void *input_loop(void *m) { void *input_loop(void *m) {
metrics_stdout *metrics = (metrics_stdout *) m;
char key; char key;
while (running) { while (running) {
cin >> key; cin >> key;
@ -337,7 +338,7 @@ void *input_loop(void *m) {
} else { } else {
cout << "Enter t to restart trace." << endl; cout << "Enter t to restart trace." << endl;
} }
metrics->toggle_print(do_metrics); metrics_screen.toggle_print(do_metrics);
} }
} }
return NULL; return NULL;
@ -345,6 +346,7 @@ void *input_loop(void *m) {
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
srslte::metrics_hub<ue_metrics_t> metricshub;
signal(SIGINT, sig_int_handler); signal(SIGINT, sig_int_handler);
all_args_t args; all_args_t args;
parse_args(&args, argc, argv); parse_args(&args, argc, argv);
@ -361,11 +363,12 @@ int main(int argc, char *argv[])
exit(1); exit(1);
} }
metrics_stdout metrics;
metrics.init(ue, args.expert.metrics_period_secs); metricshub.init(ue, args.expert.metrics_period_secs);
metricshub.add_listener(&metrics_screen);
pthread_t input; pthread_t input;
pthread_create(&input, NULL, &input_loop, &metrics); pthread_create(&input, NULL, &input_loop, &args);
bool plot_started = false; bool plot_started = false;
bool signals_pregenerated = false; bool signals_pregenerated = false;
@ -383,7 +386,7 @@ int main(int argc, char *argv[])
sleep(1); sleep(1);
} }
pthread_cancel(input); pthread_cancel(input);
metrics.stop(); metricshub.stop();
ue->stop(); ue->stop();
ue->cleanup(); ue->cleanup();
cout << "--- exiting ---" << endl; cout << "--- exiting ---" << endl;

@ -48,57 +48,18 @@ char const * const prefixes[2][9] =
}; };
metrics_stdout::metrics_stdout() metrics_stdout::metrics_stdout()
:started(false) :do_print(false)
,do_print(false)
,n_reports(10) ,n_reports(10)
{ {
} }
bool metrics_stdout::init(ue_metrics_interface *u, float report_period_secs)
{
ue_ = u;
metrics_report_period = report_period_secs;
started = true;
pthread_create(&metrics_thread, NULL, &metrics_thread_start, this);
return true;
}
void metrics_stdout::stop()
{
if(started)
{
started = false;
pthread_join(metrics_thread, NULL);
}
}
void metrics_stdout::toggle_print(bool b) void metrics_stdout::toggle_print(bool b)
{ {
do_print = b; do_print = b;
} }
void* metrics_stdout::metrics_thread_start(void *m_)
{
metrics_stdout *m = (metrics_stdout*)m_;
m->metrics_thread_run();
return NULL;
}
void metrics_stdout::metrics_thread_run()
{
while(started)
{
usleep(metrics_report_period*1e6);
if(ue_->get_metrics(metrics)) {
print_metrics();
} else {
print_disconnect();
}
}
}
void metrics_stdout::print_metrics() void metrics_stdout::set_metrics(ue_metrics_t &metrics, float metrics_report_period)
{ {
if(!do_print) if(!do_print)
return; return;
@ -138,13 +99,6 @@ void metrics_stdout::print_metrics()
} }
void metrics_stdout::print_disconnect()
{
if(do_print) {
cout << "--- disconnected ---" << endl;
}
}
std::string metrics_stdout::float_to_string(float f, int digits) std::string metrics_stdout::float_to_string(float f, int digits)
{ {
std::ostringstream os; std::ostringstream os;

Loading…
Cancel
Save