File indexing completed on 2023-03-17 11:15:37
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include <memory>
0021
0022
0023 #include "FWCore/Framework/interface/Frameworkfwd.h"
0024 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0025
0026 #include "FWCore/Framework/interface/Event.h"
0027 #include "FWCore/Framework/interface/MakerMacros.h"
0028
0029 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0030
0031 #include "valgrind/callgrind.h"
0032
0033
0034
0035 #include <iostream>
0036 using namespace std;
0037 namespace callgrind {
0038 class Profiler : public edm::one::EDAnalyzer<> {
0039 public:
0040 explicit Profiler(const edm::ParameterSet&);
0041 ~Profiler() override;
0042
0043 private:
0044 void beginJob() override;
0045 void analyze(const edm::Event&, const edm::EventSetup&) override;
0046 void endJob() override;
0047
0048
0049 int m_firstEvent;
0050 int m_lastEvent;
0051 int m_action;
0052 int m_evtCount;
0053 };
0054 }
0055 using namespace callgrind;
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067 Profiler::Profiler(const edm::ParameterSet& parameters) {
0068
0069 m_firstEvent = parameters.getParameter<int>("firstEvent");
0070 m_lastEvent = parameters.getParameter<int>("lastEvent");
0071 m_action = parameters.getParameter<int>("action");
0072 m_evtCount = 0;
0073 }
0074
0075 Profiler::~Profiler() {
0076
0077
0078 }
0079
0080
0081
0082
0083
0084
0085 #pragma GCC diagnostic push
0086 #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
0087 void Profiler::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0088 m_evtCount++;
0089 if (m_evtCount >= m_firstEvent && (m_evtCount <= m_lastEvent || m_lastEvent == -1)) {
0090 switch (m_action) {
0091 case 0:
0092 CALLGRIND_STOP_INSTRUMENTATION;
0093 cout << "Stop Instr" << endl;
0094 break;
0095 case 1:
0096 CALLGRIND_START_INSTRUMENTATION;
0097 CALLGRIND_DUMP_STATS;
0098 cout << "Start Instr" << endl;
0099 break;
0100 case 2:
0101 CALLGRIND_DUMP_STATS;
0102 cout << "Dump stat" << endl;
0103 break;
0104 }
0105 }
0106 }
0107 #pragma GCC diagnostic pop
0108
0109
0110 void Profiler::beginJob() {}
0111
0112
0113 void Profiler::endJob() {}
0114
0115
0116 DEFINE_FWK_MODULE(Profiler);