CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/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.4 2009/12/14 22:23:27 wmtan 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 void
00095 Profiler::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00096 {
00097 m_evtCount++;
00098 if(m_evtCount >= m_firstEvent && (m_evtCount <= m_lastEvent || m_lastEvent == -1))
00099  {
00100   switch (m_action)
00101   {
00102    case 0: 
00103      CALLGRIND_STOP_INSTRUMENTATION;
00104      cout << "Stop Instr" << endl; 
00105      break;
00106    case 1:
00107      CALLGRIND_START_INSTRUMENTATION;
00108      CALLGRIND_DUMP_STATS;
00109      cout << "Start Instr" << endl; 
00110      break;
00111    case 2:
00112      CALLGRIND_DUMP_STATS;
00113      cout << "Dump stat" << endl; 
00114      break;
00115  
00116   }
00117 
00118  }
00119 }
00120 
00121 
00122 // ------------ method called once each job just before starting event loop  ------------
00123 void 
00124 Profiler::beginJob()
00125 {
00126 }
00127 
00128 // ------------ method called once each job just after ending the event loop  ------------
00129 void 
00130 Profiler::endJob() {
00131 }
00132 
00133 //define this as a plug-in
00134 DEFINE_FWK_MODULE(Profiler);