LocARNA-1.9.2
src/LocARNA/stopwatch.hh
00001 #ifndef LOCARNA_STOPWATCH_HH
00002 #define LOCARNA_STOPWATCH_HH
00003 
00004 #ifdef HAVE_CONFIG_H
00005 #include <config.h>
00006 #endif
00007 
00008 #include "aux.hh"
00009 #include <iosfwd>
00010 #include <string>
00011 
00012 namespace LocARNA {
00016     class StopWatch {
00017     private:
00018         struct timer_t {
00019             bool running;      
00020             double last_start; 
00021             double total;      
00022             size_t cycles;     
00023 
00024             timer_t()
00025                 : running(false), last_start(0.0), total(0.0), cycles(0) {}
00026         };
00027 
00029         typedef unordered_map<std::string, timer_t>::type map_t;
00030 
00031         map_t timers;
00032 
00033         bool print_on_exit;
00034 
00035     public:
00041         explicit StopWatch(bool print_on_exit = false);
00042 
00046         ~StopWatch();
00047 
00053         void
00054         set_print_on_exit(bool print_on_exit);
00055 
00063         bool
00064         start(const std::string &name);
00065 
00073         bool
00074         stop(const std::string &name);
00075 
00083         bool
00084         is_running(const std::string &name) const;
00085 
00093         double
00094         current_total(const std::string &name) const;
00095 
00103         size_t
00104         current_cycles(const std::string &name) const;
00105 
00116         std::ostream &
00117         print_info(std::ostream &out, const std::string &name) const;
00118 
00126         std::ostream &
00127         print_info(std::ostream &out) const;
00128 
00129     private:
00130         double
00131         current_time() const;
00132     };
00133 }
00134 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends