Commit b9eea268 authored by Alejandro Homs Puron's avatar Alejandro Homs Puron Committed by operator for beamline
Browse files

Add FrameMap delay_stat:

* Measure systematic delay drift between first and last items
parent a0faa86e
......@@ -101,12 +101,16 @@ class FrameMap
FrameType getLastFinishedFrame() const
{ return getOldestFrame(getItemFrameArray()); }
XYStat::LinRegress calcDelayStat()
{ return m_delay_stat.calcLinRegress(); }
private:
friend class Item;
struct AtomicCounter {
int count;
Mutex mutex;
Timestamp t0;
void set(int reset)
{
......@@ -115,12 +119,17 @@ class FrameMap
mutex.unlock();
}
bool dec_test_and_reset(int reset)
bool dec_test_and_reset(int reset, double& delay)
{
mutex.lock();
Timestamp t = Timestamp::now();
if (count == reset)
t0 = t;
bool zero = (--count == 0);
if (zero)
if (zero) {
count = reset;
delay = t - t0;
}
mutex.unlock();
return zero;
}
......@@ -132,6 +141,7 @@ class FrameMap
int m_buffer_size;
CounterList m_frame_item_count_list;
ItemList m_item_list;
XYStat m_delay_stat;
};
inline bool FrameMap::Item::isBadFrame(FrameType frame)
......
......@@ -210,6 +210,10 @@ void Camera::AcqThread::threadFunction()
m_cam->getStats(stats);
DEB_ALWAYS() << DEB_VAR1(stats);
FrameMap& m = m_cam->m_frame_map;
XYStat::LinRegress delay_stat = m.calcDelayStat();
DEB_ALWAYS() << DEB_VAR1(delay_stat);
if (had_frames) {
affinity_mgr.recvFinished();
affinity_mgr.waitLimaFinished();
......
......@@ -68,9 +68,12 @@ FrameMap::Item::frameFinished(FrameType frame, bool no_check, bool valid)
for (FrameType f = m_last_frame + 1; f != (frame + 1); ++f) {
int idx = f % m_map->m_buffer_size;
AtomicCounter& count = m_map->m_frame_item_count_list[idx];
bool finished = count.dec_test_and_reset(nb_items);
if (finished)
double delay;
bool finished = count.dec_test_and_reset(nb_items, delay);
if (finished) {
finfo.finished.insert(f);
m_map->m_delay_stat.add(frame, delay);
}
}
if (DEB_CHECK_ANY(DebTypeReturn)) {
......@@ -133,6 +136,8 @@ void FrameMap::clear()
CounterList::iterator cit, cend = count_list.end();
for (cit = count_list.begin(); cit != cend; ++cit)
cit->set(m_nb_items);
m_delay_stat.reset();
}
FrameArray FrameMap::getItemFrameArray() const
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment