|
|
@ -25,42 +25,74 @@
|
|
|
|
#include "srslte/common/logmap.h"
|
|
|
|
#include "srslte/common/logmap.h"
|
|
|
|
#include <chrono>
|
|
|
|
#include <chrono>
|
|
|
|
|
|
|
|
|
|
|
|
namespace srslte {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef ENABLE_TIMEPROF
|
|
|
|
#ifdef ENABLE_TIMEPROF
|
|
|
|
|
|
|
|
#define TPROF_ENABLE_DEFAULT true
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define TPROF_ENABLE_DEFAULT false
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
template <typename Prof>
|
|
|
|
namespace srslte {
|
|
|
|
class tprof
|
|
|
|
|
|
|
|
|
|
|
|
// individual time interval measure
|
|
|
|
|
|
|
|
class tprof_measure
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
using tpoint = std::chrono::time_point<std::chrono::high_resolution_clock>;
|
|
|
|
using tpoint = std::chrono::time_point<std::chrono::high_resolution_clock>;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tprof_measure() = default;
|
|
|
|
|
|
|
|
void start() { t1 = std::chrono::high_resolution_clock::now(); }
|
|
|
|
|
|
|
|
std::chrono::nanoseconds stop()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
auto t2 = std::chrono::high_resolution_clock::now();
|
|
|
|
|
|
|
|
return std::chrono::duration_cast<std::chrono::nanoseconds>(t2 - t1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
tpoint t1;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <typename Prof, bool Enabled = TPROF_ENABLE_DEFAULT>
|
|
|
|
|
|
|
|
class tprof
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
template <typename... Args>
|
|
|
|
template <typename... Args>
|
|
|
|
explicit tprof(Args&&... args) : prof(std::forward<Args>(args)...)
|
|
|
|
explicit tprof(Args&&... args) : prof(std::forward<Args>(args)...)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
srslte::logmap::get("TPROF")->set_level(LOG_LEVEL_INFO);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void start() { t1 = std::chrono::high_resolution_clock::now(); }
|
|
|
|
void start() { meas.start(); }
|
|
|
|
|
|
|
|
|
|
|
|
std::chrono::nanoseconds stop()
|
|
|
|
std::chrono::nanoseconds stop()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto t2 = std::chrono::high_resolution_clock::now();
|
|
|
|
auto d = meas.stop();
|
|
|
|
auto d = std::chrono::duration_cast<std::chrono::nanoseconds>(t2 - t1);
|
|
|
|
prof(d);
|
|
|
|
prof.process(d);
|
|
|
|
|
|
|
|
return d;
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
tpoint t1;
|
|
|
|
tprof_measure meas;
|
|
|
|
Prof prof;
|
|
|
|
Prof prof;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// specialization for when the tprof is disabled
|
|
|
|
template <typename Prof>
|
|
|
|
template <typename Prof>
|
|
|
|
|
|
|
|
class tprof<Prof, false>
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
template <typename... Args>
|
|
|
|
|
|
|
|
explicit tprof(Args&&... args)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void start() {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::chrono::nanoseconds stop() { return std::chrono::nanoseconds{0}; }
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <typename Prof, bool Enabled = TPROF_ENABLE_DEFAULT>
|
|
|
|
struct mutexed_tprof {
|
|
|
|
struct mutexed_tprof {
|
|
|
|
using tpoint = std::chrono::time_point<std::chrono::high_resolution_clock>;
|
|
|
|
|
|
|
|
struct measure {
|
|
|
|
struct measure {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
measure(mutexed_tprof<Prof>* h_) : t1(std::chrono::high_resolution_clock::now()), h(h_) {}
|
|
|
|
explicit measure(mutexed_tprof<Prof>* h_) : h(h_) { meas.start(); }
|
|
|
|
~measure()
|
|
|
|
~measure()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (deferred) {
|
|
|
|
if (deferred) {
|
|
|
@ -69,15 +101,14 @@ struct mutexed_tprof {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
std::chrono::nanoseconds stop()
|
|
|
|
std::chrono::nanoseconds stop()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto t2 = std::chrono::high_resolution_clock::now();
|
|
|
|
auto d = meas.stop();
|
|
|
|
std::lock_guard<std::mutex> lock(h->mutex);
|
|
|
|
std::lock_guard<std::mutex> lock(h->mutex);
|
|
|
|
std::chrono::nanoseconds d = std::chrono::duration_cast<std::chrono::nanoseconds>(t2 - t1);
|
|
|
|
h->prof(d);
|
|
|
|
h->prof.process(d);
|
|
|
|
|
|
|
|
return d;
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void defer_stop() { deferred = true; }
|
|
|
|
void defer_stop() { deferred = true; }
|
|
|
|
|
|
|
|
|
|
|
|
tpoint t1;
|
|
|
|
tprof_measure meas;
|
|
|
|
mutexed_tprof<Prof>* h;
|
|
|
|
mutexed_tprof<Prof>* h;
|
|
|
|
bool deferred = false;
|
|
|
|
bool deferred = false;
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -85,7 +116,6 @@ struct mutexed_tprof {
|
|
|
|
template <typename... Args>
|
|
|
|
template <typename... Args>
|
|
|
|
explicit mutexed_tprof(Args&&... args) : prof(std::forward<Args>(args)...)
|
|
|
|
explicit mutexed_tprof(Args&&... args) : prof(std::forward<Args>(args)...)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
srslte::logmap::get("TPROF")->set_level(LOG_LEVEL_INFO);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
measure start() { return measure{this}; }
|
|
|
|
measure start() { return measure{this}; }
|
|
|
|
|
|
|
|
|
|
|
@ -95,24 +125,11 @@ private:
|
|
|
|
std::mutex mutex;
|
|
|
|
std::mutex mutex;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <typename Prof>
|
|
|
|
|
|
|
|
struct tprof {
|
|
|
|
|
|
|
|
template <typename... Args>
|
|
|
|
|
|
|
|
explicit tprof(Args&&... args)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void start() {}
|
|
|
|
|
|
|
|
std::chrono::nanoseconds stop() { return {}; }
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <typename Prof>
|
|
|
|
template <typename Prof>
|
|
|
|
struct mutexed_tprof {
|
|
|
|
struct mutexed_tprof<Prof, false> {
|
|
|
|
struct measure {
|
|
|
|
struct measure {
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
std::chrono::nanoseconds stop() { return {}; }
|
|
|
|
std::chrono::nanoseconds stop() { return std::chrono::nanoseconds{0}; }
|
|
|
|
void defer_stop() {}
|
|
|
|
void defer_stop() {}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
@ -120,20 +137,14 @@ struct mutexed_tprof {
|
|
|
|
explicit mutexed_tprof(Args&&... args)
|
|
|
|
explicit mutexed_tprof(Args&&... args)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
measure start() {}
|
|
|
|
measure start() { return measure{}; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void process(long duration) {}
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct avg_time_stats {
|
|
|
|
struct avg_time_stats {
|
|
|
|
avg_time_stats(const char* name_, size_t print_period_) : name(name_), print_period(print_period_) {}
|
|
|
|
avg_time_stats(const char* name_, const char* logname, size_t print_period_);
|
|
|
|
void process(std::chrono::nanoseconds duration);
|
|
|
|
void operator()(std::chrono::nanoseconds duration);
|
|
|
|
|
|
|
|
|
|
|
|
srslte::log_ref log_ptr = srslte::logmap::get("TPROF");
|
|
|
|
srslte::log_ref log_ptr;
|
|
|
|
std::string name;
|
|
|
|
std::string name;
|
|
|
|
double avg_val = 1;
|
|
|
|
double avg_val = 1;
|
|
|
|
long count = 0, max_val = 0, min_val = std::numeric_limits<long>::max();
|
|
|
|
long count = 0, max_val = 0, min_val = std::numeric_limits<long>::max();
|
|
|
@ -144,14 +155,13 @@ template <typename TUnit>
|
|
|
|
class sliding_window_stats
|
|
|
|
class sliding_window_stats
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
sliding_window_stats(const char* name_, size_t print_period_ = 10, TUnit warn_thres_ = 0);
|
|
|
|
sliding_window_stats(const char* name_, const char* logname, size_t print_period_ = 10);
|
|
|
|
void process(std::chrono::nanoseconds duration);
|
|
|
|
void operator()(std::chrono::nanoseconds duration);
|
|
|
|
|
|
|
|
|
|
|
|
srslte::log_ref log_ptr = srslte::logmap::get("TPROF");
|
|
|
|
srslte::log_ref log_ptr;
|
|
|
|
std::string name;
|
|
|
|
std::string name;
|
|
|
|
std::vector<std::chrono::nanoseconds> sliding_window;
|
|
|
|
std::vector<std::chrono::nanoseconds> sliding_window;
|
|
|
|
size_t window_idx = 0;
|
|
|
|
size_t window_idx = 0;
|
|
|
|
TUnit warn_thres = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
using sliding_window_stats_ms = sliding_window_stats<std::chrono::milliseconds>;
|
|
|
|
using sliding_window_stats_ms = sliding_window_stats<std::chrono::milliseconds>;
|
|
|
|
|
|
|
|
|
|
|
|