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
{
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>

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

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

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

@ -48,57 +48,18 @@ char const * const prefixes[2][9] =
};
metrics_stdout::metrics_stdout()
:started(false)
,do_print(false)
:do_print(false)
,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)
{
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)
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::ostringstream os;

Loading…
Cancel
Save