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 23 of file ProfilerService.h.

Constructor & Destructor Documentation

◆ ProfilerService()

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

Standard Service Constructor.

Definition at line 12 of file ProfilerService.cc.

References mutracking_dqm_sourceclient-live_cfg::allPaths, 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>())),
20  pset.getUntrackedParameter<std::vector<std::string> >("excludePaths", std::vector<std::string>())),
21  m_allPaths(false),
22  m_evtCount(0),
23  m_counts(0),
24  m_doEvent(false),
25  m_active(0),
26  m_paused(false) {
27  static std::string const allPaths("ALL");
28  m_allPaths = std::find(m_paths.begin(), m_paths.end(), allPaths) != m_paths.end();
29 
30  // either FullEvent or selected path
31  static std::string const fullEvent("FullEvent");
32  if (std::find(m_paths.begin(), m_paths.end(), fullEvent) != m_paths.end())
34  else {
39  }
40 }
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:19
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::~ProfilerService ( )

Destructor.

Definition at line 42 of file ProfilerService.cc.

References dumpStat().

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

Member Function Documentation

◆ active()

bool ProfilerService::active ( void  ) const
inline

true if instrumentation is active

Definition at line 59 of file ProfilerService.h.

References m_active.

59 { return m_active > 0; }

◆ beginEvent()

void ProfilerService::beginEvent ( )
private

Definition at line 119 of file ProfilerService.cc.

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

Referenced by beginEventI().

119  {
120  newEvent();
121  // static std::string const fullEvent("FullEvent");
122  // if (std::find(m_paths.begin(),m_paths.end(),fullEvent) != m_paths.end())
123  if (m_allPaths)
125 }
bool startInstrumentation()
start instrumentation if not active. true if started now

◆ beginEventI()

void ProfilerService::beginEventI ( edm::StreamContext const &  stream)
inline

Definition at line 65 of file ProfilerService.h.

References beginEvent().

Referenced by ProfilerService().

65 { beginEvent(); }

◆ beginPath()

void ProfilerService::beginPath ( std::string const &  path)
private

Definition at line 133 of file ProfilerService.cc.

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

Referenced by beginPathI().

133  {
134  if (!doEvent())
135  return;
136  // assume less than 5-6 path to instrument or to exclude
137  if (std::find(m_excludedPaths.begin(), m_excludedPaths.end(), path) != m_excludedPaths.end()) {
139  return;
140  }
141  if (std::find(m_paths.begin(), m_paths.end(), path) == m_paths.end())
142  return;
143  m_activePath = path;
145 }
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:19
bool doEvent() const
true if the current event has to be instrumented
bool pauseInstrumentation()
bool startInstrumentation()
start instrumentation if not active. true if started now

◆ beginPathI()

void ProfilerService::beginPathI ( edm::StreamContext const &  stream,
edm::PathContext const &  path 
)
inline

Definition at line 68 of file ProfilerService.h.

References beginPath(), and castor_dqm_sourceclient_file_cfg::path.

Referenced by ProfilerService().

68 { beginPath(path.pathName()); }
void beginPath(std::string const &path)

◆ doEvent()

bool ProfilerService::doEvent ( ) const
inline

true if the current event has to be instrumented

Definition at line 56 of file ProfilerService.h.

References m_doEvent.

Referenced by beginPath(), and startInstrumentation().

56 { return m_doEvent; }

◆ dumpStat()

void ProfilerService::dumpStat ( ) const

dump profiling information

Definition at line 99 of file ProfilerService.cc.

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

99 { CALLGRIND_DUMP_STATS; }

◆ endEvent()

void ProfilerService::endEvent ( )
private

Definition at line 127 of file ProfilerService.cc.

References forceStopInstrumentation(), and stopInstrumentation().

Referenced by endEventI().

127  {
129  // force, a nested instrumentation may fail to close in presence of filters
131 }
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

◆ endEventI()

void ProfilerService::endEventI ( edm::StreamContext const &  stream)
inline

Definition at line 67 of file ProfilerService.h.

References endEvent().

Referenced by ProfilerService().

67 { endEvent(); }

◆ endPath()

void ProfilerService::endPath ( std::string const &  path)
private

Definition at line 147 of file ProfilerService.cc.

References m_activePath, castor_dqm_sourceclient_file_cfg::path, resumeInstrumentation(), and stopInstrumentation().

Referenced by endPathI().

147  {
149  if (m_activePath == path) {
151  m_activePath.clear();
152  }
153  // do to force, a nested instrumentation may fail to close in presence of filters
154  // forceStopInstrumentation();
155 }
bool resumeInstrumentation()
std::string m_activePath
bool stopInstrumentation()
stop instrumentation if not active anymore; true if stopped now

◆ endPathI()

void ProfilerService::endPathI ( edm::StreamContext const &  stream,
edm::PathContext const &  path,
edm::HLTPathStatus const &   
)
inline

Definition at line 69 of file ProfilerService.h.

References endPath(), and castor_dqm_sourceclient_file_cfg::path.

Referenced by ProfilerService().

69  {
70  endPath(path.pathName());
71  }
void endPath(std::string const &path)

◆ forceStopInstrumentation()

bool ProfilerService::forceStopInstrumentation ( )

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

Definition at line 71 of file ProfilerService.cc.

References m_active.

Referenced by endEvent(), and fullEvent().

71  {
72  if (m_active == 0)
73  return false;
74  // FIXME report something if appens;
75  CALLGRIND_STOP_INSTRUMENTATION;
76  m_active = 0;
77  return true;
78 }

◆ fullEvent()

void ProfilerService::fullEvent ( )
private

Definition at line 107 of file ProfilerService.cc.

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

Referenced by preSourceI(), and ProfilerService().

107  {
108  newEvent();
109  if (m_doEvent && m_active == 0)
111  if ((!m_doEvent) && m_active != 0) {
113  // force, a nested instrumentation may fail to close in presence of filters
115  dumpStat();
116  }
117 }
void dumpStat() const
dump profiling information
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

◆ newEvent()

void ProfilerService::newEvent ( )
private

Definition at line 102 of file ProfilerService.cc.

References m_doEvent, m_evtCount, m_firstEvent, and m_lastEvent.

Referenced by beginEvent(), and fullEvent().

◆ pauseInstrumentation()

bool ProfilerService::pauseInstrumentation ( )

Definition at line 80 of file ProfilerService.cc.

References m_active, and m_paused.

Referenced by beginPath().

80  {
81  if (m_active == 0)
82  return false;
83  CALLGRIND_STOP_INSTRUMENTATION;
84  m_paused = true;
85  return true;
86 }

◆ preSourceI()

void ProfilerService::preSourceI ( edm::StreamID  )
inline

Definition at line 63 of file ProfilerService.h.

References fullEvent().

Referenced by ProfilerService().

63 { fullEvent(); }

◆ resumeInstrumentation()

bool ProfilerService::resumeInstrumentation ( )

Definition at line 88 of file ProfilerService.cc.

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

Referenced by endPath().

88  {
89  if (m_active == 0 || (!m_paused))
90  return false;
91  CALLGRIND_START_INSTRUMENTATION;
92  if (m_counts % m_dumpInterval == 0)
93  dumpStat();
94  ++m_counts;
95  m_paused = false;
96  return true;
97 }
void dumpStat() const
dump profiling information

◆ startInstrumentation()

bool ProfilerService::startInstrumentation ( )

start instrumentation if not active. true if started now

Definition at line 46 of file ProfilerService.cc.

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

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

46  {
47  // FIXME here or in client?
48  if (!doEvent())
49  return false;
50 
51  if (m_active == 0) {
52  CALLGRIND_START_INSTRUMENTATION;
53  if (m_counts % m_dumpInterval == 0)
54  dumpStat();
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

◆ stopInstrumentation()

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)
64  return false;
65  --m_active;
66  if (m_active == 0)
67  CALLGRIND_STOP_INSTRUMENTATION;
68  return m_active == 0;
69 }

Friends And Related Function Documentation

◆ test::CheckPaths

friend struct test::CheckPaths
friend

Definition at line 26 of file ProfilerService.h.

◆ test::TestProfilerService

friend class test::TestProfilerService
friend

Definition at line 25 of file ProfilerService.h.

Member Data Documentation

◆ m_active

int ProfilerService::m_active
private

◆ m_activePath

std::string ProfilerService::m_activePath
private

Definition at line 98 of file ProfilerService.h.

Referenced by beginPath(), and endPath().

◆ m_allPaths

bool ProfilerService::m_allPaths
private

Definition at line 90 of file ProfilerService.h.

Referenced by beginEvent(), and ProfilerService().

◆ m_counts

int ProfilerService::m_counts
private

Definition at line 94 of file ProfilerService.h.

Referenced by resumeInstrumentation(), and startInstrumentation().

◆ m_doEvent

bool ProfilerService::m_doEvent
private

Definition at line 95 of file ProfilerService.h.

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

◆ m_dumpInterval

int ProfilerService::m_dumpInterval
private

Definition at line 87 of file ProfilerService.h.

Referenced by resumeInstrumentation(), and startInstrumentation().

◆ m_evtCount

int ProfilerService::m_evtCount
private

Definition at line 93 of file ProfilerService.h.

Referenced by newEvent().

◆ m_excludedPaths

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

Definition at line 89 of file ProfilerService.h.

Referenced by beginPath().

◆ m_firstEvent

int ProfilerService::m_firstEvent
private

Definition at line 85 of file ProfilerService.h.

Referenced by newEvent().

◆ m_lastEvent

int ProfilerService::m_lastEvent
private

Definition at line 86 of file ProfilerService.h.

Referenced by newEvent().

◆ m_paths

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

Definition at line 88 of file ProfilerService.h.

Referenced by beginPath(), and ProfilerService().

◆ m_paused

bool ProfilerService::m_paused
private

Definition at line 97 of file ProfilerService.h.

Referenced by pauseInstrumentation(), and resumeInstrumentation().