CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/FWCore/Services/plugins/ResourceEnforcer.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Services
00004 // Class  :     ResourceEnforcer
00005 // 
00006 // Implementation:
00007 //     [Notes on implementation]
00008 //
00009 // Original Author:  Chris Jones
00010 //         Created:  Sun May  6 12:16:49 CDT 2012
00011 // $Id: ResourceEnforcer.cc,v 1.1 2012/05/06 19:14:27 chrjones Exp $
00012 //
00013 
00014 // system include files
00015 
00016 // user include files
00017 #include "FWCore/Services/src/ProcInfoFetcher.h"
00018 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00019 #include "FWCore/ParameterSet/interface/ConfigurationDescriptions.h"
00020 #include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
00021 #include "FWCore/Utilities/interface/CPUTimer.h"
00022 #include "FWCore/ServiceRegistry/interface/ServiceMaker.h"
00023 
00024 
00025 namespace edm {
00026   class Event;
00027   class EventSetup;
00028   
00029   namespace service {
00030     class ResourceEnforcer {
00031     public:
00032       ResourceEnforcer(edm::ParameterSet const& iConfig, ActivityRegistry& iAR);
00033       
00034       void check();
00035       
00036       void postEventProcessing(Event const& e, EventSetup const&);
00037       
00038       static void fillDescriptions(edm::ConfigurationDescriptions & descriptions);
00039 
00040     private:
00041       ProcInfoFetcher m_fetcher;
00042       CPUTimer m_timer;
00043       
00044       double m_maxVSize;
00045       double m_maxRSS;
00046       double m_maxTime;
00047     };
00048   }
00049 }
00050 
00051 using namespace edm::service;
00052 //
00053 // constants, enums and typedefs
00054 //
00055 
00056 //
00057 // static data member definitions
00058 //
00059 
00060 //
00061 // constructors and destructor
00062 //
00063 ResourceEnforcer::ResourceEnforcer( edm::ParameterSet const& iConfig,ActivityRegistry& iReg):
00064 m_maxVSize(iConfig.getUntrackedParameter<double>("maxVSize",0)*1000.), //convert to MB
00065 m_maxRSS(iConfig.getUntrackedParameter<double>("maxRSS",0)*1000.),
00066 m_maxTime(iConfig.getUntrackedParameter<double>("maxTime",0)*60.*60.) //convert from hours to seconds
00067 
00068 {
00069   iReg.watchPostProcessEvent(this, &ResourceEnforcer::postEventProcessing);
00070   m_timer.start();
00071 
00072 }
00073 
00074 //
00075 // member functions
00076 //
00077 
00078 //
00079 // const member functions
00080 //
00081 
00082 void 
00083 ResourceEnforcer::postEventProcessing(Event const& e, EventSetup const&) {
00084   this->check();
00085 }
00086 
00087 
00088 void
00089 ResourceEnforcer::check()
00090 {
00091   ProcInfo pi =m_fetcher.fetch();
00092   
00093   if(0!=m_maxVSize && m_maxVSize< pi.vsize) {
00094     throw edm::Exception(errors::ExceededResourceVSize)<<"Exceeded maximum allowed VSize of "<<m_maxVSize/1000.<<" GB (VSize is "<<pi.vsize/1000.<<")";
00095   }
00096 
00097   if(0!=m_maxRSS && m_maxRSS< pi.rss) {
00098     throw edm::Exception(errors::ExceededResourceRSS)<<"Exceeded maximum allowed RSS of "<<m_maxRSS/1000.<<" GB (VSize is "<<pi.rss/1000.<<")";
00099   }
00100 
00101   if(0!=m_maxTime && m_maxTime < m_timer.realTime()) {
00102     throw edm::Exception(errors::ExceededResourceTime)<<"Exceeded maximum allowed time of "<<m_maxTime/60./60.<<" hours";
00103   }
00104 }
00105 
00106 
00107 //
00108 // static member functions
00109 //
00110 
00111 void ResourceEnforcer::fillDescriptions(ConfigurationDescriptions& descriptions) {
00112   ParameterSetDescription desc;
00113   desc.addUntracked<double>("maxVSize", 0.)->setComment("Maximum allowed VSize for the job in GB. Ignored if set to 0.");
00114   desc.addUntracked<double>("maxRSS", 0.)->setComment("Maximum allowd RSS for the job in GB. Ignored if set to 0.");
00115   desc.addUntracked<double>("maxTime", 0.)->setComment("Maximum allowd wallclock time for the job in hours. Ignored if set to 0.");
00116   descriptions.add("ResourceEnforcer", desc);
00117 }
00118 
00119 DEFINE_FWK_SERVICE(ResourceEnforcer);