Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:23: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/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 // class declaration
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     // ----------member data ---------------------------
0049     int m_firstEvent;
0050     int m_lastEvent;
0051     int m_action;
0052     int m_evtCount;
0053   };
0054 }  // namespace callgrind
0055 using namespace callgrind;
0056 //
0057 // constants, enums and typedefs
0058 //
0059 
0060 //
0061 // static data member definitions
0062 //
0063 
0064 //
0065 // constructors and destructor
0066 //
0067 Profiler::Profiler(const edm::ParameterSet& parameters) {
0068   //now do what ever initialization is needed
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   // do anything here that needs to be done at desctruction time
0077   // (e.g. close files, deallocate resources etc.)
0078 }
0079 
0080 //
0081 // member functions
0082 //
0083 
0084 // ------------ method called to for each event  ------------
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 // ------------ method called once each job just before starting event loop  ------------
0110 void Profiler::beginJob() {}
0111 
0112 // ------------ method called once each job just after ending the event loop  ------------
0113 void Profiler::endJob() {}
0114 
0115 //define this as a plug-in
0116 DEFINE_FWK_MODULE(Profiler);