CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
ProfilerService Class Reference

#include <ProfilerService.h>

Public Member Functions

bool active () const
 true if instrumentation is active More...
 
void beginEventI (const edm::EventID &, const edm::Timestamp &)
 
void beginPathI (std::string const &path)
 
bool doEvent () const
 true if the current event has to be instrumented More...
 
void dumpStat () const
 dump profiling information More...
 
void endEventI (const edm::Event &, const edm::EventSetup &)
 
void endPathI (std::string const &path, const edm::HLTPathStatus &)
 
bool forceStopInstrumentation ()
 forced stop instrumentation independenly of activity status; true if stopped now More...
 
bool pauseInstrumentation ()
 
void preSourceI (edm::StreamID)
 
 ProfilerService (edm::ParameterSet const &pset, edm::ActivityRegistry &activity)
 Standard Service Constructor. More...
 
bool resumeInstrumentation ()
 
bool startInstrumentation ()
 start instrumentation if not active. true if started now More...
 
bool stopInstrumentation ()
 stop instrumentation if not active anymore; true if stopped now More...
 
 ~ProfilerService ()
 Destructor. More...
 

Private Member Functions

void beginEvent ()
 
void beginPath (std::string const &path)
 
void endEvent ()
 
void endPath (std::string const &path)
 
void fullEvent ()
 
void newEvent ()
 

Private Attributes

int m_active
 
std::string m_activePath
 
bool m_allPaths
 
int m_counts
 
bool m_doEvent
 
int m_dumpInterval
 
int m_evtCount
 
std::vector< std::string > m_excludedPaths
 
int m_firstEvent
 
int m_lastEvent
 
std::vector< std::string > m_paths
 
bool m_paused
 

Detailed Description

A Service to start and stop calgrind profiling on demand... act also as profiler watchdog (in the same service to avoid dependency between service)

Definition at line 18 of file ProfilerService.h.

Constructor & Destructor Documentation

ProfilerService::ProfilerService ( edm::ParameterSet const &  pset,
edm::ActivityRegistry activity 
)

Standard Service Constructor.

Definition at line 12 of file ProfilerService.cc.

References beginEventI(), beginPathI(), endEventI(), endPathI(), spr::find(), fullEvent(), m_allPaths, m_paths, preSourceI(), AlCaHLTBitMon_QueryRunRegistry::string, edm::ActivityRegistry::watchPostProcessEvent(), edm::ActivityRegistry::watchPostProcessPath(), edm::ActivityRegistry::watchPostSourceEvent(), edm::ActivityRegistry::watchPreProcessEvent(), and edm::ActivityRegistry::watchPreProcessPath().

13  :
14 
15  m_firstEvent(pset.getUntrackedParameter<int>("firstEvent",0 )),
16  m_lastEvent(pset.getUntrackedParameter<int>("lastEvent",std::numeric_limits<int>::max())),
17  m_dumpInterval(pset.getUntrackedParameter<int>("dumpInterval",100)),
18  m_paths(pset.getUntrackedParameter<std::vector<std::string> >("paths",std::vector<std::string>() )),
19  m_excludedPaths(pset.getUntrackedParameter<std::vector<std::string> >("excludePaths",std::vector<std::string>() )),
20  m_allPaths(false),
21  m_evtCount(0),
22  m_counts(0),
23  m_doEvent(false),
24  m_active(0),
25  m_paused(false) {
26  static std::string const allPaths("ALL");
27  m_allPaths = std::find(m_paths.begin(),m_paths.end(),allPaths) != m_paths.end();
28 
29  // either FullEvent or selected path
30  static std::string const fullEvent("FullEvent");
31  if (std::find(m_paths.begin(),m_paths.end(),fullEvent) != m_paths.end())
33  else {
38  }
39 }
std::vector< std::string > m_excludedPaths
std::vector< std::string > m_paths
void watchPreProcessEvent(PreProcessEvent::slot_type const &iSlot)
void watchPostSourceEvent(PostSourceEvent::slot_type const &iSlot)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
void endEventI(const edm::Event &, const edm::EventSetup &)
void watchPostProcessEvent(PostProcessEvent::slot_type const &iSlot)
void preSourceI(edm::StreamID)
const T & max(const T &a, const T &b)
void beginEventI(const edm::EventID &, const edm::Timestamp &)
void beginPathI(std::string const &path)
void endPathI(std::string const &path, const edm::HLTPathStatus &)
void watchPreProcessPath(PreProcessPath::slot_type const &iSlot)
void watchPostProcessPath(PostProcessPath::slot_type const &iSlot)
ProfilerService::~ProfilerService ( )

Destructor.

Definition at line 41 of file ProfilerService.cc.

References dumpStat().

41  {
42  dumpStat();
43 }
void dumpStat() const
dump profiling information

Member Function Documentation

bool ProfilerService::active ( void  ) const
inline

true if instrumentation is active

Definition at line 54 of file ProfilerService.h.

References m_active.

54 { return m_active>0;}
void ProfilerService::beginEvent ( )
private

Definition at line 117 of file ProfilerService.cc.

References m_allPaths, newEvent(), and startInstrumentation().

Referenced by beginEventI().

117  {
118  newEvent();
119  // static std::string const fullEvent("FullEvent");
120  // if (std::find(m_paths.begin(),m_paths.end(),fullEvent) != m_paths.end())
121  if (m_allPaths)
123 }
bool startInstrumentation()
start instrumentation if not active. true if started now
void ProfilerService::beginEventI ( const edm::EventID ,
const edm::Timestamp  
)
inline

Definition at line 63 of file ProfilerService.h.

References beginEvent().

Referenced by ProfilerService().

63  {
64  beginEvent();
65  }
void ProfilerService::beginPath ( std::string const &  path)
private

Definition at line 131 of file ProfilerService.cc.

References doEvent(), spr::find(), m_activePath, m_excludedPaths, m_paths, getHLTPrescaleColumns::path, pauseInstrumentation(), and startInstrumentation().

Referenced by beginPathI().

131  {
132  if (!doEvent()) return;
133  // assume less than 5-6 path to instrument or to exclude
134  if (std::find(m_excludedPaths.begin(),m_excludedPaths.end(),path) != m_excludedPaths.end()) {
136  return;
137  }
138  if (std::find(m_paths.begin(),m_paths.end(),path) == m_paths.end()) return;
141 }
std::vector< std::string > m_excludedPaths
std::vector< std::string > m_paths
std::string m_activePath
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
bool pauseInstrumentation()
bool startInstrumentation()
start instrumentation if not active. true if started now
bool doEvent() const
true if the current event has to be instrumented
void ProfilerService::beginPathI ( std::string const &  path)
inline

Definition at line 70 of file ProfilerService.h.

References beginPath().

Referenced by ProfilerService().

70  {
71  beginPath(path);
72  }
void beginPath(std::string const &path)
bool ProfilerService::doEvent ( ) const
inline

true if the current event has to be instrumented

Definition at line 51 of file ProfilerService.h.

References m_doEvent.

Referenced by beginPath(), and startInstrumentation().

51 { return m_doEvent;}
void ProfilerService::dumpStat ( ) const

dump profiling information

Definition at line 94 of file ProfilerService.cc.

Referenced by fullEvent(), resumeInstrumentation(), startInstrumentation(), and ~ProfilerService().

94  {
95  CALLGRIND_DUMP_STATS;
96 }
void ProfilerService::endEvent ( )
private

Definition at line 125 of file ProfilerService.cc.

References forceStopInstrumentation(), and stopInstrumentation().

Referenced by endEventI().

125  {
127  // force, a nested instrumentation may fail to close in presence of filters
129 }
bool stopInstrumentation()
stop instrumentation if not active anymore; true if stopped now
bool forceStopInstrumentation()
forced stop instrumentation independenly of activity status; true if stopped now
void ProfilerService::endEventI ( const edm::Event ,
const edm::EventSetup  
)
inline

Definition at line 67 of file ProfilerService.h.

References endEvent().

Referenced by ProfilerService().

67  {
68  endEvent();
69  }
void ProfilerService::endPath ( std::string const &  path)
private

Definition at line 143 of file ProfilerService.cc.

References m_activePath, resumeInstrumentation(), and stopInstrumentation().

Referenced by endPathI().

143  {
145  if (m_activePath==path) {
147  m_activePath.clear();
148  }
149  // do to force, a nested instrumentation may fail to close in presence of filters
150  // forceStopInstrumentation();
151 }
bool resumeInstrumentation()
std::string m_activePath
bool stopInstrumentation()
stop instrumentation if not active anymore; true if stopped now
void ProfilerService::endPathI ( std::string const &  path,
const edm::HLTPathStatus  
)
inline

Definition at line 73 of file ProfilerService.h.

References endPath().

Referenced by ProfilerService().

73  {
74  endPath(path);
75  }
void endPath(std::string const &path)
bool ProfilerService::forceStopInstrumentation ( )

forced stop instrumentation independenly of activity status; true if stopped now

Definition at line 70 of file ProfilerService.cc.

References m_active.

Referenced by endEvent(), and fullEvent().

70  {
71  if (m_active==0) return false;
72  // FIXME report something if appens;
73  CALLGRIND_STOP_INSTRUMENTATION;
74  m_active=0;
75  return true;
76 }
void ProfilerService::fullEvent ( )
private

Definition at line 105 of file ProfilerService.cc.

References dumpStat(), forceStopInstrumentation(), m_active, m_doEvent, newEvent(), startInstrumentation(), and stopInstrumentation().

Referenced by preSourceI(), and ProfilerService().

105  {
106  newEvent();
107  if(m_doEvent&&m_active==0)
109  if ( (!m_doEvent) && m_active!=0) {
111  // force, a nested instrumentation may fail to close in presence of filters
113  dumpStat();
114  }
115 }
bool stopInstrumentation()
stop instrumentation if not active anymore; true if stopped now
bool forceStopInstrumentation()
forced stop instrumentation independenly of activity status; true if stopped now
bool startInstrumentation()
start instrumentation if not active. true if started now
void dumpStat() const
dump profiling information
void ProfilerService::newEvent ( )
private

Definition at line 99 of file ProfilerService.cc.

References m_doEvent, m_evtCount, m_firstEvent, and m_lastEvent.

Referenced by beginEvent(), and fullEvent().

bool ProfilerService::pauseInstrumentation ( )

Definition at line 78 of file ProfilerService.cc.

References m_active, and m_paused.

Referenced by beginPath().

78  {
79  if (m_active==0) return false;
80  CALLGRIND_STOP_INSTRUMENTATION;
81  m_paused=true;
82  return true;
83 }
void ProfilerService::preSourceI ( edm::StreamID  )
inline

Definition at line 59 of file ProfilerService.h.

References fullEvent().

Referenced by ProfilerService().

59  {
60  fullEvent();
61  }
bool ProfilerService::resumeInstrumentation ( )

Definition at line 85 of file ProfilerService.cc.

References dumpStat(), m_active, m_counts, m_dumpInterval, and m_paused.

Referenced by endPath().

85  {
86  if (m_active==0 || (!m_paused)) return false;
87  CALLGRIND_START_INSTRUMENTATION;
89  ++m_counts;
90  m_paused=false;
91  return true;
92 }
void dumpStat() const
dump profiling information
bool ProfilerService::startInstrumentation ( )

start instrumentation if not active. true if started now

Definition at line 47 of file ProfilerService.cc.

References doEvent(), dumpStat(), m_active, m_counts, and m_dumpInterval.

Referenced by beginEvent(), beginPath(), and fullEvent().

47  {
48  // FIXME here or in client?
49  if (!doEvent()) return false;
50 
51 
52  if (m_active==0) {
53  CALLGRIND_START_INSTRUMENTATION;
55  ++m_counts;
56  }
57  // support nested start/stop
58  ++m_active;
59  return m_active==1;
60 }
void dumpStat() const
dump profiling information
bool doEvent() const
true if the current event has to be instrumented
bool ProfilerService::stopInstrumentation ( )

stop instrumentation if not active anymore; true if stopped now

Definition at line 62 of file ProfilerService.cc.

References m_active.

Referenced by endEvent(), endPath(), and fullEvent().

62  {
63  if (m_active==0) return false;
64  --m_active;
65  if (m_active==0)
66  CALLGRIND_STOP_INSTRUMENTATION;
67  return m_active==0;
68 }

Member Data Documentation

int ProfilerService::m_active
private
std::string ProfilerService::m_activePath
private

Definition at line 103 of file ProfilerService.h.

Referenced by beginPath(), and endPath().

bool ProfilerService::m_allPaths
private

Definition at line 95 of file ProfilerService.h.

Referenced by beginEvent(), and ProfilerService().

int ProfilerService::m_counts
private

Definition at line 99 of file ProfilerService.h.

Referenced by resumeInstrumentation(), and startInstrumentation().

bool ProfilerService::m_doEvent
private

Definition at line 100 of file ProfilerService.h.

Referenced by doEvent(), fullEvent(), and newEvent().

int ProfilerService::m_dumpInterval
private

Definition at line 92 of file ProfilerService.h.

Referenced by resumeInstrumentation(), and startInstrumentation().

int ProfilerService::m_evtCount
private

Definition at line 98 of file ProfilerService.h.

Referenced by newEvent().

std::vector<std::string> ProfilerService::m_excludedPaths
private

Definition at line 94 of file ProfilerService.h.

Referenced by beginPath().

int ProfilerService::m_firstEvent
private

Definition at line 90 of file ProfilerService.h.

Referenced by newEvent().

int ProfilerService::m_lastEvent
private

Definition at line 91 of file ProfilerService.h.

Referenced by newEvent().

std::vector<std::string> ProfilerService::m_paths
private

Definition at line 93 of file ProfilerService.h.

Referenced by beginPath(), and ProfilerService().

bool ProfilerService::m_paused
private

Definition at line 102 of file ProfilerService.h.

Referenced by pauseInstrumentation(), and resumeInstrumentation().