From 84d4f021259e589498229b65dd89cf4948022bd6 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 6 May 2016 09:17:32 +0200 Subject: tracker/hatire: add debug logging variance --- tracker-hatire/thread.cpp | 15 ++++++++++++--- tracker-hatire/thread.hpp | 5 +++++ 2 files changed, 17 insertions(+), 3 deletions(-) (limited to 'tracker-hatire') diff --git a/tracker-hatire/thread.cpp b/tracker-hatire/thread.cpp index ace4198c..e0bd445f 100755 --- a/tracker-hatire/thread.cpp +++ b/tracker-hatire/thread.cpp @@ -294,9 +294,6 @@ void hatire_thread::serial_info_impl() void hatire_thread::on_serial_read() { - constexpr int hz = 90; - constexpr int ms = 1000/hz; - { QMutexLocker lck(&data_mtx); #ifndef HATIRE_DEBUG_LOGFILE @@ -311,8 +308,20 @@ void hatire_thread::on_serial_read() } #endif } + + stat.input(timer.elapsed_ms()); + timer.start(); + + if (throttle_timer.elapsed_ms() >= 1000) + { + throttle_timer.start(); + qDebug() << "stat:" << "avg" << stat.avg() << "stddev" << stat.stddev(); + } + // qt can fire QSerialPort::readyRead() needlessly, causing a busy loop. // see https://github.com/opentrack/opentrack/issues/327#issuecomment-207941003 + constexpr int hz = 90; + constexpr int ms = 1000/hz; portable::sleep(ms); } diff --git a/tracker-hatire/thread.hpp b/tracker-hatire/thread.hpp index f36d114e..44866e51 100755 --- a/tracker-hatire/thread.hpp +++ b/tracker-hatire/thread.hpp @@ -8,6 +8,9 @@ #include #include +#include "opentrack/variance.hpp" +#include "opentrack-compat/timer.hpp" + enum results { result_ok, @@ -100,6 +103,8 @@ class hatire_thread : public QThread QByteArray data_read; serial_t com_port; thread_settings s; + variance stat; + Timer timer, throttle_timer; void run() override; -- cgit v1.2.3