ReFRACtor
accumulated_timer.h
Go to the documentation of this file.
1 #ifndef ACCUMULATED_TIMER_H
2 #define ACCUMULATED_TIMER_H
3 #include "printable.h"
4 #include "logger.h"
5 #include <boost/shared_ptr.hpp>
6 #include <boost/noncopyable.hpp>
7 #include <boost/timer.hpp>
8 
9 namespace FullPhysics {
10 class FunctionTimer;
11 class FunctionTimerR;
12 
13 /****************************************************************/
19 class AccumulatedTimer : public Printable<AccumulatedTimer> {
20 public:
21 
22 //-----------------------------------------------------------------------
25 //-----------------------------------------------------------------------
26 
27  AccumulatedTimer(const std::string& Desc) : elapsed_(0.0), desc(Desc) {}
28 
29 //-----------------------------------------------------------------------
31 //-----------------------------------------------------------------------
32 
33  double elapsed() const {return elapsed_; }
34 
35 //-----------------------------------------------------------------------
37 //-----------------------------------------------------------------------
38 
39  void reset_elapsed() {elapsed_ = 0.0;}
40 
41 //-----------------------------------------------------------------------
43 //-----------------------------------------------------------------------
44 
45  FunctionTimer function_timer(bool Auto_log = false) const;
46  void print(std::ostream& Os) const
47  { Os << desc << " elapsed time " << elapsed(); }
48 private:
49  mutable double elapsed_;
50  std::string desc;
51  friend class FunctionTimerR;
52 };
53 
54 /****************************************************************/
57 class FunctionTimerR : boost::noncopyable {
58 public:
59  FunctionTimerR(const AccumulatedTimer& At, bool Auto_log)
60  : at(At), auto_log(Auto_log) {}
62  {
63  at.elapsed_ += t.elapsed();
64  if(auto_log) {
65  Logger::info() << "Current: " << at.desc << " elapsed time "
66  << t.elapsed() << "\n";
67  Logger::info() << "Total: " << at << "\n";
68  }
69  }
70 private:
71  const AccumulatedTimer& at;
72  boost::timer t;
73  bool auto_log;
74 };
75 
76 /****************************************************************/
81 public:
82  FunctionTimer(const AccumulatedTimer& At, bool Auto_log) :
83  p(new FunctionTimerR(At, Auto_log)) {}
84 private:
86 };
87 
88 inline FunctionTimer AccumulatedTimer::function_timer(bool Auto_log) const
89 { return FunctionTimer(*this, Auto_log); }
90 }
91 #endif
static LogHelper info()
Definition: logger.h:109
AccumulatedTimer(const std::string &Desc)
Create an AccumulatedTimer.
void reset_elapsed()
Reset elapsed time to 0.
Helper class for AccumulatedTimer.
This is a Mixin for classes that can be printed.
Definition: printable.h:24
FunctionTimer function_timer(bool Auto_log=false) const
Function timer.
FunctionTimer(const AccumulatedTimer &At, bool Auto_log)
This is a simple timer class that can be used to accumulate the time spent in multiple calls to a fun...
Contains classes to abstract away details in various Spurr Radiative Transfer software.
Definition: doxygen_python.h:1
void print(std::ostream &Os) const
Helper class for AccumulatedTimer.
FunctionTimerR(const AccumulatedTimer &At, bool Auto_log)
double elapsed() const
Total elapsed time.

Copyright © 2017, California Institute of Technology.
ALL RIGHTS RESERVED.
U.S. Government Sponsorship acknowledged.
Generated Fri Aug 24 2018 15:44:11