Go to the documentation of this file.00001 #include "Utilities/Timing/interface/TimingReport.h"
00002 #include <algorithm>
00003 #include <iostream>
00004 #include <ostream>
00005 #include <iomanip>
00006 #include <map>
00007
00008 double TimingReport::Item::realsec() const {
00009 return std::max(0.,stopwatch.lap().seconds()-counter*PentiumTimer::bias());
00010 }
00011
00012 double TimingReport::Item::realticks() const {
00013 return std::max(0.,stopwatch.lap().ticks()-counter*PentiumTimer::bias(false));
00014 }
00015
00016 double TimingReport::Item::cpusec() const {
00017 return std::max(0.,cpuwatch.lap().seconds()-counter*(LinuxCPUTimer::bias()+PentiumTimer::bias()));
00018 }
00019
00020
00021 TimingReport * TimingReport::current() {
00022 static TimingReport * currentTimingReport=0;
00023
00024 if (currentTimingReport==0) currentTimingReport = new TimingReport();
00025 return currentTimingReport;
00026
00027 }
00028
00029 TimingReport::TimingReport() : on(true), inTicks_(false) {
00030
00031
00032
00033 }
00034
00035 void TimingReport::switchOn(bool ion) {
00036 if (on==ion) return;
00037 on = ion;
00038
00039
00040 SMAP::iterator p = registry.begin();
00041 SMAP::iterator e = registry.end();
00042 for (;p!=e; ++p) (*p).second.switchOn(on);
00043 }
00044
00045 TimingReport::~TimingReport() {
00046 if (!on) return;
00047 dump(std::cout);
00048 }
00049
00050 void TimingReport::dump(std::ostream & ico, bool active) {
00052 typedef std::map<std::string, Item *, std::less<std::string> > LMAP;
00053 LMAP lreg;
00054 {
00055 SMAP::iterator p = registry.begin();
00056 SMAP::iterator e = registry.end();
00057 while (p!=e) {
00058 if ( (*p).second.on && (!active||(*p).second.active()) )
00059 lreg[(*p).first] = &(*p).second;
00060 ++p;
00061 }
00062 }
00063
00064 std::ostream co(ico.rdbuf());
00065 size_t namew = 20;
00066 co << "\n";
00067 if (active) co << "Active ";
00068 co << "Timing Report (in "
00069 << (inTicks() ? "ticks" : "seconds") << ")\n" << std::endl;
00070 LMAP::iterator p = lreg.begin();
00071 LMAP::iterator e = lreg.end();
00072 while (p!=e) { namew = std::max(namew,(*p).first.size()); ++p;}
00073 p = lreg.begin();
00074 while (p!=e) {
00075 co.setf(std::ios::left,std::ios::adjustfield);
00076 if (inTicks())
00077 co << std::setiosflags(std::ios::showpoint)
00078 << std::setprecision(3);
00079 else
00080 co << std::setiosflags(std::ios::showpoint | std::ios::fixed)
00081 << std::setprecision(3);
00082
00083 co << std::setw(namew) << (*p).first.c_str() << " ";
00084 co.setf(std::ios::right,std::ios::adjustfield);
00085 co << std::setw(10) << (*(*p).second).counter << " ";
00086 co << std::setw(10)
00087 << (inTicks() ? (*(*p).second).realticks()
00088 : (*(*p).second).realsec() ) << " (real)";
00089 #ifdef __linux__
00090 co << " " << std::setw(10)
00091 << (inTicks() ? 1./PentiumTimer::ticksInSec() : 1.)*(*(*p).second).cpusec() << " (cpu)";
00092 #endif
00093 co << std::endl;
00094 ++p;
00095 }
00096 co << "\n" << std::endl;
00097 }