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.

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 }

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

◆ ~ProfilerService()

ProfilerService::~ProfilerService ( )

Destructor.

Definition at line 42 of file ProfilerService.cc.

42 { dumpStat(); }

References dumpStat().

Member Function Documentation

◆ active()

bool ProfilerService::active ( void  ) const
inline

true if instrumentation is active

Definition at line 59 of file ProfilerService.h.

59 { return m_active > 0; }

References m_active.

◆ beginEvent()

void ProfilerService::beginEvent ( )
private

Definition at line 119 of file ProfilerService.cc.

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 }

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

Referenced by beginEventI().

◆ beginEventI()

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

Definition at line 65 of file ProfilerService.h.

65 { beginEvent(); }

References beginEvent().

Referenced by ProfilerService().

◆ beginPath()

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

Definition at line 133 of file ProfilerService.cc.

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 }

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

Referenced by beginPathI().

◆ beginPathI()

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

Definition at line 68 of file ProfilerService.h.

68 { beginPath(path.pathName()); }

References beginPath(), and castor_dqm_sourceclient_file_cfg::path.

Referenced by ProfilerService().

◆ doEvent()

bool ProfilerService::doEvent ( ) const
inline

true if the current event has to be instrumented

Definition at line 56 of file ProfilerService.h.

56 { return m_doEvent; }

References m_doEvent.

Referenced by beginPath(), and startInstrumentation().

◆ dumpStat()

void ProfilerService::dumpStat ( ) const

dump profiling information

Definition at line 99 of file ProfilerService.cc.

99 { CALLGRIND_DUMP_STATS; }

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

◆ endEvent()

void ProfilerService::endEvent ( )
private

Definition at line 127 of file ProfilerService.cc.

127  {
129  // force, a nested instrumentation may fail to close in presence of filters
131 }

References forceStopInstrumentation(), and stopInstrumentation().

Referenced by endEventI().

◆ endEventI()

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

Definition at line 67 of file ProfilerService.h.

67 { endEvent(); }

References endEvent().

Referenced by ProfilerService().

◆ endPath()

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

Definition at line 147 of file ProfilerService.cc.

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 }

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

Referenced by endPathI().

◆ endPathI()

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

Definition at line 69 of file ProfilerService.h.

69  {
70  endPath(path.pathName());
71  }

References endPath(), and castor_dqm_sourceclient_file_cfg::path.

Referenced by ProfilerService().

◆ forceStopInstrumentation()

bool ProfilerService::forceStopInstrumentation ( )

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

Definition at line 71 of file ProfilerService.cc.

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 }

References m_active.

Referenced by endEvent(), and fullEvent().

◆ fullEvent()

void ProfilerService::fullEvent ( )
private

Definition at line 107 of file ProfilerService.cc.

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 }

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

Referenced by preSourceI(), and ProfilerService().

◆ newEvent()

void ProfilerService::newEvent ( )
private

Definition at line 102 of file ProfilerService.cc.

102  {
103  ++m_evtCount;
105 }

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.

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

References m_active, and m_paused.

Referenced by beginPath().

◆ preSourceI()

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

Definition at line 63 of file ProfilerService.h.

63 { fullEvent(); }

References fullEvent().

Referenced by ProfilerService().

◆ resumeInstrumentation()

bool ProfilerService::resumeInstrumentation ( )

Definition at line 88 of file ProfilerService.cc.

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 }

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

Referenced by endPath().

◆ startInstrumentation()

bool ProfilerService::startInstrumentation ( )

start instrumentation if not active. true if started now

Definition at line 46 of file ProfilerService.cc.

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 }

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

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

◆ stopInstrumentation()

bool ProfilerService::stopInstrumentation ( )

stop instrumentation if not active anymore; true if stopped now

Definition at line 62 of file ProfilerService.cc.

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 }

References m_active.

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

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

ProfilerService::stopInstrumentation
bool stopInstrumentation()
stop instrumentation if not active anymore; true if stopped now
Definition: ProfilerService.cc:62
mutracking_dqm_sourceclient-live_cfg.allPaths
allPaths
Definition: mutracking_dqm_sourceclient-live_cfg.py:181
ProfilerService::fullEvent
void fullEvent()
Definition: ProfilerService.cc:107
ProfilerService::m_firstEvent
int m_firstEvent
Definition: ProfilerService.h:85
ProfilerService::endEventI
void endEventI(edm::StreamContext const &stream)
Definition: ProfilerService.h:67
ProfilerService::startInstrumentation
bool startInstrumentation()
start instrumentation if not active. true if started now
Definition: ProfilerService.cc:46
ProfilerService::endPath
void endPath(std::string const &path)
Definition: ProfilerService.cc:147
ProfilerService::m_active
int m_active
Definition: ProfilerService.h:96
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
edm::ActivityRegistry::watchPostSourceEvent
void watchPostSourceEvent(PostSourceEvent::slot_type const &iSlot)
Definition: ActivityRegistry.h:190
edm::ActivityRegistry::watchPreEvent
void watchPreEvent(PreEvent::slot_type const &iSlot)
Definition: ActivityRegistry.h:458
ProfilerService::m_dumpInterval
int m_dumpInterval
Definition: ProfilerService.h:87
ProfilerService::beginEvent
void beginEvent()
Definition: ProfilerService.cc:119
ProfilerService::beginEventI
void beginEventI(edm::StreamContext const &stream)
Definition: ProfilerService.h:65
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
ProfilerService::m_excludedPaths
std::vector< std::string > m_excludedPaths
Definition: ProfilerService.h:89
ProfilerService::resumeInstrumentation
bool resumeInstrumentation()
Definition: ProfilerService.cc:88
ProfilerService::m_doEvent
bool m_doEvent
Definition: ProfilerService.h:95
edm::ActivityRegistry::watchPostEvent
void watchPostEvent(PostEvent::slot_type const &iSlot)
Definition: ActivityRegistry.h:464
ProfilerService::beginPath
void beginPath(std::string const &path)
Definition: ProfilerService.cc:133
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
ProfilerService::beginPathI
void beginPathI(edm::StreamContext const &stream, edm::PathContext const &path)
Definition: ProfilerService.h:68
ProfilerService::endPathI
void endPathI(edm::StreamContext const &stream, edm::PathContext const &path, edm::HLTPathStatus const &)
Definition: ProfilerService.h:69
ProfilerService::m_counts
int m_counts
Definition: ProfilerService.h:94
ProfilerService::pauseInstrumentation
bool pauseInstrumentation()
Definition: ProfilerService.cc:80
ProfilerService::m_lastEvent
int m_lastEvent
Definition: ProfilerService.h:86
edm::ActivityRegistry::watchPostPathEvent
void watchPostPathEvent(PostPathEvent::slot_type const &iSlot)
Definition: ActivityRegistry.h:476
ProfilerService::m_activePath
std::string m_activePath
Definition: ProfilerService.h:98
ProfilerService::m_evtCount
int m_evtCount
Definition: ProfilerService.h:93
ProfilerService::newEvent
void newEvent()
Definition: ProfilerService.cc:102
ProfilerService::m_paths
std::vector< std::string > m_paths
Definition: ProfilerService.h:88
ProfilerService::doEvent
bool doEvent() const
true if the current event has to be instrumented
Definition: ProfilerService.h:56
ProfilerService::m_paused
bool m_paused
Definition: ProfilerService.h:97
ProfilerService::forceStopInstrumentation
bool forceStopInstrumentation()
forced stop instrumentation independenly of activity status; true if stopped now
Definition: ProfilerService.cc:71
castor_dqm_sourceclient_file_cfg.path
path
Definition: castor_dqm_sourceclient_file_cfg.py:37
edm::ActivityRegistry::watchPrePathEvent
void watchPrePathEvent(PrePathEvent::slot_type const &iSlot)
Definition: ActivityRegistry.h:470
ProfilerService::endEvent
void endEvent()
Definition: ProfilerService.cc:127
ProfilerService::preSourceI
void preSourceI(edm::StreamID)
Definition: ProfilerService.h:63
ProfilerService::m_allPaths
bool m_allPaths
Definition: ProfilerService.h:90
ProfilerService::dumpStat
void dumpStat() const
dump profiling information
Definition: ProfilerService.cc:99
muonDTDigis_cfi.pset
pset
Definition: muonDTDigis_cfi.py:27