Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-10-08 02:27:20

0001 #include "FWCore/MessageService/test/MemoryTestClient_A.h"
0002 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0003 #include "FWCore/Framework/interface/MakerMacros.h"
0004 
0005 #include <iostream>
0006 #include <iomanip>
0007 #include <string>
0008 
0009 namespace edmtest {
0010 
0011   int MemoryTestClient_A::nevent = 0;
0012 
0013   MemoryTestClient_A::MemoryTestClient_A(edm::ParameterSet const& ps)
0014       : memoryPattern(), vsize(0), last_allocation(nullptr) {
0015     int pattern = ps.getUntrackedParameter<int>("pattern", 1);
0016     edm::LogWarning("memoryPattern") << "Memory Pattern selected: " << pattern;
0017     initializeMemoryPattern(pattern);
0018     usesResource("MemoryTestClient_A");
0019   }
0020 
0021   void MemoryTestClient_A::analyze(edm::Event const& /*unused*/
0022                                    ,
0023                                    edm::EventSetup const& /*unused*/
0024   ) {
0025     nevent++;
0026     double v = memoryPattern[nevent % memoryPattern.size()];
0027     edm::LogVerbatim("memoryUsage") << "Event " << nevent << " uses " << v << " Mbytes";
0028     if (v > vsize) {
0029       int leaksize = static_cast<int>((v - vsize) * 1048576);
0030       char* leak = new char[leaksize];
0031       edm::LogPrint("memoryIncrease") << "Event " << nevent << " increases vsize by " << v - vsize << " Mbytes";
0032       vsize = v;
0033       last_allocation = leak;
0034     }
0035     // DO NOT delete[] leak; the point is to increment vsize!
0036 
0037   }  // MessageLoggerClient::analyze()
0038 
0039   void MemoryTestClient_A::initializeMemoryPattern(int pattern) {
0040     switch (pattern) {
0041       case 1:  // A general pattern
0042         memoryPattern.push_back(2.1);
0043         memoryPattern.push_back(3.1);
0044         memoryPattern.push_back(4.1);
0045         memoryPattern.push_back(2.1);
0046         memoryPattern.push_back(1.7);
0047         memoryPattern.push_back(8.4);
0048         memoryPattern.push_back(3.4);
0049         memoryPattern.push_back(43.1);
0050         memoryPattern.push_back(17.1);
0051         memoryPattern.push_back(2.1);
0052         memoryPattern.push_back(47.9);
0053         memoryPattern.push_back(8.3);
0054         memoryPattern.push_back(56.3);
0055         memoryPattern.push_back(1.1);
0056         memoryPattern.push_back(19.1);
0057         memoryPattern.push_back(2.1);
0058         memoryPattern.push_back(22.0);
0059         memoryPattern.push_back(9.1);
0060         memoryPattern.push_back(2.1);
0061         memoryPattern.push_back(57.9);
0062         memoryPattern.push_back(2.1);
0063         memoryPattern.push_back(59.5);
0064         memoryPattern.push_back(4.1);
0065         memoryPattern.push_back(6.1);
0066         memoryPattern.push_back(61.5);
0067         memoryPattern.push_back(4.2);
0068         memoryPattern.push_back(6.3);
0069         break;
0070       case 2:  // Here, there is a swap with R1 insteadd of L1
0071         memoryPattern.push_back(2.1);
0072         memoryPattern.push_back(3.1);
0073         memoryPattern.push_back(4.1);
0074         memoryPattern.push_back(2.1);
0075         memoryPattern.push_back(1.7);
0076         memoryPattern.push_back(8.4);
0077         memoryPattern.push_back(3.4);
0078         memoryPattern.push_back(2.1);
0079         memoryPattern.push_back(1.7);
0080         memoryPattern.push_back(3.4);
0081         memoryPattern.push_back(43.1);
0082         memoryPattern.push_back(17.1);
0083         memoryPattern.push_back(2.1);
0084         memoryPattern.push_back(47.9);
0085         memoryPattern.push_back(8.3);
0086         memoryPattern.push_back(56.3);
0087         memoryPattern.push_back(1.1);
0088         memoryPattern.push_back(69.1);
0089         memoryPattern.push_back(2.1);
0090         memoryPattern.push_back(22.0);
0091         memoryPattern.push_back(9.1);
0092         memoryPattern.push_back(2.1);
0093         memoryPattern.push_back(117.9);
0094         memoryPattern.push_back(2.1);
0095         memoryPattern.push_back(119.5);
0096         memoryPattern.push_back(4.1);
0097         memoryPattern.push_back(6.1);
0098         memoryPattern.push_back(120.8);
0099         memoryPattern.push_back(19.5);
0100         break;
0101       case 3:  // Here, there are few increments
0102         memoryPattern.push_back(2.1);
0103         memoryPattern.push_back(3.1);
0104         memoryPattern.push_back(4.1);
0105         memoryPattern.push_back(2.1);
0106         memoryPattern.push_back(1.7);
0107         memoryPattern.push_back(8.4);
0108         memoryPattern.push_back(3.4);
0109         memoryPattern.push_back(2.1);
0110         memoryPattern.push_back(1.7);
0111         memoryPattern.push_back(3.4);
0112         memoryPattern.push_back(43.1);
0113         memoryPattern.push_back(17.1);
0114         break;
0115       default:
0116         memoryPattern.push_back(2.1);
0117         memoryPattern.push_back(3.1);
0118         memoryPattern.push_back(4.1);
0119         memoryPattern.push_back(2.1);
0120     }
0121   }
0122 
0123 }  // namespace edmtest
0124 
0125 using edmtest::MemoryTestClient_A;
0126 DEFINE_FWK_MODULE(MemoryTestClient_A);