@/*description: { This script generates the mplementation of the \textit{profiling module}. Each function scanned for the profiling has both a counter and a chronograph assigned. The chronograph holds the total time spent in the function. The display of result is the simplest that may exist: functions are listed with the number of calls and the total time (\samp{RawProfiling::displayResults()}). The file to generate is \samp{"RawProfiling.cpp"} and will be put in \samp{RAW_PROFILING_DIR}. } */ @#include #include #ifdef WIN32 # include "windows.h" # include "winbase.h" #else # include #endif #include "RawProfiling.h" namespace RawProfiling { unsigned long Chronograph::getTimeInMillis() { if (active_) { stop(); start(); } return (unsigned long) (elapsed_ / freqInMillis_); } int64 Chronograph::now() { #ifdef WIN32 LARGE_INTEGER value; QueryPerformanceCounter(&value); return (int64)value.QuadPart; #else struct timeb tb; ftime(&tb); return (int64)tb.time * 1000 + (int64)tb.millitm; #endif } int64 Chronograph::freq() { #ifdef WIN32 LARGE_INTEGER freq; QueryPerformanceFrequency(&freq); return (int64)freq.QuadPart; #else return 1000; #endif } void RawProfiling::displayResults() { @ foreach i in this.listOfKeys { if i.class { @ std::cout << "@i.class@::@i.name@ (" << @i@_counter << ", " << @i@_chronograph.getTimeInMillis() << "ms)" << std::endl; @ } else { @ std::cout << "@i.name@ (" << @i@_counter << ", " << @i@_chronograph.getTimeInMillis() << "ms)" << std::endl; @ } } @ } bool RawProfiling::writeToHTML(const std::string& sFilename) { std::ofstream HTMLFile(sFilename.c_str(), std::ios::out | std::ios::binary); if (HTMLFile.fail()) return false; HTMLFile << "" << std::endl; HTMLFile << "\t" << std::endl; HTMLFile << "\t\t

Profiling results

" << std::endl; HTMLFile << "\t\t" << std::endl; HTMLFile << "\t\t\t" << std::endl; HTMLFile << "\t\t\t\t" << std::endl; HTMLFile << "\t\t\t\t" << std::endl; HTMLFile << "\t\t\t\t" << std::endl; HTMLFile << "\t\t\t" << std::endl; @ foreach i in this.listOfKeys { @ HTMLFile << "\t\t\t" << std::endl; @ if i.class { @ HTMLFile << "\t\t\t\t" << std::endl; @ } else { @ HTMLFile << "\t\t\t\t" << std::endl; @ } @ HTMLFile << "\t\t\t\t" << std::endl; HTMLFile << "\t\t\t\t" << std::endl; HTMLFile << "\t\t\t" << std::endl; @ } @ HTMLFile << "\t\t
FunctionOccurrencesTime in ms
@i.class@::@i.name@@i.name@" << @i@_counter << "" << @i@_chronograph.getTimeInMillis() << "
" << std::endl; HTMLFile << "\t" << std::endl; HTMLFile << "" << std::endl; HTMLFile.close(); return true; } @ foreach i in this.listOfKeys { @ int RawProfiling::@i@_counter = 0; Chronograph RawProfiling::@i@_chronograph = Chronograph(); @ } @}