CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_4/src/PerfTools/Callgrind/plugins/CallgrindAnalyzer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    Profiler
00004 // Class:      Profiler
00005 // 
00013 //
00014 // Original Author:  Andrea Rizzi
00015 //         Created:  Thu Jan 18 10:34:18 CET 2007
00016 // $Id: CallgrindAnalyzer.cc,v 1.6 2012/01/31 13:56:04 eulisse Exp $
00017 //
00018 //
00019 
00020 
00021 // system include files
00022 #include <memory>
00023 
00024 // user include files
00025 #include "FWCore/Framework/interface/Frameworkfwd.h"
00026 #include "FWCore/Framework/interface/EDAnalyzer.h"
00027 
00028 #include "FWCore/Framework/interface/Event.h"
00029 #include "FWCore/Framework/interface/MakerMacros.h"
00030 
00031 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00032 
00033 
00034 #include "valgrind/callgrind.h"
00035 //
00036 // class declaration
00037 //
00038 #include <iostream>
00039 using namespace std;
00040 class Profiler : public edm::EDAnalyzer {
00041 public:
00042   explicit Profiler(const edm::ParameterSet&);
00043   ~Profiler();
00044 
00045 
00046 private:
00047   virtual void beginJob() ;
00048   virtual void analyze(const edm::Event&, const edm::EventSetup&);
00049   virtual void endJob() ;
00050   
00051   // ----------member data ---------------------------
00052       int m_firstEvent;
00053       int m_lastEvent;
00054       int m_action;
00055       int m_evtCount;
00056 };
00057 
00058 //
00059 // constants, enums and typedefs
00060 //
00061 
00062 //
00063 // static data member definitions
00064 //
00065 
00066 //
00067 // constructors and destructor
00068 //
00069 Profiler::Profiler(const edm::ParameterSet& parameters)
00070 {
00071    //now do what ever initialization is needed
00072    m_firstEvent         = parameters.getParameter<int>("firstEvent");
00073    m_lastEvent          = parameters.getParameter<int>("lastEvent");
00074    m_action             = parameters.getParameter<int>("action");
00075    m_evtCount=0;
00076 
00077 }
00078 
00079 
00080 Profiler::~Profiler()
00081 {
00082  
00083    // do anything here that needs to be done at desctruction time
00084    // (e.g. close files, deallocate resources etc.)
00085 
00086 }
00087 
00088 
00089 //
00090 // member functions
00091 //
00092 
00093 // ------------ method called to for each event  ------------
00094 #pragma GCC diagnostic push
00095 #pragma GCC diagnostic ignored "-Wunused-but-set-variable"
00096 void
00097 Profiler::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00098 {
00099 m_evtCount++;
00100 if(m_evtCount >= m_firstEvent && (m_evtCount <= m_lastEvent || m_lastEvent == -1))
00101  {
00102   switch (m_action)
00103   {
00104    case 0: 
00105      CALLGRIND_STOP_INSTRUMENTATION;
00106      cout << "Stop Instr" << endl; 
00107      break;
00108    case 1:
00109      CALLGRIND_START_INSTRUMENTATION;
00110      CALLGRIND_DUMP_STATS;
00111      cout << "Start Instr" << endl; 
00112      break;
00113    case 2:
00114      CALLGRIND_DUMP_STATS;
00115      cout << "Dump stat" << endl; 
00116      break;
00117  
00118   }
00119 
00120  }
00121 }
00122 #pragma GCC diagnostic pop
00123 
00124 
00125 // ------------ method called once each job just before starting event loop  ------------
00126 void 
00127 Profiler::beginJob()
00128 {
00129 }
00130 
00131 // ------------ method called once each job just after ending the event loop  ------------
00132 void 
00133 Profiler::endJob() {
00134 }
00135 
00136 //define this as a plug-in
00137 DEFINE_FWK_MODULE(Profiler);