#include #include #include using namespace CLHEP; using namespace RAT; Profiler::Profiler( const std::string name, const std::string detail ) : fTotalTime( 0.0 ), fCalls( 0 ) { fName = name; fDetail = detail; } void Profiler::Stop() { fStopwatch.Stop(); fTotalTime += fStopwatch.RealTime(); fTotalCPUTime += fStopwatch.CpuTime(); fCalls += 1; } void Profiler::OutputTiming() const { info << dformat( "%20s:%11s:%8d call%s, ", fName.c_str(), fDetail.c_str(), fCalls, fCalls == 1 ? "" : "s" ); if( fCalls > 0 ) { const double timePerCall = fTotalTime / static_cast( fCalls ); const double cpuTimePerCall = fTotalCPUTime / static_cast( fCalls ); if( timePerCall > 1e-5 ) info << dformat( "%7.5fs/call, ", timePerCall ); else info << "< 1e-5 s/call, "; if( cpuTimePerCall > 1e-5 ) debug << dformat( "%7.5f cpu-sec/call, ", cpuTimePerCall ); else debug << "<1e-5 cpu-sec/call, "; if( fTotalTime > 0.1 ) info << dformat( "%4.1fs total.\n", fTotalTime ); else info << dformat( "<0.1s total.\n" ); } else info << "NaN s/call, NaN s total.\n"; }