CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DataFormats/GeometrySurface/plugins/BlockWipedAllocatorService.cc

Go to the documentation of this file.
00001 #include "FWCore/PluginManager/interface/ModuleDef.h"
00002 #include "FWCore/ServiceRegistry/interface/ServiceMaker.h"
00003 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00004 
00005 #include "DataFormats/GeometrySurface/interface/BlockWipedAllocator.h"
00006 #include <iostream>
00007 
00008 
00009 #include "DataFormats/GeometrySurface/interface/ReferenceCounted.h"
00010 
00011 
00012 namespace {
00013   struct Dumper {
00014     void visit(BlockWipedAllocator const& alloc) const {
00015       BlockWipedAllocator::Stat sa1 = alloc.stat();
00016       std::cout << "Alloc for size " << sa1.typeSize
00017                 << ": " << sa1.blockSize
00018                 << ", " << sa1.currentOccupancy
00019                 << "/" << sa1.currentAvailable
00020                 << ", " << sa1.totalAvailable
00021                 << "/" << sa1.nBlocks
00022                 << ", " << sa1.alive
00023                 << std::endl;
00024     }
00025     
00026   };
00027   
00028 }
00029 
00032 class BlockWipedAllocatorService {
00033 private:
00034   bool m_useAlloc;
00035   bool m_dump;
00036   int  m_clearFreq;
00037 public:
00038   BlockWipedAllocatorService(const edm::ParameterSet & iConfig,
00039                              edm::ActivityRegistry & iAR ) {
00040     
00041     m_useAlloc = iConfig.getUntrackedParameter<bool>("usePoolAllocator",false);
00042     m_dump = iConfig.getUntrackedParameter<bool>("dumpEachModule",false);
00043     m_clearFreq = std::max(1,iConfig.getUntrackedParameter<int>("clearFrequency",20));
00044 
00045     if (m_useAlloc) BlockWipedPoolAllocated::usePool();
00046     iAR.watchPreSource(this,&BlockWipedAllocatorService::preSource);
00047     iAR.watchPreProcessEvent(this,&BlockWipedAllocatorService::preEventProcessing);
00048     iAR.watchPostEndJob(this,&BlockWipedAllocatorService::postEndJob);
00049     iAR.watchPreModule(this,&BlockWipedAllocatorService::preModule);
00050     iAR.watchPostModule(this,&BlockWipedAllocatorService::postModule);
00051   }
00052 
00053   // wipe the workspace before each event
00054   void preEventProcessing(const edm::EventID&, const edm::Timestamp&) { wiper();}
00055 
00056   // nope event-principal deleted in source
00057   void preSource() {
00058    // wiper();
00059   }
00060 
00061   void dump() {
00062     std::cout << "ReferenceCounted stat"<< std::endl;
00063     std::cout << "still alive/referenced " 
00064               << ReferenceCountedPoolAllocated::s_alive
00065               << "/" << ReferenceCountedPoolAllocated::s_referenced
00066               << std::endl;
00067 
00068     std::cout << "BlockAllocator stat"<< std::endl;
00069     std::cout << "still alive " << BlockWipedPoolAllocated::s_alive << std::endl;
00070     Dumper dumper;
00071     blockWipedPool().visit(dumper);
00072   }
00073 
00074 
00075   void wiper() {
00076     dump();
00077     blockWipedPool().wipe();
00078     // blockWipedPool().clear();  // try to crash
00079     {
00080        static int c=0;
00081        c++;
00082        if (m_clearFreq==c) {
00083          blockWipedPool().clear();
00084          c=0;
00085        }
00086     }
00087 
00088   }
00089  
00090   // wipe before each module (no, obj in event....)
00091   void preModule(const edm::ModuleDescription& desc){
00092     //     blockWipedPool().wipe();
00093   }
00094 
00095   void postModule(const edm::ModuleDescription& desc){
00096     if (m_dump) dump();
00097     }
00098 
00099   // final stat
00100   void postEndJob() {
00101     wiper();
00102   }
00103   
00104 };
00105 
00106 
00107 
00108 DEFINE_FWK_SERVICE(BlockWipedAllocatorService);