LSSTApplications  1.1.2+25,10.0+13,10.0+132,10.0+133,10.0+224,10.0+41,10.0+8,10.0-1-g0f53050+14,10.0-1-g4b7b172+19,10.0-1-g61a5bae+98,10.0-1-g7408a83+3,10.0-1-gc1e0f5a+19,10.0-1-gdb4482e+14,10.0-11-g3947115+2,10.0-12-g8719d8b+2,10.0-15-ga3f480f+1,10.0-2-g4f67435,10.0-2-gcb4bc6c+26,10.0-28-gf7f57a9+1,10.0-3-g1bbe32c+14,10.0-3-g5b46d21,10.0-4-g027f45f+5,10.0-4-g86f66b5+2,10.0-4-gc4fccf3+24,10.0-40-g4349866+2,10.0-5-g766159b,10.0-5-gca2295e+25,10.0-6-g462a451+1
LSSTDataManagementBasePackage
Public Member Functions | Private Attributes | Friends | List of all members
lsst::ap::Stopwatch Class Reference

Utility class for profiling. More...

#include <Time.h>

Public Member Functions

 Stopwatch (bool const go=true)
 
void start ()
 
void stop ()
 
std::string const toString () const
 
double seconds () const
 

Private Attributes

TimeSpec _ts
 
bool _stopped
 

Friends

std::ostream & operator<< (std::ostream &, Stopwatch const &)
 

Detailed Description

Utility class for profiling.

Definition at line 98 of file Time.h.

Constructor & Destructor Documentation

lsst::ap::Stopwatch::Stopwatch ( bool const  go = true)
explicit

Definition at line 124 of file Time.cc.

124  : _ts(), _stopped(true) {
125  if (go) {
126  start();
127  }
128 }
TimeSpec _ts
Definition: Time.h:114

Member Function Documentation

double lsst::ap::Stopwatch::seconds ( ) const

Definition at line 156 of file Time.cc.

156  {
157  TimeSpec t;
158  if (_stopped) {
159  t = _ts;
160  } else {
161  t.now();
162  t -= _ts;
163  }
164  return t.seconds();
165 }
TimeSpec & now()
Definition: Time.cc:93
double seconds() const
Definition: Time.h:87
TimeSpec _ts
Definition: Time.h:114
void lsst::ap::Stopwatch::start ( )

Definition at line 131 of file Time.cc.

131  {
132  if (_stopped) {
133  _ts.now();
134  _stopped = false;
135  }
136 }
TimeSpec & now()
Definition: Time.cc:93
TimeSpec _ts
Definition: Time.h:114
void lsst::ap::Stopwatch::stop ( )

Definition at line 139 of file Time.cc.

139  {
140  if (!_stopped) {
141  TimeSpec t;
142  t.now() -= _ts;
143  _ts = t;
144  _stopped = true;
145  }
146 }
TimeSpec _ts
Definition: Time.h:114
std::string const lsst::ap::Stopwatch::toString ( void  ) const

Definition at line 149 of file Time.cc.

149  {
150  std::ostringstream os;
151  os << *this;
152  return os.str();
153 }

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
Stopwatch const &  watch 
)
friend

Definition at line 168 of file Time.cc.

168  {
169  TimeSpec t;
170  if (watch._stopped) {
171  t = watch._ts;
172  } else {
173  t.now();
174  t -= watch._ts;
175  }
176  long nsec = t.tv_nsec % 1000000000l;
177  long sec = t.tv_sec + t.tv_nsec/1000000000l;
178  long min = (sec/60) % 60;
179  long hour = sec/3600;
180 
181  double s = static_cast<double>(sec % 60) + 1e-9 * static_cast<double>(nsec);
182 
183  if (hour > 0) {
184  os << hour << "hr ";
185  }
186  if (min > 0) {
187  os << min << "min ";
188  }
189  os << s << "sec";
190  return os;
191 }
double min
Definition: attributes.cc:216

Member Data Documentation

bool lsst::ap::Stopwatch::_stopped
private

Definition at line 115 of file Time.h.

TimeSpec lsst::ap::Stopwatch::_ts
private

Definition at line 114 of file Time.h.


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