Thread: [Compbench-devel] CompBenchmarks++/libcompbenchmarks/Plan Plan.cpp, 1.3, 1.4 Plan.h, 1.3, 1.4
Brought to you by:
xfred
From: Frederic T. <xf...@us...> - 2007-01-25 22:08:50
|
Update of /cvsroot/compbench/CompBenchmarks++/libcompbenchmarks/Plan In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv21077 Modified Files: Plan.cpp Plan.h Log Message: methods to restore all parameters according to an XML node (hierarchy). Index: Plan.h =================================================================== RCS file: /cvsroot/compbench/CompBenchmarks++/libcompbenchmarks/Plan/Plan.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Plan.h 25 Jan 2007 21:33:48 -0000 1.3 --- Plan.h 25 Jan 2007 22:08:46 -0000 1.4 *************** *** 13,22 **** namespace CBM { class Plan { protected: ! std::vector<class Compiler *> compilers; ! std::vector<std::string> compilerOptions; ! std::vector<class Benchmark *> benchmarks; int iteration; --- 13,29 ---- namespace CBM { + /** \brief Configure and run benchmarks within specified contexts. + * This class manage sets of benchmarks, compiler options and compilers + * to evaluate performances in a convenient way. */ class Plan { protected: ! std::vector<class Compiler *> compilers; /*!< Compilers */ ! std::vector<std::string> compilerOptions; /*!< Compilers' optimisations */ ! std::vector<class Benchmark *> benchmarks; /*!< Benchmarks */ + /** Current iteration. + * This value represents the index of the current benchmarking evaluation + * !!! + */ int iteration; *************** *** 24,27 **** --- 31,39 ---- virtual int isUnique(std::string _options); virtual int isUnique(class Benchmark *_benchmark); + + virtual void restoreBenchmarks(class XMLNode *_benchmarksNode); + virtual void restoreCompilers(class XMLNode *_compilersNode); + virtual void restoreOptions(class XMLNode *_optionsNode); + public: Plan(); *************** *** 53,58 **** --- 65,75 ---- 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 ~Plan(); Index: Plan.cpp =================================================================== RCS file: /cvsroot/compbench/CompBenchmarks++/libcompbenchmarks/Plan/Plan.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Plan.cpp 25 Jan 2007 21:33:48 -0000 1.3 --- Plan.cpp 25 Jan 2007 22:08:46 -0000 1.4 *************** *** 66,69 **** --- 66,130 ---- } + void Plan::restoreBenchmarks(CBM::XMLNode *_benchmarksNode) + { + int i; + int n = _benchmarksNode->nodeNumber(); + CBM::XMLNode *N; + CBM::XMLAttribute *A; + + for(i=0; i<n; i++) { + N=_benchmarksNode->getNode(i); + if (N->Name() != "benchmark") + continue; + A=N->getAttribute("id"); + if (!A) + continue; + add(cbmSystem->Benchmark(A->Value())); + } + } + + void Plan::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); + } + + void Plan::restoreOptions(CBM::XMLNode *_optionsNode) + { + int i; + int n = _optionsNode->nodeNumber(); + CBM::XMLNode *N; + CBM::XMLAttribute *A; + + for(i=0; i<n; i++) { + N=_optionsNode->getNode(i); + if (N->Name() != "option") + continue; + A=N->getAttribute("value"); + if (!A) + continue; + add(A->Value()); + } + } + + int Plan::add(CBM::Compiler *_compiler) { *************** *** 73,76 **** --- 134,138 ---- compilers.push_back(_compiler); + stop(); return(1); } *************** *** 83,86 **** --- 145,149 ---- compilerOptions.push_back(_compilerOptions); + stop(); return(1); } *************** *** 93,96 **** --- 156,160 ---- benchmarks.push_back(_benchmark); + stop(); return(1); } *************** *** 109,113 **** } compilers=ncompilers; ! return(1); } --- 173,177 ---- } compilers=ncompilers; ! stop(); return(1); } *************** *** 126,130 **** } compilerOptions=noptions; ! return(1); } --- 190,194 ---- } compilerOptions=noptions; ! stop(); return(1); } *************** *** 142,146 **** nbenchmarks.push_back(B); } ! benchmarks=nbenchmarks; return(1); --- 206,210 ---- nbenchmarks.push_back(B); } ! stop(); benchmarks=nbenchmarks; return(1); *************** *** 165,179 **** CBM::Compiler *Plan::getCompiler(int _index) { ! return(compilers[_index]); } std::string Plan::getCompilerOptions(int _index) { ! return(compilerOptions[_index]); } CBM::Benchmark *Plan::getBenchmark(int _index) { ! return(benchmarks[_index]); } --- 229,252 ---- CBM::Compiler *Plan::getCompiler(int _index) { ! if (_index<compilerNumber()) ! return(compilers[_index]); ! else ! return(0); } std::string Plan::getCompilerOptions(int _index) { ! if (_index<compilerOptionNumber()) ! return(compilerOptions[_index]); ! else ! return(""); } CBM::Benchmark *Plan::getBenchmark(int _index) { ! if (_index<benchmarkNumber()) ! return(benchmarks[_index]); ! else ! return(0); } *************** *** 296,299 **** --- 369,398 ---- } + void Plan::stop(void) + { + iteration=0; + } + + void Plan::reset(void) + { + CBM::Compiler *C; + CBM::Benchmark *B; + std::string O; + + while ( (C=getCompiler(0)) != 0 ) { + remove(C); + delete(C); + } + + while ( (B=getBenchmark(0)) != 0 ) { + remove(B); + delete(B); + } + + while ( (O=getCompilerOptions(0)) != "") { + remove(O); + } + } + int Plan::store(void) { *************** *** 304,307 **** --- 403,454 ---- } + int Plan::restore(XMLNode *_planRootNode) + { + XMLNode *S; + XMLNode *R; + XMLNode *BM; + XMLNode *CO; + XMLNode *OP; + XMLNode *CI; + XMLAttribute *A; + + reset(); + + 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); + + CO=S->getNode("compilers"); + if (!CO) + return(0); + restoreCompilers(CO); + + OP=S->getNode("options"); + if (!OP) + return(0); + restoreOptions(OP); + + 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); + } + Plan::~Plan() { |