Commits

Anonymous committed c6a9649

extended IPerfMonSvc interface to allow user-defined start/stop (cpu/mem) monitoring hooks

Comments (0)

Files changed (3)

+2008-04-10  Sebastien Binet  <binet@lblbox>
+
+	* tagging PerfMonKernel-00-07-00
+	* extended IPerfMonSvc interface to allow user-defined start/stop
+	  (cpu/mem) monitoring hooks
+	* added a helper RAII class to ease usage of above new feature
+	* M PerfMonKernel/IPerfMonSvc.h
+	* M src/IPerfMonSvc.cxx
+
 2007-11-29  Sebastien Binet  <binet@lblbox>
 
 	* tagging PerfMonKernel-00-06-00

PerfMonKernel/IPerfMonSvc.h

 
 // forward declaration
 namespace AIDA { class IBaseHistogram; }
+class INamedInterface;
+namespace PerfMon { class ScopedMonitor; }
 
 class IPerfMonSvc : virtual public IMonitorSvc
 { 
+  friend class PerfMon::ScopedMonitor;
+
   /////////////////////////////////////////////////////////////////// 
   // Public methods: 
   /////////////////////////////////////////////////////////////////// 
   /////////////////////////////////////////////////////////////////// 
  protected: 
 
+  /// helper method to retrieve the current performance monitoring service
+  static IPerfMonSvc* instance();
+
   /// set the current state of the Gaudi's FSM
   void setMonState( PerfMon::State::Type step )
   { m_monState = step; }
 
+  /** Start collecting monitoring data on behalf of @a requester, with some
+   *  user provided label @a item
+   */
+  virtual void startAud( const std::string& item,
+			 const INamedInterface& requester ) = 0;
+
+  /** Stop collecting monitoring data on behalf of @a requester, with some
+   *  user provided label @a item
+   */
+  virtual void stopAud ( const std::string& item,
+			 const INamedInterface& requester ) = 0;
+
   /////////////////////////////////////////////////////////////////// 
   // Private methods: 
   /////////////////////////////////////////////////////////////////// 
   return IID_IPerfMonSvc; 
 }
 
+namespace PerfMon {
+/// simple helper class using RAII to start/stop monitoring
+class ScopedMonitor
+{
+  /// the label of this monitor helper
+  std::string m_item;
+  /// the component which asked to start a perf audit
+  const INamedInterface& m_requester;
+  /// the pointer to the performance monitoring service
+  IPerfMonSvc* m_monSvc;
+  
+  ScopedMonitor();// not implemented
+ public:
+  ScopedMonitor( const std::string& item, 
+		 const INamedInterface& requester ) :
+    m_item     ( item ),
+    m_requester( requester ),
+    m_monSvc   ( IPerfMonSvc::instance() )
+  {
+    if (m_monSvc) m_monSvc->startAud( m_item, m_requester );
+  }
+  ~ScopedMonitor()
+  {
+    if (m_monSvc) m_monSvc->stopAud ( m_item, m_requester );
+  }
+};
+} //> namespace PerfMon
+
 #endif //> PERFMONKERNEL_IPERFMONSVC_H

src/IPerfMonSvc.cxx

 // Author: S.Binet<binet@cern.ch>
 /////////////////////////////////////////////////////////////////// 
 
+// Gaudi includes
+#include "GaudiKernel/Bootstrap.h"
+#include "GaudiKernel/ISvcLocator.h"
+
 // PerfMonKernel includes
 #include "PerfMonKernel/IPerfMonSvc.h"
 
 // Non-const methods: 
 /////////////////////////////////////////////////////////////////// 
 
+/// helper method to retrieve the current performance monitoring service
+IPerfMonSvc* IPerfMonSvc::instance()
+{
+  static IPerfMonSvc * svc = 0;
+  if ( 0 == svc ) {
+    ISvcLocator * svcLocator = Gaudi::svcLocator();
+    if ( svcLocator ) {
+      const bool createIf = true;
+      svcLocator->service( "PerfMonSvc", svc, createIf ).ignore();
+    }
+  }
+  
+  return svc;
+}
+