CMS 3D CMS Logo

ProfilerService.cc
Go to the documentation of this file.
2 
6 
7 #include <algorithm>
8 #include <limits>
9 
10 #include "valgrind/callgrind.h"
11 
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(
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 }
41 
43 
44 #pragma GCC diagnostic push
45 #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
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 }
61 
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 }
70 
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 }
79 
81  if (m_active == 0)
82  return false;
83  CALLGRIND_STOP_INSTRUMENTATION;
84  m_paused = true;
85  return true;
86 }
87 
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 }
98 
99 void ProfilerService::dumpStat() const { CALLGRIND_DUMP_STATS; }
100 #pragma GCC diagnostic pop
101 
103  ++m_evtCount;
105 }
106 
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 }
118 
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 }
126 
129  // force, a nested instrumentation may fail to close in presence of filters
131 }
132 
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 }
146 
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 }
void watchPreEvent(PreEvent::slot_type const &iSlot)
std::vector< std::string > m_excludedPaths
bool resumeInstrumentation()
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 beginPath(std::string const &path)
void endPath(std::string const &path)
void watchPostEvent(PostEvent::slot_type const &iSlot)
std::string m_activePath
void watchPostPathEvent(PostPathEvent::slot_type const &iSlot)
~ProfilerService()
Destructor.
void watchPostSourceEvent(PostSourceEvent::slot_type const &iSlot)
void dumpStat() const
dump profiling information
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
bool stopInstrumentation()
stop instrumentation if not active anymore; true if stopped now
void preSourceI(edm::StreamID)
bool doEvent() const
true if the current event has to be instrumented
bool forceStopInstrumentation()
forced stop instrumentation independenly of activity status; true if stopped now
bool pauseInstrumentation()
bool startInstrumentation()
start instrumentation if not active. true if started now
void endEventI(edm::StreamContext const &stream)
void beginPathI(edm::StreamContext const &stream, edm::PathContext const &path)
ProfilerService(edm::ParameterSet const &pset, edm::ActivityRegistry &activity)
Standard Service Constructor.
void beginEventI(edm::StreamContext const &stream)