evaluator that throw an exception if a maximum CPU user time has been reached, for POSIX systems
This commit is contained in:
parent
efb22a6eda
commit
5697f6d699
3 changed files with 66 additions and 1 deletions
5
eo/NEWS
5
eo/NEWS
|
|
@ -1,4 +1,7 @@
|
|||
* release 1.1 (not yet released)
|
||||
* current
|
||||
- evaluators that throw an exception if a maximum time has en reached (wallclock and CPU user time for POSIX systems), independently of the number of generations
|
||||
|
||||
* release 1.1
|
||||
- provide cmake build system, remove the old autotools one
|
||||
- package generation system
|
||||
- GCC 4.3 compatibility
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@
|
|||
#include <eoEvalFuncPtr.h>
|
||||
#include <eoEvalCounterThrowException.h>
|
||||
#include <eoEvalTimeThrowException.h>
|
||||
#include <eoEvalUserTimeThrowException.h>
|
||||
|
||||
// Continuators - all include eoContinue.h
|
||||
#include <eoCombinedContinue.h>
|
||||
|
|
|
|||
61
eo/src/eoEvalUserTimeThrowException.h
Normal file
61
eo/src/eoEvalUserTimeThrowException.h
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
(c) Thales group, 2010
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation;
|
||||
version 2 of the License.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
Contact: http://eodev.sourceforge.net
|
||||
|
||||
Authors:
|
||||
Johann Dréo <johann.dreo@thalesgroup.com>
|
||||
*/
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
|
||||
#include <eoExceptions.h>
|
||||
|
||||
/** Check at each evaluation if a given CPU user time contract has been reached.
|
||||
*
|
||||
* Throw an eoMaxTimeException if the given max time has been reached.
|
||||
* Usefull if you want to end the search independently of generations.
|
||||
* This class uses (almost-)POSIX headers.
|
||||
* It uses a computation of the user time used on the CPU. For a wallclock time measure, see eoEvalTimeThrowException
|
||||
*
|
||||
* @ingroup Evaluation
|
||||
*/
|
||||
template< class EOT >
|
||||
class eoEvalUserTimeThrowException : public eoEvalFuncCounter< EOT >
|
||||
{
|
||||
public:
|
||||
eoEvalUserTimeThrowException( eoEvalFunc<EOT> & func, long max ) : _max(max), eoEvalFuncCounter<EOT>( func, "CPU-user") {}
|
||||
|
||||
virtual void operator() ( EOT & eo )
|
||||
{
|
||||
if( eo.invalid() ) {
|
||||
|
||||
getrusage(RUSAGE_SELF,&_usage);
|
||||
|
||||
if( _usage.ru_utime.tv_sec >= _max ) {
|
||||
throw eoMaxTimeException( _usage.ru_utime.tv_sec );
|
||||
} else {
|
||||
func(eo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
long _max;
|
||||
struct rusage _usage;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue