[Orxonox-commit 3839] r8515 - in code/branches/unity_build/src: libraries/core/command libraries/util orxonox/overlays

rgrieder at orxonox.net rgrieder at orxonox.net
Fri May 20 03:53:22 CEST 2011


Author: rgrieder
Date: 2011-05-20 03:53:21 +0200 (Fri, 20 May 2011)
New Revision: 8515

Modified:
   code/branches/unity_build/src/libraries/core/command/Shell.cc
   code/branches/unity_build/src/libraries/util/OutputHandler.cc
   code/branches/unity_build/src/libraries/util/OutputHandler.h
   code/branches/unity_build/src/orxonox/overlays/InGameConsole.cc
Log:
The output listener writing to the memory as buffer should record input of ALL levels, but instead be deactivated when not needed anymore.

Modified: code/branches/unity_build/src/libraries/core/command/Shell.cc
===================================================================
--- code/branches/unity_build/src/libraries/core/command/Shell.cc	2011-05-19 15:32:25 UTC (rev 8514)
+++ code/branches/unity_build/src/libraries/core/command/Shell.cc	2011-05-20 01:53:21 UTC (rev 8515)
@@ -83,8 +83,8 @@
         this->setConfigValues();
 
         // Get the previous output and add it to the Shell
-        for (OutputHandler::OutputVectorIterator it = OutputHandler::getInstance().getOutputVectorBegin();
-            it != OutputHandler::getInstance().getOutputVectorEnd(); ++it)
+        OutputHandler::OutputVector::const_iterator it = OutputHandler::getInstance().getOutput().begin();
+        for (;it != OutputHandler::getInstance().getOutput().end(); ++it)
         {
             if (it->first <= this->getSoftDebugLevel())
             {

Modified: code/branches/unity_build/src/libraries/util/OutputHandler.cc
===================================================================
--- code/branches/unity_build/src/libraries/util/OutputHandler.cc	2011-05-19 15:32:25 UTC (rev 8514)
+++ code/branches/unity_build/src/libraries/util/OutputHandler.cc	2011-05-20 01:53:21 UTC (rev 8515)
@@ -146,26 +146,23 @@
     @brief
         OutputListener that writes all the output piece by piece to an array
         associated with the corresponding output level.
+        Used as buffer until all output devices have been initialised.
     @note
-        Only output below or equal to the current soft debug level is written
-        to minimise huge arrays for the normal run.
+        At some point, OutputHandler::disableMemoryLog() has to be called in
+        order to avoid large memory footprints of this class.
     */
     class MemoryLogWriter : public OutputListener
     {
     public:
         friend class OutputHandler;
 
-        /**
-        @brief
-            Sets the right soft debug level and registers itself
-        */
         MemoryLogWriter()
             : OutputListener("memoryLog")
         {
             this->outputStream_ = &this->buffer_;
         }
 
-        //! Pushed the just written output to the internal array
+        //! Push the just written output to the internal array
         void outputChanged(int level)
         {
             if (!this->buffer_.str().empty())
@@ -179,8 +176,8 @@
         }
 
     private:
-        std::ostringstream                        buffer_; //!< Stream object used to process the output
-        std::vector<std::pair<int, std::string> > output_; //!< Vector containing ALL output
+        std::ostringstream          buffer_; //!< Stream object used to process the output
+        OutputHandler::OutputVector output_; //!< Vector containing ALL output
     };
 
 
@@ -211,10 +208,10 @@
         this->consoleWriter_->softDebugLevel_ = defaultLevelConsole;
         this->registerOutputListener(this->consoleWriter_);
 
-        this->output_ = new MemoryLogWriter();
-        // We capture as much input as the listener with the highest level
-        this->output_->softDebugLevel_ = getSoftDebugLevel();
-        this->registerOutputListener(this->output_);
+        this->memoryBuffer_ = new MemoryLogWriter();
+        // Write everything, e.g. use hardDebugLevel
+        this->memoryBuffer_->softDebugLevel_ = hardDebugLevel;
+        this->registerOutputListener(this->memoryBuffer_);
     }
 
     //! Destroys the LogFileWriter and the MemoryLogWriter
@@ -222,7 +219,7 @@
     {
         delete this->logFile_;
         delete this->consoleWriter_;
-        delete this->output_;
+        delete this->memoryBuffer_; // Might already be NULL
     }
 
     OutputHandler& OutputHandler::getInstance()
@@ -266,14 +263,16 @@
         this->registerOutputListener(this->consoleWriter_);
     }
 
-    OutputHandler::OutputVectorIterator OutputHandler::getOutputVectorBegin() const
+    void OutputHandler::disableMemoryLog()
     {
-        return this->output_->output_.begin();
+        this->unregisterOutputListener(this->memoryBuffer_);
+        // Only clear the buffer so we can still reference the vector
+        this->memoryBuffer_->output_.clear();
     }
 
-    OutputHandler::OutputVectorIterator OutputHandler::getOutputVectorEnd() const
+    const OutputHandler::OutputVector& OutputHandler::getOutput() const
     {
-        return this->output_->output_.end();
+        return this->memoryBuffer_->output_;
     }
 
     int OutputHandler::getSoftDebugLevel(const std::string& name) const

Modified: code/branches/unity_build/src/libraries/util/OutputHandler.h
===================================================================
--- code/branches/unity_build/src/libraries/util/OutputHandler.h	2011-05-19 15:32:25 UTC (rev 8514)
+++ code/branches/unity_build/src/libraries/util/OutputHandler.h	2011-05-20 01:53:21 UTC (rev 8515)
@@ -102,11 +102,9 @@
             static inline OutputHandler& getOutStream(int level)
                 { return OutputHandler::getInstance().setOutputLevel(level); }
 
-            typedef std::vector<std::pair<int, std::string> >::const_iterator OutputVectorIterator;
-            //! Returns an iterator to the beginning of the all-output vector
-            OutputVectorIterator getOutputVectorBegin() const;
-            //! Returns an iterator to the end of the all-output vector
-            OutputVectorIterator getOutputVectorEnd() const;
+            typedef std::vector<std::pair<int, std::string> > OutputVector;
+            //! Returns all output written so far (empty if disableMemoryLog() was called)
+            const OutputVector& getOutput() const;
 
             //! Writes to all output devices
             static inline void log(const std::string& text)
@@ -139,6 +137,8 @@
             void disableCout();
             //! Enables the std::cout stream for output (startup behaviour)
             void enableCout();
+            //! Stop writing to the memory buffer (call this as soon as possible to minimise memory usage)
+            void disableMemoryLog();
 
             //! Sets the level of the incoming output and returns the OutputHandler
             inline OutputHandler& setOutputLevel(int level)
@@ -224,7 +224,7 @@
             int                        outputLevel_;      //!< The level of the incoming output
             LogFileWriter*             logFile_;          //!< Listener that writes to the log file
             ConsoleWriter*             consoleWriter_;    //!< Listener for std::cout (just program beginning)
-            MemoryLogWriter*           output_;           //!< Listener that Stores ALL output below the current soft debug level
+            MemoryLogWriter*           memoryBuffer_;     //!< Writes to memory as a buffer (can/must be stopped at some time)
             static int                 softDebugLevel_s;  //!< Maximum of all soft debug levels. @note This is only static for faster access
     };
 

Modified: code/branches/unity_build/src/orxonox/overlays/InGameConsole.cc
===================================================================
--- code/branches/unity_build/src/orxonox/overlays/InGameConsole.cc	2011-05-19 15:32:25 UTC (rev 8514)
+++ code/branches/unity_build/src/orxonox/overlays/InGameConsole.cc	2011-05-20 01:53:21 UTC (rev 8515)
@@ -90,6 +90,10 @@
 
         this->setConfigValues();
         this->initialise();
+
+        // Output buffering is not anymore needed. Not the best solution to do
+        // this here, but there isn't much of another way.
+        OutputHandler::getInstance().disableMemoryLog();
     }
 
     /**




More information about the Orxonox-commit mailing list