Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
WireCell::TimeKeeper Class Reference

#include <TimeKeeper.h>

Public Types

typedef boost::posix_time::ptime ptime
 
typedef boost::posix_time::time_duration deltat
 
typedef std::pair< ptime, std::stringevent
 

Public Member Functions

 TimeKeeper (const std::string &msg="start", ptime starting_time=boost::posix_time::microsec_clock::local_time())
 
 ~TimeKeeper ()
 
ptime start_time () const
 Return the time at which this time keeper was started. More...
 
ptime last_time () const
 Return the time of the last event. More...
 
deltat last_duration () const
 Return the duration between the last two events. More...
 
deltat since (ptime now=boost::posix_time::microsec_clock::local_time()) const
 Return the time duration between "now" and the start time. More...
 
std::string operator() (std::string msg="<tick>", ptime now=boost::posix_time::microsec_clock::local_time())
 Record an event. More...
 
std::string summary () const
 Return summary up to now. More...
 
event operator[] (int ind) const
 Return event by index. More...
 

Private Member Functions

std::string emit (int ind) const
 Emit a formatted message for the given event index. More...
 

Private Attributes

std::vector< eventm_events
 

Detailed Description

A helper class to give some time keeping.

Use like

TimeKeeper tk("starting"); ... tk("starting long calculation...."); do_long_calculation(); tk("...done"); ... info(tk.summary());

Definition at line 21 of file TimeKeeper.h.

Member Typedef Documentation

typedef boost::posix_time::time_duration WireCell::TimeKeeper::deltat

Definition at line 24 of file TimeKeeper.h.

Definition at line 25 of file TimeKeeper.h.

typedef boost::posix_time::ptime WireCell::TimeKeeper::ptime

Definition at line 23 of file TimeKeeper.h.

Constructor & Destructor Documentation

TimeKeeper::TimeKeeper ( const std::string msg = "start",
ptime  starting_time = boost::posix_time::microsec_clock::local_time() 
)

Definition at line 8 of file TimeKeeper.cxx.

9 {
10  m_events.push_back(event(starting_time, msg));
11 }
void msg(const char *fmt,...)
Definition: message.cpp:107
std::pair< ptime, std::string > event
Definition: TimeKeeper.h:25
std::vector< event > m_events
Definition: TimeKeeper.h:60
TimeKeeper::~TimeKeeper ( )

Definition at line 13 of file TimeKeeper.cxx.

14 {
15 }

Member Function Documentation

std::string TimeKeeper::emit ( int  ind) const
private

Emit a formatted message for the given event index.

Definition at line 57 of file TimeKeeper.cxx.

58 {
59  while (ind < 0) { ind += m_events.size();}
60  int prev_ind = ind-1;
61  if (prev_ind<0) prev_ind=0;
62  const event& prev = (*this)[prev_ind];
63  const event& evt = (*this)[ind];
64 
65  deltat from_start = since(evt.first);
66  deltat from_last = evt.first - prev.first;
67 
68  stringstream ss;
69  ss << "TICK: " << from_start.total_milliseconds() << " ms "
70  << "(this: " << from_last.total_milliseconds() << " ms) "
71  << evt.second;
72  return ss.str();
73 }
deltat since(ptime now=boost::posix_time::microsec_clock::local_time()) const
Return the time duration between "now" and the start time.
Definition: TimeKeeper.cxx:36
std::vector< event > m_events
Definition: TimeKeeper.h:60
TCEvent evt
Definition: DataStructs.cxx:7
boost::posix_time::time_duration deltat
Definition: TimeKeeper.h:24
TimeKeeper::deltat TimeKeeper::last_duration ( ) const

Return the duration between the last two events.

Definition at line 31 of file TimeKeeper.cxx.

32 {
33  return (*this)[-1].first - (*this)[-2].first;
34 }
boost::posix_time::ptime TimeKeeper::last_time ( ) const

Return the time of the last event.

Definition at line 27 of file TimeKeeper.cxx.

28 {
29  return (*this)[-1].first;
30 }
std::string TimeKeeper::operator() ( std::string  msg = "<tick>",
ptime  now = boost::posix_time::microsec_clock::local_time() 
)

Record an event.

Definition at line 17 of file TimeKeeper.cxx.

18 {
19  m_events.push_back(event(now, msg));
20  return emit(-1);
21 }
void msg(const char *fmt,...)
Definition: message.cpp:107
std::string emit(int ind) const
Emit a formatted message for the given event index.
Definition: TimeKeeper.cxx:57
std::pair< ptime, std::string > event
Definition: TimeKeeper.h:25
std::vector< event > m_events
Definition: TimeKeeper.h:60
TimeKeeper::event TimeKeeper::operator[] ( int  ind) const

Return event by index.

Definition at line 41 of file TimeKeeper.cxx.

42 {
43  while (ind < 0) { ind += m_events.size();}
44 
45  return m_events[ind];
46 }
std::vector< event > m_events
Definition: TimeKeeper.h:60
boost::posix_time::time_duration TimeKeeper::since ( ptime  now = boost::posix_time::microsec_clock::local_time()) const

Return the time duration between "now" and the start time.

Definition at line 36 of file TimeKeeper.cxx.

37 {
38  return now - start_time();
39 }
ptime start_time() const
Return the time at which this time keeper was started.
Definition: TimeKeeper.cxx:23
boost::posix_time::ptime TimeKeeper::start_time ( ) const

Return the time at which this time keeper was started.

Definition at line 23 of file TimeKeeper.cxx.

24 {
25  return (*this)[0].first;
26 }
std::string TimeKeeper::summary ( ) const

Return summary up to now.

Definition at line 48 of file TimeKeeper.cxx.

49 {
50  stringstream ss;
51  for (size_t ind=0; ind<m_events.size(); ++ind) {
52  ss << this->emit(ind) << "\n";
53  }
54  return ss.str();
55 }
std::string emit(int ind) const
Emit a formatted message for the given event index.
Definition: TimeKeeper.cxx:57
std::vector< event > m_events
Definition: TimeKeeper.h:60

Member Data Documentation

std::vector< event > WireCell::TimeKeeper::m_events
private

Definition at line 60 of file TimeKeeper.h.


The documentation for this class was generated from the following files: