Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23:20

0001 #ifndef ProfilerService_H
0002 #define ProfilerService_H
0003 
0004 //FIXME only forward declarations???
0005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0006 #include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
0007 #include "FWCore/ServiceRegistry/interface/PathContext.h"
0008 
0009 #include <vector>
0010 #include <string>
0011 
0012 // Unit test for ProfilerService
0013 namespace test {
0014   class TestProfilerService;
0015   struct CheckPaths;
0016 }  // namespace test
0017 
0018 /** \class  ProfilerService
0019  * A Service to start and stop calgrind profiling on demand...
0020  * act also as profiler watchdog 
0021  * (in the same service to avoid dependency between service)
0022  */
0023 class ProfilerService {
0024   // For tests
0025   friend class test::TestProfilerService;
0026   friend struct test::CheckPaths;
0027 
0028 public:
0029   /// Standard Service Constructor
0030   ProfilerService(edm::ParameterSet const& pset, edm::ActivityRegistry& activity);
0031 
0032   /// Destructor
0033   ~ProfilerService();
0034 
0035   // ---- Public Interface -----
0036 
0037   /// start instrumentation if not active. true if started now
0038   bool startInstrumentation();
0039 
0040   /// stop instrumentation if not active anymore; true if stopped now
0041   bool stopInstrumentation();
0042 
0043   /// forced stop instrumentation independenly of activity status; true if stopped now
0044   bool forceStopInstrumentation();
0045 
0046   // pause instrumentation (if active)
0047   bool pauseInstrumentation();
0048 
0049   // resume instrumentation (if paused)
0050   bool resumeInstrumentation();
0051 
0052   /// dump profiling information
0053   void dumpStat() const;
0054 
0055   /// true if the current event has to be instrumented
0056   bool doEvent() const { return m_doEvent; }
0057 
0058   /// true if instrumentation is active
0059   bool active() const { return m_active > 0; }
0060 
0061   // ---- Service Interface: to  be called only by the Framework ----
0062 
0063   void preSourceI(edm::StreamID) { fullEvent(); }
0064 
0065   void beginEventI(edm::StreamContext const& stream) { beginEvent(); }
0066 
0067   void endEventI(edm::StreamContext const& stream) { endEvent(); }
0068   void beginPathI(edm::StreamContext const& stream, edm::PathContext const& path) { beginPath(path.pathName()); }
0069   void endPathI(edm::StreamContext const& stream, edm::PathContext const& path, edm::HLTPathStatus const&) {
0070     endPath(path.pathName());
0071   }
0072 
0073 private:
0074   void fullEvent();
0075 
0076   void beginEvent();
0077   void endEvent();
0078 
0079   void beginPath(std::string const& path);
0080   void endPath(std::string const& path);
0081 
0082   void newEvent();
0083 
0084   // configurable
0085   int m_firstEvent;
0086   int m_lastEvent;
0087   int m_dumpInterval;
0088   std::vector<std::string> m_paths;
0089   std::vector<std::string> m_excludedPaths;
0090   bool m_allPaths;
0091 
0092   // internal state
0093   int m_evtCount;
0094   int m_counts;
0095   bool m_doEvent;
0096   int m_active;
0097   bool m_paused;
0098   std::string m_activePath;
0099 };
0100 
0101 #endif  // ProfilerService_H