LSSTApplications  8.0.0.0+107,8.0.0.1+13,9.1+18,9.2,master-g084aeec0a4,master-g0aced2eed8+6,master-g15627eb03c,master-g28afc54ef9,master-g3391ba5ea0,master-g3d0fb8ae5f,master-g4432ae2e89+36,master-g5c3c32f3ec+17,master-g60f1e072bb+1,master-g6a3ac32d1b,master-g76a88a4307+1,master-g7bce1f4e06+57,master-g8ff4092549+31,master-g98e65bf68e,master-ga6b77976b1+53,master-gae20e2b580+3,master-gb584cd3397+53,master-gc5448b162b+1,master-gc54cf9771d,master-gc69578ece6+1,master-gcbf758c456+22,master-gcec1da163f+63,master-gcf15f11bcc,master-gd167108223,master-gf44c96c709
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: