CMS 3D CMS Logo

CallgrindAnalyzer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Profiler
4 // Class: Profiler
5 //
13 //
14 // Original Author: Andrea Rizzi
15 // Created: Thu Jan 18 10:34:18 CET 2007
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
25 
28 
30 
31 #include "valgrind/callgrind.h"
32 //
33 // class declaration
34 //
35 #include <iostream>
36 using namespace std;
37 namespace callgrind {
38  class Profiler : public edm::one::EDAnalyzer<> {
39  public:
40  explicit Profiler(const edm::ParameterSet&);
41  ~Profiler() override;
42 
43  private:
44  void beginJob() override;
45  void analyze(const edm::Event&, const edm::EventSetup&) override;
46  void endJob() override;
47 
48  // ----------member data ---------------------------
51  int m_action;
53  };
54 } // namespace callgrind
55 using namespace callgrind;
56 //
57 // constants, enums and typedefs
58 //
59 
60 //
61 // static data member definitions
62 //
63 
64 //
65 // constructors and destructor
66 //
67 Profiler::Profiler(const edm::ParameterSet& parameters) {
68  //now do what ever initialization is needed
69  m_firstEvent = parameters.getParameter<int>("firstEvent");
70  m_lastEvent = parameters.getParameter<int>("lastEvent");
71  m_action = parameters.getParameter<int>("action");
72  m_evtCount = 0;
73 }
74 
75 Profiler::~Profiler() {
76  // do anything here that needs to be done at desctruction time
77  // (e.g. close files, deallocate resources etc.)
78 }
79 
80 //
81 // member functions
82 //
83 
84 // ------------ method called to for each event ------------
85 #pragma GCC diagnostic push
86 #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
87 void Profiler::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
88  m_evtCount++;
89  if (m_evtCount >= m_firstEvent && (m_evtCount <= m_lastEvent || m_lastEvent == -1)) {
90  switch (m_action) {
91  case 0:
92  CALLGRIND_STOP_INSTRUMENTATION;
93  cout << "Stop Instr" << endl;
94  break;
95  case 1:
96  CALLGRIND_START_INSTRUMENTATION;
97  CALLGRIND_DUMP_STATS;
98  cout << "Start Instr" << endl;
99  break;
100  case 2:
101  CALLGRIND_DUMP_STATS;
102  cout << "Dump stat" << endl;
103  break;
104  }
105  }
106 }
107 #pragma GCC diagnostic pop
108 
109 // ------------ method called once each job just before starting event loop ------------
111 
112 // ------------ method called once each job just after ending the event loop ------------
113 void Profiler::endJob() {}
114 
115 //define this as a plug-in
example_stream void analyze(const edm::Event &, const edm::EventSetup &) override
void beginJob()
Definition: Breakpoints.cc:14
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16