Skip to content

Commit 8f052f5

Browse files
authored
Merge pull request #49528 from Dr15Jones/esModuleCtrInModuleAllocFile
Add ESModule constructor info to ModuleAlloc file
2 parents c6273e0 + 7ae5a70 commit 8f052f5

File tree

7 files changed

+83
-24
lines changed

7 files changed

+83
-24
lines changed

PerfTools/AllocMonitor/plugins/moduleAlloc_setupFile.cc

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -364,23 +364,39 @@ namespace edm::service::moduleAlloc {
364364

365365
auto beginTime = TimingServiceBase::jobStartTime();
366366

367+
auto esModuleCtrDtrPtr = std::make_shared<std::vector<ModuleCtrDtr>>();
368+
auto& esModuleCtrDtr = *esModuleCtrDtrPtr;
367369
auto esModuleLabelsPtr = std::make_shared<std::vector<std::string>>();
368370
auto& esModuleLabels = *esModuleLabelsPtr;
369371
auto esModuleTypesPtr = std::make_shared<std::vector<std::string>>();
370372
auto& esModuleTypes = *esModuleTypesPtr;
371373
//acquire names for all the ED and ES modules
372-
iRegistry.watchPostESModuleRegistration([&esModuleLabels, &esModuleTypes](auto const& iDescription) {
373-
if (esModuleLabels.size() <= iDescription.id_ + 1) {
374-
esModuleLabels.resize(iDescription.id_ + 2);
375-
esModuleTypes.resize(iDescription.id_ + 2);
376-
}
377-
//NOTE: we want the id to start at 1 not 0
378-
if (not iDescription.label_.empty()) {
379-
esModuleLabels[iDescription.id_ + 1] = iDescription.label_;
380-
} else {
381-
esModuleLabels[iDescription.id_ + 1] = iDescription.type_;
374+
iRegistry.watchPreESModuleConstruction(
375+
[&esModuleLabels, &esModuleTypes, &esModuleCtrDtr, beginTime, iFilter](auto const& iDescription) {
376+
auto const t = duration_cast<duration_t>(now() - beginTime).count();
377+
auto const mid = iDescription.id_ + 1; //NOTE: we want the id to start at 1 not 0
378+
if (esModuleLabels.size() <= mid) {
379+
esModuleLabels.resize(mid + 1);
380+
esModuleTypes.resize(mid + 1);
381+
esModuleCtrDtr.resize(mid + 1);
382+
}
383+
if (not iDescription.label_.empty()) {
384+
esModuleLabels[mid] = iDescription.label_;
385+
} else {
386+
esModuleLabels[mid] = iDescription.type_;
387+
}
388+
esModuleTypes[mid] = iDescription.type_;
389+
esModuleCtrDtr.back().beginConstruction = t;
390+
iFilter->startOnThread(-1 * mid);
391+
});
392+
iRegistry.watchPostESModuleConstruction([&esModuleCtrDtr, beginTime, iFilter](auto const& md) {
393+
auto const t = duration_cast<duration_t>(now() - beginTime).count();
394+
auto const mid = md.id_ + 1;
395+
esModuleCtrDtr[mid].endConstruction = t;
396+
auto alloc = iFilter->stopOnThread(-1 * mid);
397+
if (alloc) {
398+
esModuleCtrDtr[mid].constructionAllocInfo = *alloc;
382399
}
383-
esModuleTypes[iDescription.id_ + 1] = iDescription.type_;
384400
});
385401
auto moduleCtrDtrPtr = std::make_shared<std::vector<ModuleCtrDtr>>();
386402
auto& moduleCtrDtr = *moduleCtrDtrPtr;
@@ -498,6 +514,7 @@ namespace edm::service::moduleAlloc {
498514
esModuleLabelsPtr,
499515
esModuleTypesPtr,
500516
moduleCtrDtrPtr,
517+
esModuleCtrDtrPtr,
501518
sourceCtrPtr,
502519
sourceTypePtr = std::move(sourceTypePtr),
503520
beginTime,
@@ -541,6 +558,35 @@ namespace edm::service::moduleAlloc {
541558
logFile->write(std::move(msg));
542559
return;
543560
}
561+
{
562+
std::vector<int> indices(esModuleCtrDtrPtr->size());
563+
std::iota(indices.begin(), indices.end(), 0);
564+
std::sort(indices.begin(), indices.end(), [&esModuleCtrDtrPtr](int l, int r) {
565+
return (*esModuleCtrDtrPtr)[l].beginConstruction < (*esModuleCtrDtrPtr)[r].beginConstruction;
566+
});
567+
for (auto index : indices) {
568+
if (not iFilter->keepModuleInfo(-1 * index)) {
569+
continue;
570+
}
571+
auto const& ctr = (*esModuleCtrDtrPtr)[index];
572+
if (ctr.beginConstruction != 0 and ctr.endConstruction != 0) {
573+
auto msg = assembleMessage<Step::preESModule>(
574+
static_cast<std::underlying_type_t<Phase>>(Phase::construction), 0, index, 0, 0, ctr.beginConstruction);
575+
logFile->write(std::move(msg));
576+
auto emsg = assembleAllocMessage<Step::postESModule>(
577+
ctr.constructionAllocInfo,
578+
static_cast<std::underlying_type_t<Phase>>(Phase::construction),
579+
0,
580+
index,
581+
0,
582+
0,
583+
ctr.endConstruction);
584+
logFile->write(std::move(emsg));
585+
++index;
586+
}
587+
}
588+
}
589+
544590
//NOTE: the source construction can run concurently with module construction so we need to properly
545591
// interleave its timing in with the modules
546592
auto srcBeginConstruction = sourceCtrPtr->beginConstruction;

PerfTools/AllocMonitor/scripts/edmModuleAllocMonitorAnalyze.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,10 @@ def __init__(self, payload, moduleInfos, esModuleInfos, recordNames):
834834
self.moduleID = int(payload[2])
835835
self.moduleInfo = esModuleInfos[self.moduleID]
836836
self.recordID = int(payload[3])
837-
self.recordName = recordNames[self.recordID]
837+
if not self.recordID:
838+
self.recordName = ''
839+
else:
840+
self.recordName = recordNames[self.recordID]
838841
self.callID = int(payload[4])
839842
self.time = int(payload[5])
840843
def baseIndentLevel(self):

PerfTools/AllocMonitor/test/runModuleAlloc.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ LOCAL_TEST_DIR=${SCRAM_TEST_PATH}
77
LD_PRELOAD="libPerfToolsAllocMonitorPreload.so" cmsRun ${LOCAL_TEST_DIR}/moduleAlloc_cfg.py || die 'Failure using moduleAlloc_cfg.py' $?
88

99
edmModuleAllocMonitorAnalyze.py -j moduleAlloc.log > moduleAlloc.json
10-
grep -A9 'cpptypes' moduleAlloc.json > cpptypes.txt
11-
diff cpptypes.txt ${LOCAL_TEST_DIR}/unittest_output/cpptypes.txt || die 'differences in edmModuleAllocMonitorAnalyzer.py output' $?
10+
grep -A9 'cpptypes' moduleAlloc.json | sort --ignore-leading-blanks | grep -v 'cpptypes' | grep -v '}' | sed 's/,//g' > cpptypes.txt
11+
diff --ignore-all-space cpptypes.txt ${LOCAL_TEST_DIR}/unittest_output/cpptypes.txt || die 'differences in edmModuleAllocMonitorAnalyzer.py output' $?
1212

1313
edmModuleAllocJsonToCircles.py moduleAlloc.json > moduleAlloc.circles.json
1414
grep '"\(record\|type\|label\)": ".*",' moduleAlloc.circles.json > circles.txt

PerfTools/AllocMonitor/test/unittest_output/allESModules.log

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
N 16 0 1 0 0
2+
n 16 0 1 0 0
3+
N 16 0 2 0 0
4+
n 16 0 2 0 0
15
N 0 0 2 1 0
26
n 0 0 2 1 0
37
N 0 0 1 1 0

PerfTools/AllocMonitor/test/unittest_output/circles.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
"label": "DoodadESSource",
22
"type": "DoodadESSource",
3+
"record": "",
4+
"label": "DoodadESSource",
5+
"type": "DoodadESSource",
36
"record": "GadgetRcd",
47
"label": "OtherThing",
58
"type": "OtherThingProducer",
@@ -9,6 +12,9 @@
912
"record": "",
1013
"label": "WhatsItESProducer",
1114
"type": "WhatsItESProducer",
15+
"record": "",
16+
"label": "WhatsItESProducer",
17+
"type": "WhatsItESProducer",
1218
"record": "GadgetRcd",
1319
"label": "get",
1420
"type": "WhatsItAnalyzer",
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
"cpptypes": {
2-
"source": "EmptySource",
3-
"out": "AsciiOutputModule",
4-
"get": "WhatsItAnalyzer",
5-
"OtherThing": "OtherThingProducer",
6-
"Thing": "ThingProducer",
7-
"thingProducer": "ThingProducer",
8-
"DoodadESSource": "DoodadESSource",
9-
"WhatsItESProducer": "WhatsItESProducer"
10-
}
1+
"DoodadESSource": "DoodadESSource"
2+
"OtherThing": "OtherThingProducer"
3+
"Thing": "ThingProducer"
4+
"WhatsItESProducer": "WhatsItESProducer"
5+
"get": "WhatsItAnalyzer"
6+
"out": "AsciiOutputModule"
7+
"source": "EmptySource"
8+
"thingProducer": "ThingProducer"

PerfTools/AllocMonitor/test/unittest_output/only_es_ESModules.log

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
N 16 0 1 0 0
2+
n 16 0 1 0 0
13
N 0 0 1 1 0
24
n 0 0 1 1 0
35
N 0 0 1 1 1

0 commit comments

Comments
 (0)