From d95560fbcc2a35f5459a96b83fb07b7876e39ec1 Mon Sep 17 00:00:00 2001
From: Jan David Mol <mol@astron.nl>
Date: Thu, 14 Apr 2011 11:53:49 +0000
Subject: [PATCH] bug 1362: print written/dropped stats at end of obs in
 Storage, and reduced block reading message to DE BUG level

---
 RTCP/Storage/include/Storage/OutputThread.h |  1 +
 RTCP/Storage/src/InputThread.cc             |  2 +-
 RTCP/Storage/src/OutputThread.cc            | 23 ++++++++++++++-------
 3 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/RTCP/Storage/include/Storage/OutputThread.h b/RTCP/Storage/include/Storage/OutputThread.h
index c116d64cd21..7614cf7f381 100644
--- a/RTCP/Storage/include/Storage/OutputThread.h
+++ b/RTCP/Storage/include/Storage/OutputThread.h
@@ -78,6 +78,7 @@ class OutputThread
     std::vector<unsigned>   itsSequenceNumbers;
     FileStream              *itsSequenceNumbersFile;
     bool                    itsHaveCaughtException;
+    unsigned                itsBlocksWritten, itsBlocksDropped;
 };
 
 } // namespace RTCP
diff --git a/RTCP/Storage/src/InputThread.cc b/RTCP/Storage/src/InputThread.cc
index bcc5de0ae7a..67c49582fd8 100644
--- a/RTCP/Storage/src/InputThread.cc
+++ b/RTCP/Storage/src/InputThread.cc
@@ -83,7 +83,7 @@ void InputThread::mainLoop()
       //readTimer.stop();
 
       //LOG_INFO_STR(itsLogPrefix << readTimer);
-      LOG_INFO_STR(itsLogPrefix << "Read block with seqno = " << data->sequenceNumber);
+      LOG_DEBUG_STR(itsLogPrefix << "Read block with seqno = " << data->sequenceNumber);
 
       if (nullInput)
 	data.get()->sequenceNumber = count;
diff --git a/RTCP/Storage/src/OutputThread.cc b/RTCP/Storage/src/OutputThread.cc
index ab4e53bbba3..c23791774d7 100644
--- a/RTCP/Storage/src/OutputThread.cc
+++ b/RTCP/Storage/src/OutputThread.cc
@@ -117,7 +117,9 @@ OutputThread::OutputThread(const Parset &parset, const ProcessingPlan::planlet &
   itsFreeQueue(freeQueue),
   itsReceiveQueue(receiveQueue),
   itsSequenceNumbersFile(0), 
-  itsHaveCaughtException(false)
+  itsHaveCaughtException(false),
+  itsBlocksWritten(0),
+  itsBlocksDropped(0)
 {
   string fullfilename = dir + "/" + filename;
 
@@ -171,6 +173,10 @@ OutputThread::~OutputThread()
 
   if (itsHaveCaughtException)
     LOG_WARN_STR(itsLogPrefix << "OutputThread caught non-fatal exception(s).") ;
+
+  float dropPercent = itsBlocksWritten + itsBlocksDropped == 0 ? 0.0 : (100.0 * itsBlocksDropped) / (itsBlocksWritten + itsBlocksDropped);
+
+  LOG_INFO_STR(itsLogPrefix << itsBlocksWritten << " blocks written, " << itsBlocksDropped << " blocks dropped: " << std::setprecision(3) << dropPercent << "% lost" );
 }
 
 void OutputThread::writeLogMessage(unsigned sequenceNumber)
@@ -191,11 +197,16 @@ void OutputThread::flushSequenceNumbers()
 
 void OutputThread::checkForDroppedData(StreamableData *data)
 {
+  // TODO: check for dropped data at end of observation
+
   unsigned expectedSequenceNumber = itsNextSequenceNumber;
   unsigned droppedBlocks	  = data->sequenceNumber - expectedSequenceNumber;
 
-  if (droppedBlocks > 0)
+  if (droppedBlocks > 0) {
+    itsBlocksDropped++;
+
     LOG_WARN_STR(itsLogPrefix << "OutputThread dropped " << droppedBlocks << (droppedBlocks == 1 ? " block" : " blocks"));
+  }
 
   if (itsSequenceNumbersFile != 0) {
     itsSequenceNumbers.push_back(data->sequenceNumber);
@@ -218,14 +229,15 @@ void OutputThread::mainLoop()
     if (data.get() == 0)
       break;
 
-    checkForDroppedData(data.get());
-
     //writeTimer.start();
     writeSemaphore.down();
 
     try {
       itsWriter->write(data.get());
 
+      itsBlocksWritten++;
+
+      checkForDroppedData(data.get());
     } catch (SystemCallException &ex) {
       itsHaveCaughtException = true;
       LOG_WARN_STR(itsLogPrefix << "OutputThread caught non-fatal exception: " << ex.what()) ;
@@ -239,9 +251,6 @@ void OutputThread::mainLoop()
 
     itsFreeQueue.append(data.release());
   }
-
-  // CB -- non reachable? 
-  flushSequenceNumbers();
 }
 
 } // namespace RTCP
-- 
GitLab