41 std::unique_ptr<std::atomic<std::chrono::steady_clock::rep>[]>
m_timeSums;
44 std::chrono::steady_clock::time_point
m_time;
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::steady_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::steady_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::steady_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");
267 desc.addUntracked<
unsigned int>(
"padding", 0)
269 "[Expert use only] Extra possible concurrent modules beyond thread count.\n Only useful in debugging " 270 "possible framework scheduling problems.");
271 desc.addUntracked<
bool>(
"trackGlobalBeginRun",
false)
272 ->setComment(
"Check for concurrent modules during global begin run");
273 descriptions.
add(
"ConcurrentModuleTimer",
desc);
ModuleDescription const * moduleDescription() const
const bool m_trackGlobalBeginRun
bool trackModule(ModuleCallingContext const &iContext) const
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::vector< std::string > m_modulesToExclude
std::chrono::steady_clock::time_point m_time
#define DEFINE_FWK_SERVICE(type)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
std::vector< unsigned int > m_excludedModuleIds
unsigned int maxNumberOfThreads() const
std::atomic< bool > m_spinLock
std::unique_ptr< std::atomic< std::chrono::steady_clock::rep >[]> m_timeSums
std::string const & moduleLabel() const
unsigned int m_maxNModules