[Compbench-devel] CompBenchmarks++/libcompbenchmarks/Plan Plan-Batch.cpp, NONE, 1.1 Plan-Batch.h, N
Brought to you by:
xfred
From: Frederic T. <xf...@us...> - 2007-05-17 14:32:22
|
Update of /cvsroot/compbench/CompBenchmarks++/libcompbenchmarks/Plan In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv9242 Added Files: Plan-Batch.cpp Plan-Batch.h Log Message: First import. --- NEW FILE: Plan-Batch.h --- /* ---------------------------------------------------------------------------- $Id: Plan-Batch.h,v 1.1 2007/05/17 14:32:16 xfred Exp $ This is free software. For details, see the GNU Public License in the COPYING file, or Look http://www.fsf.org ------------------------------------------------------------------------- */ #ifndef H_CBM_PLANBATCH #define H_CBM_PLANBATCH 1 #include <vector> #include <string> #ifdef SWIG /* !!! If in SWIG parser, we need to define CBM::Benchmark so that all methods get * correctly wrapped. Hope there's a better solution... */ %module CBM %{ #include <Benchmark/Benchmark.h> #include <Compiler/Compiler-OptionSet.h> %} #include <Benchmark/Benchmark.h> #include <Compiler/Compiler-OptionSet.h> #define CBM_BM CBM::Benchmark #define CBM_OS CBM::CompilerOptionSet #define CBM_OP CBM::CompilerOptions #else # define CBM_BM class Benchmark # define CBM_OS class CompilerOptionSet # define CBM_OP class CompilerOptions #endif namespace CBM { /** \brief Define contexts for running benchmark. * * Each PlanBatch (context) consists in set of compilers, option set and * benchmarks. */ class PlanBatch { private: std::string id; protected: std::vector<class Compiler *> compilers; /*!< Compilers */ std::vector<CBM_OS*> compilerOptions; /*!< Compiler optimisations' sets */ std::vector<class Benchmark *> benchmarks; /*!< Benchmarks */ /** Current iteration. * This value represents the index of the current benchmarking evaluation * !!! */ int iteration; virtual int isUnique(class Compiler *_compiler); virtual int isUnique(CBM_OS *_set); virtual int isUnique(class Benchmark *_benchmark); virtual void restoreBenchmarks(class XMLNode *_benchmarksNode); virtual void restoreCompilerOptionSet(class XMLNode *_cosNode); virtual void restoreCompilers(class XMLNode *_compilersNode); public: PlanBatch(std::string _id); virtual std::string Id(void); virtual void setId(std::string _id); virtual int add(class Compiler *_compiler); virtual int add(CBM_OS *_set); virtual CBM_OP *addOptions(CBM_OS *_set); virtual int add(class Benchmark *_benchmark); virtual int remove(class Compiler *_compiler); virtual int remove(CBM_OS *_set); virtual int remove(CBM_OS *_set, CBM_OP *_opt); virtual int remove(class Benchmark *_benchmark); virtual int compilerNumber(void); virtual int compilerOptionNumber(void); virtual int benchmarkNumber(void); virtual class Compiler* getCompiler(int _index); virtual CBM_OS *getCompilerOptions(int _index); virtual CBM_BM *getBenchmark(int _index); virtual int totalIterations(void); virtual int currentIteration(void); virtual class Compiler* currentCompiler(void); virtual CBM_OP *currentCompilerOptions(void); virtual class Benchmark *currentBenchmark(void); /** 0 means end. */ virtual int nextIteration(int simule = 0); virtual void stop(void); class XMLNode *XML(void); virtual void reset(void); virtual int store(void); virtual int restore(XMLNode *_planRootNode); virtual ~PlanBatch(); }; } #endif --- NEW FILE: Plan-Batch.cpp --- /* ---------------------------------------------------------------------------- $Id: Plan-Batch.cpp,v 1.1 2007/05/17 14:32:16 xfred Exp $ This is free software. For details, see the GNU Public License in the COPYING file, or Look http://www.fsf.org ------------------------------------------------------------------------- */ #include <Plan/Plan-Batch.h> #include <Compiler/Compiler.h> #include <Compiler/Compiler-Options.h> #include <Compiler/Compiler-OptionSet.h> #include <Benchmark/Benchmark.h> #include <System/System.h> #include <Base/Config.h> #include <Base/XML.h> #include <Base/Result.h> using namespace CBM; PlanBatch::PlanBatch(std::string _id) { iteration=0; id=_id; } std::string PlanBatch::Id(void) { return(id); } void PlanBatch::setId(std::string _id) { id=_id; } int PlanBatch::isUnique(CBM::Compiler *_compiler) { int i; int n = compilerNumber(); CBM::Compiler *C; for(i=0; i<n; i++) { C=getCompiler(i); if (C->Name() == _compiler->Name()) { return(0); } } return(1); } int PlanBatch::isUnique(CBM::CompilerOptionSet *_set) { int i; int n = compilerOptionNumber(); CBM::CompilerOptionSet *O; for(i=0; i<n; i++) { O=getCompilerOptions(i); if (O->Id() == _set->Id()) return(0); } return(1); } int PlanBatch::isUnique(CBM::Benchmark *_benchmark) { int i; int n = benchmarkNumber(); CBM::Benchmark *B; for(i=0; i<n; i++) { B=getBenchmark(i); if (B->Name() == _benchmark->Name()) return(0); } return(1); } void PlanBatch::restoreBenchmarks(CBM::XMLNode *_benchmarksNode) { int i; int n = _benchmarksNode->nodeNumber(); CBM::XMLNode *N; CBM::XMLAttribute *A; CBM::Benchmark *B; for(i=0; i<n; i++) { N=_benchmarksNode->getNode(i); if (N->Name() != "benchmark") continue; A=N->getAttribute("id"); if (!A) continue; B=cbmSystem->Benchmark(A->Value()); add(B); } } void PlanBatch::restoreCompilerOptionSet(CBM::XMLNode *_cosNode) { int i; int n = _cosNode->nodeNumber(); CBM::XMLNode *N; CBM::XMLAttribute *A; CBM::CompilerOptionSet *COS; for(i=0; i<n; i++) { N=_cosNode->getNode(i); if (N->Name() != "option-set") continue; A=N->getAttribute("id"); if (!A) continue; COS=new CBM::CompilerOptionSet(A->Value()); add(COS); } } void PlanBatch::restoreCompilers(CBM::XMLNode *_compilersNode) { int i; int n = _compilersNode->nodeNumber(); CBM::XMLNode *N; CBM::XMLAttribute *A; CBM::CompilerSelector *SC; CBM::Compiler *C; SC=new CBM::CompilerSelector(cbmSystem); for(i=0; i<n; i++) { N=_compilersNode->getNode(i); if (N->Name() != "compiler") continue; A=N->getAttribute("id"); if (!A) continue; C=SC->select((char*) A->Value().c_str()); add(C); } delete(SC); } int PlanBatch::add(CBM::Compiler *_compiler) { if ((!_compiler) || (!isUnique(_compiler))) { return(0); } compilers.push_back(_compiler); stop(); return(1); } int PlanBatch::add(CBM::CompilerOptionSet *_set) { if ((!_set) || (!isUnique(_set))) { return(0); } compilerOptions.push_back(_set); stop(); return(1); } CBM::CompilerOptions *PlanBatch::addOptions(CBM::CompilerOptionSet *_set) { return(_set->add()); } int PlanBatch::add(CBM::Benchmark *_benchmark) { if ((!_benchmark) || (!isUnique(_benchmark))) { return(0); } benchmarks.push_back(_benchmark); stop(); return(1); } int PlanBatch::remove(CBM::Compiler *_compiler) { int i; int n = compilerNumber(); CBM::Compiler *C = 0; std::vector<CBM::Compiler*> ncompilers; for(i=0; i<n; i++) { C=getCompiler(i); if (C!=_compiler) ncompilers.push_back(C); } compilers=ncompilers; stop(); return(1); } int PlanBatch::remove(CBM::CompilerOptionSet *_set) { int i; int n = compilerOptionNumber(); CBM::CompilerOptionSet *OS = 0; std::vector<CBM::CompilerOptionSet*> noptions; for(i=0; i<n; i++) { OS=getCompilerOptions(i); if (OS!=_set) noptions.push_back(OS); } compilerOptions=noptions; stop(); return(1); } int PlanBatch::remove(CBM::CompilerOptionSet *_set, CBM::CompilerOptions *_opt) { stop(); return(_set->remove(_opt)); } int PlanBatch::remove(CBM::Benchmark *_benchmark) { int i; int n = benchmarkNumber(); CBM::Benchmark *B = 0; std::vector<CBM::Benchmark*> nbenchmarks; for(i=0; i<n; i++) { B=getBenchmark(i); if (B!=_benchmark) nbenchmarks.push_back(B); } stop(); benchmarks=nbenchmarks; return(1); } int PlanBatch::compilerNumber(void) { return(compilers.size()); } int PlanBatch::compilerOptionNumber(void) { return(compilerOptions.size()); } int PlanBatch::benchmarkNumber(void) { return(benchmarks.size()); } CBM::Compiler *PlanBatch::getCompiler(int _index) { if (_index<compilerNumber()) return(compilers[_index]); else return(0); } CBM::CompilerOptionSet *PlanBatch::getCompilerOptions(int _index) { if (_index<compilerOptionNumber()) return(compilerOptions[_index]); else return(0); } CBM::Benchmark *PlanBatch::getBenchmark(int _index) { if (_index<benchmarkNumber()) return(benchmarks[_index]); else return(0); } int PlanBatch::totalIterations(void) { return(compilerNumber()*compilerOptionNumber()*benchmarkNumber()); } int PlanBatch::currentIteration(void) { return(iteration); } CBM::Compiler *PlanBatch::currentCompiler(void) { int compilerIndex = (iteration/(compilerOptionNumber()*benchmarkNumber()))%compilerNumber(); CBM::Compiler *C = getCompiler(compilerIndex); return(C); } CBM::CompilerOptions *PlanBatch::currentCompilerOptions(void) { int optionIndex = (iteration/benchmarkNumber())%compilerOptionNumber(); // std::string O = getCompilerOptions(optionIndex); // return(O); } CBM::Benchmark *PlanBatch::currentBenchmark(void) { int benchmarkIndex = iteration%benchmarkNumber(); CBM::Benchmark *B = getBenchmark(benchmarkIndex); return(B); } int PlanBatch::nextIteration(int simule) { CBM::Compiler *C; CBM::CompilerOptions *O; std::string o; CBM::Benchmark *B; CBM::Package *P; std::string bmValue; std::string buildTime; std::string executionTime; std::string tested; std::string testOk; CBM::Result *result; if (currentIteration()>=totalIterations()) { return(0); } C=currentCompiler(); O=currentCompilerOptions(); B=currentBenchmark(); P=B->Package(); if (!simule) { bmValue="0"; buildTime="0"; executionTime="0"; tested="0"; testOk="0"; P->Configure(C, O); if (P->Make()) { buildTime=P->buildTime(); if (P->hasTest()) { tested="1"; } if (P->Test()) { testOk="1"; } bmValue=B->Bench(); } result=new CBM::Result(bmValue, buildTime, executionTime, tested, testOk); delete(O); } iteration++; return(currentIteration()<totalIterations()); } CBM::XMLNode *PlanBatch::XML(void) { XMLNode *root = new CBM::XMLNode("plan-batch"); XMLNode *S = new CBM::XMLNode("selection"); XMLNode *SB = new CBM::XMLNode("benchmarks"); XMLNode *SC = new CBM::XMLNode("compilers"); XMLNode *OS = new CBM::XMLNode("option-set"); XMLNode *tmp; std::string str; int i; int n; root->add(S); root->addAttribute("id", Id()); S->add(SB); S->add(SC); /* comp set ID !!! */ S->add(OS); n=benchmarkNumber(); for(i=0; i<n; i++) { tmp=new CBM::XMLNode("benchmark"); tmp->addAttribute("id", getBenchmark(i)->Name()); SB->add(tmp); } n=compilerNumber(); for(i=0; i<n; i++) { tmp=new CBM::XMLNode("compiler"); tmp->addAttribute("id", getCompiler(i)->Binary()); SC->add(tmp); } n=compilerOptionNumber(); for(i=0; i<n; i++) { tmp=new CBM::XMLNode("set"); tmp->addAttribute("value", getCompilerOptions(i)->Id()); OS->add(tmp); } return(root); } void PlanBatch::stop(void) { iteration=0; } void PlanBatch::reset(void) { CBM::Compiler *C; CBM::Benchmark *B; CBM::CompilerOptionSet *O; while ( (C=getCompiler(0)) != 0 ) { delete(C); } while ( (B=getBenchmark(0)) != 0 ) { delete(B); } while ( (O=getCompilerOptions(0)) != 0) { remove(O); } } int PlanBatch::store(void) { XMLNode *root = XML(); cbmSystem->Config()->setPlan(root); return(cbmSystem->storeConfiguration()); } int PlanBatch::restore(XMLNode *_planRootNode) { XMLNode *S; XMLNode *R; XMLNode *BM; XMLNode *OS; XMLNode *OP; XMLNode *CI; XMLAttribute *A; if (!_planRootNode) return(0); reset(); A=_planRootNode->getAttribute("id"); if (A) setId(A->Value()); S=_planRootNode->getNode("selection"); if (!S) return(0); R=_planRootNode->getNode("run"); if (!R) return(0); BM=S->getNode("benchmarks"); if (!BM) return(0); restoreBenchmarks(BM); OS=S->getNode("option-sets"); if (!OS) return(0); restoreCompilerOptionSet(OS); /* CO=S->getNode("compilers"); if (!CO) return(0); restoreCompilers(CO); !!! */ OP=S->getNode("options"); if (!OP) return(0); CI=R->getNode("current-iteration"); if (!CI) return(0); A=CI->getAttribute("index"); if (!A) return(0); iteration=atoi(A->Value().c_str()); return(1); } PlanBatch::~PlanBatch() { } |