CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes | Friends
ProfilerService Class Reference

#include <ProfilerService.h>

Public Member Functions

bool active () const
 true if instrumentation is active More...
 
void beginEventI (edm::StreamContext const &stream)
 
void beginPathI (edm::StreamContext const &stream, edm::PathContext const &path)
 
bool doEvent () const
 true if the current event has to be instrumented More...
 
void dumpStat () const
 dump profiling information More...
 
void endEventI (edm::StreamContext const &stream)
 
void endPathI (edm::StreamContext const &stream, edm::PathContext const &path, edm::HLTPathStatus const &)
 
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
 

Friends

struct test::CheckPaths
 
class test::TestProfilerService
 

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 24 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::watchPostEvent(), edm::ActivityRegistry::watchPostPathEvent(), edm::ActivityRegistry::watchPostSourceEvent(), edm::ActivityRegistry::watchPreEvent(), and edm::ActivityRegistry::watchPrePathEvent().

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 }
void watchPreEvent(PreEvent::slot_type const &iSlot)
std::vector< std::string > m_excludedPaths
void watchPrePathEvent(PrePathEvent::slot_type const &iSlot)
void endPathI(edm::StreamContext const &stream, edm::PathContext const &path, edm::HLTPathStatus const &)
std::vector< std::string > m_paths
void watchPostEvent(PostEvent::slot_type const &iSlot)
void watchPostPathEvent(PostPathEvent::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:20
void preSourceI(edm::StreamID)
void endEventI(edm::StreamContext const &stream)
void beginPathI(edm::StreamContext const &stream, edm::PathContext const &path)
void beginEventI(edm::StreamContext const &stream)
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 64 of file ProfilerService.h.

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

Definition at line 117 of file ProfilerService.cc.

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

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 ( edm::StreamContext const &  stream)
inline

Definition at line 73 of file ProfilerService.h.

Referenced by ProfilerService().

73  {
74  beginEvent();
75  }
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, callgraph::path, pauseInstrumentation(), and startInstrumentation().

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:20
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 ( edm::StreamContext const &  stream,
edm::PathContext const &  path 
)
inline

Definition at line 80 of file ProfilerService.h.

References edm::PathContext::pathName().

Referenced by ProfilerService().

80  {
81  beginPath(path.pathName());
82  }
void beginPath(std::string const &path)
bool ProfilerService::doEvent ( ) const
inline

true if the current event has to be instrumented

Definition at line 61 of file ProfilerService.h.

Referenced by beginPath(), and startInstrumentation().

61 { 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().

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 ( edm::StreamContext const &  stream)
inline

Definition at line 77 of file ProfilerService.h.

Referenced by ProfilerService().

77  {
78  endEvent();
79  }
void ProfilerService::endPath ( std::string const &  path)
private

Definition at line 143 of file ProfilerService.cc.

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

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 ( edm::StreamContext const &  stream,
edm::PathContext const &  path,
edm::HLTPathStatus const &   
)
inline

Definition at line 83 of file ProfilerService.h.

References callgraph::path, edm::PathContext::pathName(), and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by ProfilerService().

83  {
84  endPath(path.pathName());
85  }
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 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 69 of file ProfilerService.h.

Referenced by ProfilerService().

69  {
70  fullEvent();
71  }
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 }

Friends And Related Function Documentation

friend struct test::CheckPaths
friend

Definition at line 27 of file ProfilerService.h.

friend class test::TestProfilerService
friend

Definition at line 26 of file ProfilerService.h.

Member Data Documentation

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

Definition at line 113 of file ProfilerService.h.

Referenced by beginPath(), and endPath().

bool ProfilerService::m_allPaths
private

Definition at line 105 of file ProfilerService.h.

Referenced by beginEvent(), and ProfilerService().

int ProfilerService::m_counts
private

Definition at line 109 of file ProfilerService.h.

Referenced by resumeInstrumentation(), and startInstrumentation().

bool ProfilerService::m_doEvent
private

Definition at line 110 of file ProfilerService.h.

Referenced by fullEvent(), and newEvent().

int ProfilerService::m_dumpInterval
private

Definition at line 102 of file ProfilerService.h.

Referenced by resumeInstrumentation(), and startInstrumentation().

int ProfilerService::m_evtCount
private

Definition at line 108 of file ProfilerService.h.

Referenced by newEvent().

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

Definition at line 104 of file ProfilerService.h.

Referenced by beginPath().

int ProfilerService::m_firstEvent
private

Definition at line 100 of file ProfilerService.h.

Referenced by newEvent().

int ProfilerService::m_lastEvent
private

Definition at line 101 of file ProfilerService.h.

Referenced by newEvent().

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

Definition at line 103 of file ProfilerService.h.

Referenced by beginPath(), and ProfilerService().

bool ProfilerService::m_paused
private

Definition at line 112 of file ProfilerService.h.

Referenced by pauseInstrumentation(), and resumeInstrumentation().