39 std::unique_ptr<std::atomic<std::chrono::high_resolution_clock::rep>[]>
m_timeSums;
42 std::chrono::high_resolution_clock::time_point
m_time;
72 : m_modulesToExclude(iConfig.getUntrackedParameter<
std::
vector<
std::
string>>(
"modulesToExclude")),
75 m_padding(iConfig.getUntrackedParameter<unsigned
int>(
"padding")),
77 m_startedTiming(
false),
78 m_excludeSource(iConfig.getUntrackedParameter<
bool>(
"excludeSource")),
79 m_trackGlobalBeginRun(iConfig.getUntrackedParameter<
bool>(
"trackGlobalBeginRun")) {
80 if (not m_modulesToExclude.empty()) {
82 for (
auto const&
name : m_modulesToExclude) {
84 m_excludedModuleIds.push_back(iMod.
id());
89 iReg.watchPreModuleEvent([
this](StreamContext
const&, ModuleCallingContext
const& iContext) {
90 if (trackModule(iContext)) {
94 iReg.watchPostModuleEvent([
this](StreamContext
const&, ModuleCallingContext
const& iContext) {
95 if (trackModule(iContext)) {
100 iReg.watchPreModuleEventDelayedGet([
this](StreamContext
const&, ModuleCallingContext
const& iContext) {
101 if (trackModule(iContext)) {
107 iReg.watchPostModuleEventDelayedGet([
this](StreamContext
const&, ModuleCallingContext
const& iContext) {
108 if (trackModule(iContext)) {
117 iReg.watchPreModuleEvent([
this](StreamContext
const&, ModuleCallingContext
const&) {
start(); });
118 iReg.watchPostModuleEvent([
this](StreamContext
const&, ModuleCallingContext
const&) { stop(); });
120 iReg.watchPreModuleEventDelayedGet([
this](StreamContext
const&, ModuleCallingContext
const& iContext) {
125 iReg.watchPostModuleEventDelayedGet([
this](StreamContext
const&, ModuleCallingContext
const& iContext) {
130 if (m_trackGlobalBeginRun) {
131 iReg.watchPreModuleGlobalBeginRun([
this](GlobalContext
const&, ModuleCallingContext
const&) {
132 if (not m_startedTiming) {
134 m_startedTiming =
true;
139 iReg.watchPostModuleGlobalBeginRun([
this](GlobalContext
const&, ModuleCallingContext
const&) { stop(); });
145 m_timeSums.reset(
new std::atomic<std::chrono::high_resolution_clock::rep>[m_nTimeSums]);
146 for (
unsigned int i = 0;
i < m_nTimeSums; ++
i) {
151 iReg.watchPreSourceEvent([
this](StreamID) {
152 if (not m_startedTiming) {
154 m_startedTiming =
true;
156 if (not m_excludeSource) {
160 if (not m_excludeSource) {
161 iReg.watchPostSourceEvent([
this](StreamID) { stop(); });
167 std::cout <<
"Fraction of time running n Modules simultaneously" << std::endl;
195 std::chrono::high_resolution_clock::time_point oldTime;
196 bool expected =
false;
197 unsigned int nModules;
198 while (not
m_spinLock.compare_exchange_strong(expected,
true, std::memory_order_acq_rel)) {
208 m_spinLock.store(
false, std::memory_order_release);
211 auto diff = newTime - oldTime;
212 for (
unsigned int i = 0;
i < nModules; ++
i) {
219 std::chrono::high_resolution_clock::time_point oldTime;
220 bool expected =
false;
221 unsigned int nModules;
222 while (not
m_spinLock.compare_exchange_weak(expected,
true, std::memory_order_acq_rel)) {
229 m_spinLock.store(
false, std::memory_order_release);
232 auto diff = newTime - oldTime;
233 for (
unsigned int i = 0;
i <= nModules; ++
i) {
256 desc.addUntracked<std::vector<std::string>>(
"modulesToExclude", std::vector<std::string>{})
257 ->setComment(
"Module labels to exclude from the timing measurements");
258 desc.addUntracked<
bool>(
"excludeSource",
false)->setComment(
"Exclude the time the source is running");
259 desc.addUntracked<
unsigned int>(
"padding", 0)
261 "[Expert use only] Extra possible concurrent modules beyond thread count.\n Only useful in debugging "
262 "possible framework scheduling problems.");
263 desc.addUntracked<
bool>(
"trackGlobalBeginRun",
false)
264 ->setComment(
"Check for concurrent modules during global begin run");
265 descriptions.
add(
"ConcurrentModuleTimer",
desc);