Imported Upstream version 16.3.2
[platform/upstream/libzypp.git] / zypp / base / Measure.cc
index e5b3915..5f58582 100644 (file)
@@ -129,7 +129,7 @@ namespace zypp
         return str << obj.asString();
       }
 
-      
+
     ///////////////////////////////////////////////////////////////////
     //
     // CLASS NAME : Measure::Impl
@@ -140,9 +140,11 @@ namespace zypp
     public:
       Impl( const std::string & ident_r )
       : _ident  ( ident_r )
+      , _level  ( _glevel )
       , _seq    ( 0 )
       {
-        INT << "START MEASURE(" << _ident << ")" << endl;
+       _glevel += "..";
+        log() << _level << "START MEASURE(" << _ident << ")" << endl;
         _start.get();
       }
 
@@ -150,43 +152,56 @@ namespace zypp
       {
         _stop.get();
         ++_seq;
-        std::ostream & str( INT << "MEASURE(" << _ident << ") " );
+        std::ostream & str( log() << _level << "MEASURE(" << _ident << ") " );
         dumpMeasure( str );
+       _glevel.erase( 0, 2 );
       }
 
       void restart()
       {
-        INT << "RESTART MEASURE(" << _ident << ")" << endl;
+        log() << _level << "RESTART MEASURE(" << _ident << ")" << endl;
         _start = _stop;
       }
-      
-      void elapsed() const
+
+      void elapsed( const std::string & tag_r = std::string() ) const
       {
         _stop.get();
         ++_seq;
-        std::ostream & str( INT << "ELAPSED(" << _ident << ") " );
-        dumpMeasure( str );
+        std::ostream & str( log() << _level << "ELAPSED(" << _ident << ") " );
+        dumpMeasure( str, tag_r );
         _elapsed = _stop;
       }
 
     private:
-      std::ostream & dumpMeasure( std::ostream & str_r ) const
+      /** Return the log stream. */
+      std::ostream & log() const
+      { return INT; }
+
+      std::ostream & dumpMeasure( std::ostream & str_r, const std::string & tag_r = std::string() ) const
       {
         str_r << ( _stop - _start );
         if ( _seq > 1 ) // diff to previous _elapsed
           {
             str_r << " [" << ( _stop - _elapsed ) << "]";
           }
+       if ( ! tag_r.empty() )
+         str_r << " - " << tag_r;
         return str_r << endl;
       }
 
     private:
+      static std::string _glevel;
+
       std::string       _ident;
+      std::string       _level;
       Tm               _start;
       mutable unsigned _seq;
       mutable Tm       _elapsed;
       mutable Tm       _stop;
     };
+
+    std::string Measure::Impl::_glevel;
+
     ///////////////////////////////////////////////////////////////////
 
     ///////////////////////////////////////////////////////////////////
@@ -195,72 +210,31 @@ namespace zypp
     //
     ///////////////////////////////////////////////////////////////////
 
-    ///////////////////////////////////////////////////////////////////
-    //
-    // METHOD NAME : Measure::Measure
-    // METHOD TYPE : Ctor
-    //
     Measure::Measure()
     {}
 
-    ///////////////////////////////////////////////////////////////////
-    //
-    // METHOD NAME : Measure::Measure
-    // METHOD TYPE : Ctor
-    //
     Measure::Measure( const std::string & ident_r )
     : _pimpl( new Impl( ident_r ) )
     {}
 
-    ///////////////////////////////////////////////////////////////////
-    //
-    // METHOD NAME : Measure::~Measure
-    // METHOD TYPE : Dtor
-    //
     Measure::~Measure()
     {}
 
-    ///////////////////////////////////////////////////////////////////
-    //
-    // METHOD NAME : Measure::start
-    // METHOD TYPE : void
-    //
     void Measure::start( const std::string & ident_r )
-    {
-      stop();
-      _pimpl.reset( new Impl( ident_r ) );
-    }
+    { stop(); _pimpl.reset( new Impl( ident_r ) ); }
 
-    ///////////////////////////////////////////////////////////////////
-    //
-    // METHOD NAME : Measure::start
-    // METHOD TYPE : void
-    //
     void Measure::restart()
-    {
-      _pimpl->restart();
-    }
-    
-    ///////////////////////////////////////////////////////////////////
-    //
-    // METHOD NAME : Measure::
-    // METHOD TYPE : void
-    //
+    { _pimpl->restart(); }
+
     void Measure::elapsed() const
-    {
-      if ( _pimpl )
-        _pimpl->elapsed();
-    }
+    { if ( _pimpl ) _pimpl->elapsed(); }
+    void Measure::elapsed( const std::string & tag_r ) const
+    { if ( _pimpl ) _pimpl->elapsed( tag_r ); }
+    void Measure::elapsed( long tag_r ) const
+    { if ( _pimpl ) _pimpl->elapsed( asString( tag_r ) ); }
 
-    ///////////////////////////////////////////////////////////////////
-    //
-    // METHOD NAME : Measure::
-    // METHOD TYPE : void
-    //
     void Measure::stop()
-    {
-      _pimpl.reset();
-    }
+    { _pimpl.reset(); }
 
     /////////////////////////////////////////////////////////////////
   } // namespace debug