|
|
|
@ -29,89 +29,110 @@
|
|
|
|
|
|
|
|
|
|
namespace srslte {
|
|
|
|
|
|
|
|
|
|
struct tprof_handler {
|
|
|
|
|
explicit tprof_handler(const char* name_) : name(name_) { log_ptr->set_level(LOG_LEVEL_INFO); }
|
|
|
|
|
virtual void process(long sample) = 0;
|
|
|
|
|
template <typename Prof>
|
|
|
|
|
class tprof
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
using tpoint = std::chrono::time_point<std::chrono::high_resolution_clock>;
|
|
|
|
|
|
|
|
|
|
std::mutex mutex;
|
|
|
|
|
srslte::log_ref log_ptr = srslte::logmap::get("TPROF");
|
|
|
|
|
std::string name;
|
|
|
|
|
};
|
|
|
|
|
struct measure {
|
|
|
|
|
public:
|
|
|
|
|
measure(tprof<Prof>* h_) : t1(std::chrono::high_resolution_clock::now()), h(h_) {}
|
|
|
|
|
~measure()
|
|
|
|
|
{
|
|
|
|
|
if (deferred) {
|
|
|
|
|
stop();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
void stop()
|
|
|
|
|
{
|
|
|
|
|
auto t2 = std::chrono::high_resolution_clock::now();
|
|
|
|
|
h->process(std::chrono::duration_cast<std::chrono::nanoseconds>(t2 - t1).count());
|
|
|
|
|
}
|
|
|
|
|
void defer_stop() { deferred = true; }
|
|
|
|
|
|
|
|
|
|
struct avg_tprof : public tprof_handler {
|
|
|
|
|
avg_tprof(const char* name_, size_t print_period_) : tprof_handler(name_), print_period(print_period_) {}
|
|
|
|
|
tpoint t1;
|
|
|
|
|
tprof<Prof>* h;
|
|
|
|
|
bool deferred = false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void process(long duration) final
|
|
|
|
|
template <typename... Args>
|
|
|
|
|
explicit tprof(Args&&... args) : prof(std::forward<Args>(args)...)
|
|
|
|
|
{
|
|
|
|
|
count++;
|
|
|
|
|
avg_val = avg_val * (count - 1) / count + static_cast<double>(duration) / count;
|
|
|
|
|
max_val = std::max(max_val, duration);
|
|
|
|
|
min_val = std::min(min_val, duration);
|
|
|
|
|
if (count % print_period == 0) {
|
|
|
|
|
log_ptr->info("%s: Mean=%0.1fusec, Max=%ldusec, Min=%ldusec, nof_samples=%ld",
|
|
|
|
|
name.c_str(),
|
|
|
|
|
avg_val / 1e3,
|
|
|
|
|
max_val / 1000,
|
|
|
|
|
min_val / 1000,
|
|
|
|
|
count);
|
|
|
|
|
}
|
|
|
|
|
srslte::logmap::get("TPROF")->set_level(LOG_LEVEL_INFO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double avg_val = 1;
|
|
|
|
|
long count = 0, max_val = 0, min_val = std::numeric_limits<long>::max();
|
|
|
|
|
long print_period;
|
|
|
|
|
};
|
|
|
|
|
measure start() { return measure{this}; }
|
|
|
|
|
|
|
|
|
|
struct tprof_measure {
|
|
|
|
|
using tpoint = std::chrono::time_point<std::chrono::high_resolution_clock>;
|
|
|
|
|
virtual void process(long duration) { prof.process(duration); }
|
|
|
|
|
|
|
|
|
|
explicit tprof_measure(tprof_handler* h_) : h(h_) {}
|
|
|
|
|
|
|
|
|
|
void start() { t1 = std::chrono::high_resolution_clock::now(); }
|
|
|
|
|
Prof prof;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void stop()
|
|
|
|
|
template <typename Prof>
|
|
|
|
|
struct mutexed_tprof : public tprof<Prof> {
|
|
|
|
|
using tprof<Prof>::tprof;
|
|
|
|
|
void process(long duration) final
|
|
|
|
|
{
|
|
|
|
|
auto t2 = std::chrono::high_resolution_clock::now();
|
|
|
|
|
std::lock_guard<std::mutex> lock(h->mutex);
|
|
|
|
|
h->process(std::chrono::duration_cast<std::chrono::nanoseconds>(t2 - t1).count());
|
|
|
|
|
std::lock_guard<std::mutex> lock(mutex);
|
|
|
|
|
tprof<Prof>::prof.process(duration);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
tprof_handler* h;
|
|
|
|
|
tpoint t1;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct tprof_measure_guard {
|
|
|
|
|
tprof_measure_guard(tprof_handler* h_) : tmeas(h_) { tmeas.start(); }
|
|
|
|
|
~tprof_measure_guard() { tmeas.stop(); }
|
|
|
|
|
tprof_measure_guard(const tprof_measure_guard&) = delete;
|
|
|
|
|
tprof_measure_guard& operator=(const tprof_measure_guard&) = delete;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
tprof_measure tmeas;
|
|
|
|
|
std::mutex mutex;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
namespace srslte {
|
|
|
|
|
|
|
|
|
|
struct tprof_handler {
|
|
|
|
|
};
|
|
|
|
|
template <typename Prof>
|
|
|
|
|
struct tprof {
|
|
|
|
|
struct measure {
|
|
|
|
|
public:
|
|
|
|
|
void stop() {}
|
|
|
|
|
void defer_stop() {}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct avg_tprof : public tprof_handler {
|
|
|
|
|
avg_tprof(const char*, size_t) {}
|
|
|
|
|
};
|
|
|
|
|
template <typename... Args>
|
|
|
|
|
explicit tprof(Args&&... args)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class tprof_measure
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
explicit tprof_measure(tprof_handler* h_) {}
|
|
|
|
|
void start() {}
|
|
|
|
|
void stop() {}
|
|
|
|
|
measure start() { return measure{}; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void process(long duration) {}
|
|
|
|
|
};
|
|
|
|
|
template <typename Prof>
|
|
|
|
|
using mutexed_tprof = tprof<Prof>;
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
struct avg_time_stats {
|
|
|
|
|
avg_time_stats(const char* name_, size_t print_period_) : name(name_), print_period(print_period_) {}
|
|
|
|
|
|
|
|
|
|
void process(long duration)
|
|
|
|
|
{
|
|
|
|
|
count++;
|
|
|
|
|
avg_val = avg_val * (count - 1) / count + static_cast<double>(duration) / count;
|
|
|
|
|
max_val = std::max(max_val, duration);
|
|
|
|
|
min_val = std::min(min_val, duration);
|
|
|
|
|
if (count % print_period == 0) {
|
|
|
|
|
log_ptr->info("%s: Mean=%0.1fusec, Max=%ldusec, Min=%ldusec, nof_samples=%ld",
|
|
|
|
|
name.c_str(),
|
|
|
|
|
avg_val / 1e3,
|
|
|
|
|
max_val / 1000,
|
|
|
|
|
min_val / 1000,
|
|
|
|
|
count);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
srslte::log_ref log_ptr = srslte::logmap::get("TPROF");
|
|
|
|
|
std::string name;
|
|
|
|
|
double avg_val = 1;
|
|
|
|
|
long count = 0, max_val = 0, min_val = std::numeric_limits<long>::max();
|
|
|
|
|
long print_period;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace srslte
|
|
|
|
|
|
|
|
|
|
#endif // SRSLTE_TIME_PROF_H
|
|
|
|
|