41 std::unique_ptr<std::atomic<std::chrono::high_resolution_clock::rep>[]>
m_timeSums;
44 std::chrono::high_resolution_clock::time_point
m_time;
57 using namespace edm::service;
74 : m_modulesToExclude(iConfig.getUntrackedParameter<std::
vector<std::
string>>(
"modulesToExclude")),
77 m_padding(iConfig.getUntrackedParameter<unsigned int>(
"padding")),
79 m_startedTiming(
false),
80 m_excludeSource(
iConfig.getUntrackedParameter<
bool>(
"excludeSource")),
81 m_trackGlobalBeginRun(
iConfig.getUntrackedParameter<
bool>(
"trackGlobalBeginRun")) {
82 if (not m_modulesToExclude.empty()) {
84 for (
auto const&
name : m_modulesToExclude) {
86 m_excludedModuleIds.push_back(iMod.
id());
91 iReg.watchPreModuleDestruction([
this](ModuleDescription
const& iMod) {
92 auto found =
std::find(m_excludedModuleIds.begin(), m_excludedModuleIds.end(), iMod.id());
93 if (
found != m_excludedModuleIds.end()) {
94 m_excludedModuleIds.erase(
found);
97 iReg.watchPreModuleEvent([
this](StreamContext
const&, ModuleCallingContext
const& iContext) {
98 if (trackModule(iContext)) {
102 iReg.watchPostModuleEvent([
this](StreamContext
const&, ModuleCallingContext
const& iContext) {
103 if (trackModule(iContext)) {
108 iReg.watchPreModuleEventDelayedGet([
this](StreamContext
const&, ModuleCallingContext
const& iContext) {
109 if (trackModule(iContext)) {
115 iReg.watchPostModuleEventDelayedGet([
this](StreamContext
const&, ModuleCallingContext
const& iContext) {
116 if (trackModule(iContext)) {
125 iReg.watchPreModuleEvent([
this](StreamContext
const&, ModuleCallingContext
const&) {
start(); });
126 iReg.watchPostModuleEvent([
this](StreamContext
const&, ModuleCallingContext
const&) { stop(); });
128 iReg.watchPreModuleEventDelayedGet([
this](StreamContext
const&, ModuleCallingContext
const& iContext) {
133 iReg.watchPostModuleEventDelayedGet([
this](StreamContext
const&, ModuleCallingContext
const& iContext) {
138 if (m_trackGlobalBeginRun) {
139 iReg.watchPreModuleGlobalBeginRun([
this](GlobalContext
const&, ModuleCallingContext
const&) {
140 if (not m_startedTiming) {
142 m_startedTiming =
true;
147 iReg.watchPostModuleGlobalBeginRun([
this](GlobalContext
const&, ModuleCallingContext
const&) { stop(); });
153 m_timeSums = std::make_unique<std::atomic<std::chrono::high_resolution_clock::rep>[]>(m_nTimeSums);
154 for (
unsigned int i = 0;
i < m_nTimeSums; ++
i) {
159 iReg.watchPreSourceEvent([
this](StreamID) {
160 if (not m_startedTiming) {
162 m_startedTiming =
true;
164 if (not m_excludeSource) {
168 if (not m_excludeSource) {
169 iReg.watchPostSourceEvent([
this](StreamID) { stop(); });
175 std::cout <<
"Fraction of time running n Modules simultaneously" << std::endl;
203 std::chrono::high_resolution_clock::time_point oldTime;
204 bool expected =
false;
205 unsigned int nModules;
206 while (not
m_spinLock.compare_exchange_strong(expected,
true, std::memory_order_acq_rel)) {
216 m_spinLock.store(
false, std::memory_order_release);
219 auto diff = newTime - oldTime;
220 for (
unsigned int i = 0;
i < nModules; ++
i) {
227 std::chrono::high_resolution_clock::time_point oldTime;
228 bool expected =
false;
229 unsigned int nModules;
230 while (not
m_spinLock.compare_exchange_weak(expected,
true, std::memory_order_acq_rel)) {
237 m_spinLock.store(
false, std::memory_order_release);
240 auto diff = newTime - oldTime;
241 for (
unsigned int i = 0;
i <= nModules; ++
i) {
264 desc.
addUntracked<std::vector<std::string>>(
"modulesToExclude", std::vector<std::string>{})
265 ->setComment(
"Module labels to exclude from the timing measurements");
266 desc.
addUntracked<
bool>(
"excludeSource",
false)->setComment(
"Exclude the time the source is running");
269 "[Expert use only] Extra possible concurrent modules beyond thread count.\n Only useful in debugging "
270 "possible framework scheduling problems.");
272 ->setComment(
"Check for concurrent modules during global begin run");
273 descriptions.
add(
"ConcurrentModuleTimer", desc);
unsigned int maxNumberOfThreads() const
const bool m_trackGlobalBeginRun
ParameterDescriptionBase * addUntracked(U const &iLabel, T const &value)
const unsigned int m_padding
ConcurrentModuleTimer(edm::ParameterSet const &iConfig, edm::ActivityRegistry &iAR)
const bool m_excludeSource
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
std::string const & moduleLabel() const
std::vector< std::string > m_modulesToExclude
std::chrono::high_resolution_clock::time_point m_time
ModuleDescription const * moduleDescription() const
#define DEFINE_FWK_SERVICE(type)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< unsigned int > m_excludedModuleIds
std::atomic< bool > m_spinLock
bool trackModule(ModuleCallingContext const &iContext) const
std::unique_ptr< std::atomic< std::chrono::high_resolution_clock::rep >[]> m_timeSums
unsigned int m_maxNModules