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 public:
00036 BlockWipedAllocatorService(const edm::ParameterSet & iConfig,
00037 edm::ActivityRegistry & iAR ) {
00038
00039 m_useAlloc = iConfig.getUntrackedParameter<bool>("usePoolAllocator",false);
00040 if (m_useAlloc) BlockWipedPoolAllocated::usePool();
00041 iAR.watchPreSource(this,&BlockWipedAllocatorService::preSource);
00042 iAR.watchPreProcessEvent(this,&BlockWipedAllocatorService::preEventProcessing);
00043 iAR.watchPostEndJob(this,&BlockWipedAllocatorService::postEndJob);
00044 iAR.watchPreModule(this,&BlockWipedAllocatorService::preModule);
00045 iAR.watchPostModule(this,&BlockWipedAllocatorService::postModule);
00046 }
00047
00048
00049 void preEventProcessing(const edm::EventID&, const edm::Timestamp&) { wiper();}
00050
00051
00052 void preSource() {
00053
00054 }
00055
00056 void dump() {
00057 std::cout << "ReferenceCounted stat"<< std::endl;
00058 std::cout << "still alive/referenced "
00059 << ReferenceCountedPoolAllocated::s_alive
00060 << "/" << ReferenceCountedPoolAllocated::s_referenced
00061 << std::endl;
00062
00063 std::cout << "BlockAllocator stat"<< std::endl;
00064 std::cout << "still alive " << BlockWipedPoolAllocated::s_alive << std::endl;
00065 Dumper dumper;
00066 blockWipedPool().visit(dumper);
00067 }
00068
00069
00070 void wiper() {
00071 dump();
00072 blockWipedPool().wipe();
00073 blockWipedPool().clear();
00074 {
00075 static int c=0;
00076 if (20==c) {
00077 blockWipedPool().clear();
00078 c=0;
00079 }
00080 c++;
00081 }
00082
00083 }
00084
00085
00086 void preModule(const edm::ModuleDescription& desc){
00087
00088 }
00089
00090 void postModule(const edm::ModuleDescription& desc){
00091 dump();
00092 }
00093
00094
00095 void postEndJob() {
00096 wiper();
00097 }
00098
00099 };
00100
00101
00102
00103 DEFINE_FWK_SERVICE(BlockWipedAllocatorService);