39 std::unique_ptr<std::atomic<std::chrono::high_resolution_clock::rep>[]>
m_timeSums;
42 std::chrono::high_resolution_clock::time_point
m_time;
69 : m_modulesToExclude(iConfig.getUntrackedParameter<
std::vector<
std::
string>>(
"modulesToExclude")),
73 m_startedTiming(
false),
74 m_excludeSource(iConfig.getUntrackedParameter<
bool>(
"excludeSource")) {
75 if (not m_modulesToExclude.empty()) {
77 for (
auto const&
name : m_modulesToExclude) {
79 m_excludedModuleIds.push_back(iMod.
id());
84 iReg.watchPreModuleEvent([
this](StreamContext
const&, ModuleCallingContext
const& iContext) {
85 if (trackModule(iContext)) {
89 iReg.watchPostModuleEvent([
this](StreamContext
const&, ModuleCallingContext
const& iContext) {
90 if (trackModule(iContext)) {
95 iReg.watchPreModuleEventDelayedGet([
this](StreamContext
const&, ModuleCallingContext
const& iContext) {
96 if (trackModule(iContext)) {
102 iReg.watchPostModuleEventDelayedGet([
this](StreamContext
const&, ModuleCallingContext
const& iContext) {
103 if (trackModule(iContext)) {
112 iReg.watchPreModuleEvent([
this](StreamContext
const&, ModuleCallingContext
const&) {
start(); });
113 iReg.watchPostModuleEvent([
this](StreamContext
const&, ModuleCallingContext
const&) { stop(); });
115 iReg.watchPreModuleEventDelayedGet([
this](StreamContext
const&, ModuleCallingContext
const& iContext) {
120 iReg.watchPostModuleEventDelayedGet([
this](StreamContext
const&, ModuleCallingContext
const& iContext) {
129 m_timeSums.reset(
new std::atomic<std::chrono::high_resolution_clock::rep>[m_nTimeSums]);
130 for (
unsigned int i = 0;
i < m_nTimeSums; ++
i) {
135 iReg.watchPreSourceEvent([
this](StreamID) {
136 if (not m_startedTiming) {
138 m_startedTiming =
true;
140 if (not m_excludeSource) {
144 if (not m_excludeSource) {
145 iReg.watchPostSourceEvent([
this](StreamID) { stop(); });
150 std::cout <<
"Fraction of time running n Modules simultaneously" << std::endl;
178 std::chrono::high_resolution_clock::time_point oldTime;
179 bool expected =
false;
180 unsigned int nModules;
181 while (not
m_spinLock.compare_exchange_strong(expected,
true, std::memory_order_acq_rel)) {
188 m_spinLock.store(
false, std::memory_order_release);
191 auto diff = newTime - oldTime;
192 for (
unsigned int i = 0;
i < nModules; ++
i) {
199 std::chrono::high_resolution_clock::time_point oldTime;
200 bool expected =
false;
201 unsigned int nModules;
202 while (not
m_spinLock.compare_exchange_weak(expected,
true, std::memory_order_acq_rel)) {
209 m_spinLock.store(
false, std::memory_order_release);
212 auto diff = newTime - oldTime;
213 for (
unsigned int i = 0;
i <= nModules; ++
i) {
236 desc.
addUntracked<std::vector<std::string>>(
"modulesToExclude", std::vector<std::string>{})
237 ->setComment(
"Module labels to exclude from the timing measurements");
238 desc.
addUntracked<
bool>(
"excludeSource",
false)->setComment(
"Exclude the time the source is running");
239 descriptions.
add(
"ConcurrentModuleTimer", desc);