CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TimingReport.cc
Go to the documentation of this file.
2 #include <algorithm>
3 #include <iostream>
4 #include <ostream>
5 #include <iomanip>
6 #include <map>
7 
10 }
11 
13  return std::max(0.,stopwatch.lap().ticks()-counter*PentiumTimer::bias(false));
14 }
15 
17  return std::max(0.,cpuwatch.lap().seconds()-counter*(LinuxCPUTimer::bias()+PentiumTimer::bias()));
18 }
19 
20 
22  static TimingReport * currentTimingReport=0;
23 
24  if (currentTimingReport==0) currentTimingReport = new TimingReport();
25  return currentTimingReport;
26 
27 }
28 
30  //std::cout << "Creating a new Timing Report" << std::endl;
31  //std::cout <<"StopWatch bias " << PentiumTimer::bias()<<std::endl;
32  //std::cout <<"CPUWatch bias " << LinuxCPUTimer::bias()<<std::endl;
33 }
34 
35 void TimingReport::switchOn(bool ion) {
36  if (on==ion) return;
37  on = ion;
38  //std::cout << "switching Timing Report "
39  // << (on ? "on" : "off") << std::endl;
40  SMAP::iterator p = registry.begin();
41  SMAP::iterator e = registry.end();
42  for (;p!=e; ++p) (*p).second.switchOn(on);
43 }
44 
46  if (!on) return;
47  dump(std::cout);
48 }
49 
50 void TimingReport::dump(std::ostream & ico, bool active) {
52  typedef std::map<std::string, Item *, std::less<std::string> > LMAP;
53  LMAP lreg;
54  {
55  SMAP::iterator p = registry.begin();
56  SMAP::iterator e = registry.end();
57  while (p!=e) {
58  if ( (*p).second.on && (!active||(*p).second.active()) )
59  lreg[(*p).first] = &(*p).second;
60  ++p;
61  }
62  }
63 
64  std::ostream co(ico.rdbuf());
65  size_t namew = 20;
66  co << "\n";
67  if (active) co << "Active ";
68  co << "Timing Report (in "
69  << (inTicks() ? "ticks" : "seconds") << ")\n" << std::endl;
70  LMAP::iterator p = lreg.begin();
71  LMAP::iterator e = lreg.end();
72  while (p!=e) { namew = std::max(namew,(*p).first.size()); ++p;}
73  p = lreg.begin();
74  while (p!=e) {
75  co.setf(std::ios::left,std::ios::adjustfield);
76  if (inTicks())
77  co << std::setiosflags(std::ios::showpoint)
78  << std::setprecision(3);
79  else
80  co << std::setiosflags(std::ios::showpoint | std::ios::fixed)
81  << std::setprecision(3);
82 
83  co << std::setw(namew) << (*p).first.c_str() << " ";
84  co.setf(std::ios::right,std::ios::adjustfield);
85  co << std::setw(10) << (*(*p).second).counter << " ";
86  co << std::setw(10)
87  << (inTicks() ? (*(*p).second).realticks()
88  : (*(*p).second).realsec() ) << " (real)";
89 #ifdef __linux__
90  co << " " << std::setw(10)
91  << (inTicks() ? 1./PentiumTimer::ticksInSec() : 1.)*(*(*p).second).cpusec() << " (cpu)";
92 #endif
93  co << std::endl;
94  ++p;
95  }
96  co << "\n" << std::endl;
97 }
static double bias(bool insec=true, unsigned int n=5000)
Definition: GenTimer.h:77
double realticks() const
Definition: TimingReport.cc:12
PentiumTimer stopwatch
Definition: TimingReport.h:52
bool & inTicks()
report in ticks
Definition: TimingReport.h:74
static double ticksInSec()
Definition: GenTimer.h:83
double realsec() const
Definition: TimingReport.cc:8
double seconds() const
Definition: GenTimer.h:33
Time::TimeInterval lap() const
Definition: GenTimer.h:122
const T & max(const T &a, const T &b)
static TimingReport * current()
Definition: TimingReport.cc:21
tuple cout
Definition: gather_cfg.py:121
void switchOn(bool ion)
switch all on
Definition: TimingReport.cc:35
double cpusec() const
Definition: TimingReport.cc:16
void dump(std::ostream &co, bool active=false)
Definition: TimingReport.cc:50