Skip to content

Commit d814816

Browse files
authored
Merge pull request #48286 from Dr15Jones/moduleTypeAllocMonitor
Add module types to ModuleAllocMonitor output
2 parents 31ab4d2 + 77eab58 commit d814816

File tree

4 files changed

+63
-8
lines changed

4 files changed

+63
-8
lines changed

PerfTools/AllocMonitor/plugins/moduleAlloc_setupFile.cc

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,33 +365,42 @@ namespace edm::service::moduleAlloc {
365365

366366
auto esModuleLabelsPtr = std::make_shared<std::vector<std::string>>();
367367
auto& esModuleLabels = *esModuleLabelsPtr;
368+
auto esModuleTypesPtr = std::make_shared<std::vector<std::string>>();
369+
auto& esModuleTypes = *esModuleTypesPtr;
368370
//acquire names for all the ED and ES modules
369-
iRegistry.watchPostESModuleRegistration([&esModuleLabels](auto const& iDescription) {
371+
iRegistry.watchPostESModuleRegistration([&esModuleLabels, &esModuleTypes](auto const& iDescription) {
370372
if (esModuleLabels.size() <= iDescription.id_ + 1) {
371373
esModuleLabels.resize(iDescription.id_ + 2);
374+
esModuleTypes.resize(iDescription.id_ + 2);
372375
}
373376
//NOTE: we want the id to start at 1 not 0
374377
if (not iDescription.label_.empty()) {
375378
esModuleLabels[iDescription.id_ + 1] = iDescription.label_;
376379
} else {
377380
esModuleLabels[iDescription.id_ + 1] = iDescription.type_;
378381
}
382+
esModuleTypes[iDescription.id_ + 1] = iDescription.type_;
379383
});
380384
auto moduleCtrDtrPtr = std::make_shared<std::vector<ModuleCtrDtr>>();
381385
auto& moduleCtrDtr = *moduleCtrDtrPtr;
382386
auto moduleLabelsPtr = std::make_shared<std::vector<std::string>>();
387+
auto moduleTypesPtr = std::make_shared<std::vector<std::string>>();
383388
auto& moduleLabels = *moduleLabelsPtr;
389+
auto& moduleTypes = *moduleTypesPtr;
384390
iRegistry.watchPreModuleConstruction(
385-
[&moduleLabels, &moduleCtrDtr, beginTime, iFilter](ModuleDescription const& md) {
391+
[&moduleLabels, &moduleTypes, &moduleCtrDtr, beginTime, iFilter](ModuleDescription const& md) {
386392
auto const t = duration_cast<duration_t>(now() - beginTime).count();
387393

388394
auto const mid = md.id();
389395
if (mid < moduleLabels.size()) {
390396
moduleLabels[mid] = md.moduleLabel();
397+
moduleTypes[mid] = md.moduleName();
391398
moduleCtrDtr[mid].beginConstruction = t;
392399
} else {
393400
moduleLabels.resize(mid + 1);
394401
moduleLabels.back() = md.moduleLabel();
402+
moduleTypes.resize(mid + 1);
403+
moduleTypes.back() = md.moduleName();
395404
moduleCtrDtr.resize(mid + 1);
396405
moduleCtrDtr.back().beginConstruction = t;
397406
}
@@ -481,7 +490,9 @@ namespace edm::service::moduleAlloc {
481490
iRegistry.watchPreBeginJob([logFile,
482491
iFilter,
483492
moduleLabelsPtr,
493+
moduleTypesPtr,
484494
esModuleLabelsPtr,
495+
esModuleTypesPtr,
485496
moduleCtrDtrPtr,
486497
sourceCtrPtr,
487498
beginTime,
@@ -490,15 +501,19 @@ namespace edm::service::moduleAlloc {
490501
*addDataInDtr = true;
491502
{
492503
std::ostringstream oss;
493-
moduleIdToLabel(oss, *moduleLabelsPtr, 'M', "EDModule ID", "Module label");
504+
moduleIdToLabelAndType(
505+
oss, *moduleLabelsPtr, *moduleTypesPtr, 'M', "EDModule ID", "Module label", "Module type");
494506
logFile->write(oss.str());
495507
moduleLabelsPtr.reset();
508+
moduleTypesPtr.reset();
496509
}
497510
{
498511
std::ostringstream oss;
499-
moduleIdToLabel(oss, *esModuleLabelsPtr, 'N', "ESModule ID", "ESModule label");
512+
moduleIdToLabelAndType(
513+
oss, *esModuleLabelsPtr, *esModuleTypesPtr, 'N', "ESModule ID", "ESModule label", "ESModule type");
500514
logFile->write(oss.str());
501515
esModuleLabelsPtr.reset();
516+
esModuleTypesPtr.reset();
502517
}
503518
{
504519
auto const moduleAllocStart = duration_cast<duration_t>(beginModuleAlloc - beginTime).count();

PerfTools/AllocMonitor/plugins/monitor_file_utilities.cc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "FWCore/Utilities/interface/OStreamColumn.h"
33

44
#include <vector>
5+
#include <cassert>
56

67
namespace {
78
std::string const space{" "};
@@ -29,4 +30,35 @@ namespace edm::moduleAlloc::monitor_file_utilities {
2930
}
3031
oStream << '\n';
3132
}
33+
34+
void moduleIdToLabelAndType(std::ostream& oStream,
35+
std::vector<std::string> const& iModuleLabels,
36+
std::vector<std::string> const& iModuleTypes,
37+
char moduleIdSymbol,
38+
std::string const& iIDHeader,
39+
std::string const& iLabelHeader,
40+
std::string const& iTypeHeader) {
41+
assert(iModuleLabels.size() == iModuleTypes.size());
42+
std::size_t const width{std::to_string(iModuleLabels.size()).size()};
43+
OStreamColumn col0{iIDHeader, width};
44+
auto itMax = std::max_element(iModuleLabels.begin(), iModuleLabels.end(), [](auto const& iL, auto const& iR) {
45+
return iL.size() < iR.size();
46+
});
47+
OStreamColumn labelCol{iLabelHeader, itMax->size()};
48+
std::string const& typeCol = iTypeHeader;
49+
50+
oStream << "\n# " << col0 << space << labelCol << space << typeCol << '\n';
51+
oStream << "# " << std::string(col0.width() + space.size() + labelCol.width() + space.size() + typeCol.size(), '-')
52+
<< '\n';
53+
54+
for (std::size_t i{}; i < iModuleLabels.size(); ++i) {
55+
auto const& label = iModuleLabels[i];
56+
auto const& type = iModuleTypes[i];
57+
if (not label.empty()) {
58+
oStream << '#' << moduleIdSymbol << ' ' << std::setw(width) << std::left << col0(i) << space
59+
<< std::setw(itMax->size()) << std::left << labelCol(label) << space << std::left << type << '\n';
60+
}
61+
}
62+
oStream << '\n';
63+
}
3264
} // namespace edm::moduleAlloc::monitor_file_utilities

PerfTools/AllocMonitor/plugins/monitor_file_utilities.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,13 @@ namespace edm::moduleAlloc::monitor_file_utilities {
3939
char moduleIdSymbol,
4040
std::string const& iIDHeader,
4141
std::string const& iLabelHeader);
42+
void moduleIdToLabelAndType(std::ostream&,
43+
std::vector<std::string> const& iModules,
44+
std::vector<std::string> const& iTypes,
45+
char moduleIdSymbol,
46+
std::string const& iIDHeader,
47+
std::string const& iLabelHeader,
48+
std::string const& iTypeHeader);
49+
4250
} // namespace edm::moduleAlloc::monitor_file_utilities
4351
#endif

PerfTools/AllocMonitor/scripts/edmModuleAllocMonitorAnalyze.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -961,11 +961,11 @@ def __init__(self,f, moduleCentric):
961961
if s > numStreamsFromSource:
962962
numStreamsFromSource = s
963963
if len(l) > 5 and l[0:2] == "#M":
964-
(id,name)=tuple(l[2:].split())
964+
(id,name,mType)=tuple(l[2:].split())
965965
moduleNames[int(id)] = name
966966
continue
967967
if len(l) > 5 and l[0:2] == "#N":
968-
(id,name)=tuple(l[2:].split())
968+
(id,name,mType)=tuple(l[2:].split())
969969
esModuleNames[int(id)] = name
970970
continue
971971
if len(l) > 5 and l[0:2] == "#R":
@@ -1315,8 +1315,8 @@ def incr(t):
13151315

13161316
self.tracerFile.extend([
13171317
'#R 1 Record',
1318-
'#M 1 Module',
1319-
'#N 1 ESModule',
1318+
'#M 1 Module ModuleType',
1319+
'#N 1 ESModule ESModuleType',
13201320
f'F {Phase.startTracing} 0 0 0 0 {incr(t)}',
13211321
f'S {Phase.construction} 0 {incr(t)}',
13221322
f's {Phase.construction} 0 {incr(t)} 1 1 10 0 10 10',

0 commit comments

Comments
 (0)