Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:32:20

0001 // -*- C++ -*-
0002 //
0003 // Package:    Profiler
0004 // Class:      Profiler
0005 //
0006 /**\class Profiler Profiler.cc PerfTools/Callgrind/plugins/Profiler.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Andrea Rizzi
0015 //         Created:  Thu Jan 18 10:34:18 CET 2007
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 
0022 // user include files
0023 #include "FWCore/Framework/interface/Frameworkfwd.h"
0024 #include "FWCore/Framework/interface/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 // class declaration
0034 //
0035 #include <iostream>
0036 using namespace std;
0037 class Profiler : public edm::EDAnalyzer {
0038 public:
0039   explicit Profiler(const edm::ParameterSet&);
0040   ~Profiler() override;
0041 
0042 private:
0043   void beginJob() override;
0044   void analyze(const edm::Event&, const edm::EventSetup&) override;
0045   void endJob() override;
0046 
0047   // ----------member data ---------------------------
0048   int m_firstEvent;
0049   int m_lastEvent;
0050   int m_action;
0051   int m_evtCount;
0052 };
0053 
0054 //
0055 // constants, enums and typedefs
0056 //
0057 
0058 //
0059 // static data member definitions
0060 //
0061 
0062 //
0063 // constructors and destructor
0064 //
0065 Profiler::Profiler(const edm::ParameterSet& parameters) {
0066   //now do what ever initialization is needed
0067   m_firstEvent = parameters.getParameter<int>("firstEvent");
0068   m_lastEvent = parameters.getParameter<int>("lastEvent");
0069   m_action = parameters.getParameter<int>("action");
0070   m_evtCount = 0;
0071 }
0072 
0073 Profiler::~Profiler() {
0074   // do anything here that needs to be done at desctruction time
0075   // (e.g. close files, deallocate resources etc.)
0076 }
0077 
0078 //
0079 // member functions
0080 //
0081 
0082 // ------------ method called to for each event  ------------
0083 #pragma GCC diagnostic push
0084 #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
0085 void Profiler::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0086   m_evtCount++;
0087   if (m_evtCount >= m_firstEvent && (m_evtCount <= m_lastEvent || m_lastEvent == -1)) {
0088     switch (m_action) {
0089       case 0:
0090         CALLGRIND_STOP_INSTRUMENTATION;
0091         cout << "Stop Instr" << endl;
0092         break;
0093       case 1:
0094         CALLGRIND_START_INSTRUMENTATION;
0095         CALLGRIND_DUMP_STATS;
0096         cout << "Start Instr" << endl;
0097         break;
0098       case 2:
0099         CALLGRIND_DUMP_STATS;
0100         cout << "Dump stat" << endl;
0101         break;
0102     }
0103   }
0104 }
0105 #pragma GCC diagnostic pop
0106 
0107 // ------------ method called once each job just before starting event loop  ------------
0108 void Profiler::beginJob() {}
0109 
0110 // ------------ method called once each job just after ending the event loop  ------------
0111 void Profiler::endJob() {}
0112 
0113 //define this as a plug-in
0114 DEFINE_FWK_MODULE(Profiler);