TimeKeeper.cxx
Go to the documentation of this file.
2 
3 #include <sstream>
4 
5 using namespace std;
6 using namespace WireCell;
7 
8 TimeKeeper::TimeKeeper(const std::string& msg, ptime starting_time)
9 {
10  m_events.push_back(event(starting_time, msg));
11 }
12 
13 TimeKeeper::~TimeKeeper()
14 {
15 }
16 
17 std::string TimeKeeper::operator()(std::string msg, ptime now)
18 {
19  m_events.push_back(event(now, msg));
20  return emit(-1);
21 }
22 
23 boost::posix_time::ptime TimeKeeper::start_time() const
24 {
25  return (*this)[0].first;
26 }
27 boost::posix_time::ptime TimeKeeper::last_time() const
28 {
29  return (*this)[-1].first;
30 }
31 TimeKeeper::deltat TimeKeeper::last_duration() const
32 {
33  return (*this)[-1].first - (*this)[-2].first;
34 }
35 
36 boost::posix_time::time_duration TimeKeeper::since(ptime now) const
37 {
38  return now - start_time();
39 }
40 
41 TimeKeeper::event TimeKeeper::operator[](int ind) const
42 {
43  while (ind < 0) { ind += m_events.size();}
44 
45  return m_events[ind];
46 }
47 
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 }
56 
57 std::string TimeKeeper::emit(int ind) const
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 }
void msg(const char *fmt,...)
Definition: message.cpp:107
std::string string
Definition: nybbler.cc:12
STL namespace.
boost::posix_time::ptime ptime
Definition: TimeKeeper.h:23
Definition: Main.h:22
std::pair< ptime, std::string > event
Definition: TimeKeeper.h:25
def summary(store)
Definition: info.py:119
TCEvent evt
Definition: DataStructs.cxx:7
boost::posix_time::time_duration deltat
Definition: TimeKeeper.h:24