Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

# Tools/Xabsl2/GT/GTXabsl2Profiler/GTXabsl2Profiler.cpp

Go to the documentation of this file.

    00001 #include "GTXabsl2Profiler.h"
    00002
    00003 GTXabsl2Profiler::GTXabsl2Profiler(SolutionRequest::xabsl2EngineID id, const unsigned long* frameNumber)
    00004 :profilerCollectMode(GTXabsl2Profiler::dontCollectProfiles),
    00005 profilerWriteMode(GTXabsl2Profiler::dontWriteProfiles),frameNumber(frameNumber)
    00006 {
    00007   logFileName = std::string("Xabsl2/")+std::string(SolutionRequest::getXabsl2EngineFileID(id))+std::string(".log");
    00008 }
    00009
    00010 GTXabsl2Profiler::GTXabsl2Profiler()
    00011 :profilerCollectMode(GTXabsl2Profiler::dontCollectProfiles),
    00012 profilerWriteMode(GTXabsl2Profiler::dontWriteProfiles), frameNumber(NULL), logFileName(""){}
    00013
    00014
    00015 void GTXabsl2Profiler::init(Xabsl2Engine& pEngine){
    00016   OutTextFile out(logFileName.c_str(), false);
    00017   log.init(pEngine);
    00018   out << log;
    00019 }
    00020
    00021 void GTXabsl2Profiler::registerSymbols(Xabsl2Engine& engine){
    00022
    00023   engine.registerEnumeratedOutputSymbol("profiler-collect-mode",(int*)&profilerCollectMode);
    00024   engine.registerEnumeratedOutputSymbolEnumElement("profiler-collect-mode","profiler-collect-mode.collect-profiles", GTXabsl2Profiler::collectProfiles);
    00025   engine.registerEnumeratedOutputSymbolEnumElement("profiler-collect-mode","profiler-collect-mode.dont-collect-profiles", GTXabsl2Profiler::dontCollectProfiles);
    00026
    00027   engine.registerEnumeratedOutputSymbol("profiler-write-mode",(int*)&profilerWriteMode);
    00028   engine.registerEnumeratedOutputSymbolEnumElement("profiler-write-mode","profiler-write-mode.write-profiles", GTXabsl2Profiler::writeProfiles  );
    00029   engine.registerEnumeratedOutputSymbolEnumElement("profiler-write-mode","profiler-write-mode.write-complete-profiles", GTXabsl2Profiler::writeCompleteProfiles);
    00030   engine.registerEnumeratedOutputSymbolEnumElement("profiler-write-mode","profiler-write-mode.dont-write-profiles", GTXabsl2Profiler::dontWriteProfiles);
    00031
    00032 }
    00033
    00034
    00035 void GTXabsl2Profiler::recordLog(Xabsl2Engine& pEngine){
    00036   GTXabsl2LogEntry logEntry;
    00037   logEntry.frameNumber = *frameNumber;
    00038
    00039   const Xabsl2Option* option;
    00040
    00041   // number of active options is 0 when basic behaviors are tested separately
    00042   option = pEngine.getRootOption();
    00043   while (option!=0)
    00044   {
    00045     if(log.nameTable.exists(option->n, option->activeState->n))
    00046     {
    00047       std::vector<double> params;
    00048
    00049       for(int i = 0; i<option->parameters.getSize();++i)
    00050       {
    00051         params.push_back(option->parameters[i]);
    00052       }
    00053       logEntry.activeOptions.push_back(GTXabsl2ActiveOption(log.nameTable.getOptionPosition(option->n), log.nameTable.getStatePosition(option->n, option->activeState->n), params));
    00054     }
    00055     option = option->activeState->subsequentOption;
    00056   }
    00057   int i;
    00058   for(i = 0; i  < pEngine.numberOfDecimalInputSymbols(); ++i)
    00059     logEntry.inputSymbolValues.push_back(pEngine.getDecimalInputSymbol(i)->getValue());
    00060   for(i = 0; i  < pEngine.numberOfBooleanInputSymbols(); ++i)
    00061     logEntry.inputSymbolValues.push_back(pEngine.getBooleanInputSymbol(i)->getValue());
    00062   for(i = 0; i  < pEngine.numberOfEnumeratedInputSymbols(); ++i)
    00063     logEntry.inputSymbolValues.push_back(pEngine.getEnumeratedInputSymbol(i)->getValue());
    00064
    00065   if(!log.size() || log.back().activeOptions != logEntry.activeOptions){
    00066     log.push_back(logEntry);
    00067   }
    00068 }
    00069
    00070 void GTXabsl2Profiler::writeLogEntriesToFileAndRemove(int number){
    00071
    00072   OutTextFile out(logFileName.c_str(), true);
    00073   // debugLogToStream(out);
    00074   for(int i = 0; i < number && log.size(); ++i)
    00075   {
    00076     out << log[0];
    00077     log.pop_front();
    00078   }
    00079
    00080 }
    00081 void GTXabsl2Profiler::writeCompleteLogToFileAndClear(){
    00082   OutTextFile out(logFileName.c_str(), true);
    00083
    00084   // debugLogToStream(out);
    00085   for(unsigned int i = 0;i < log.size(); ++i)
    00086   {
    00087     out << log[i];
    00088   }
    00089   log.clear();
    00090
    00091 }
    00092