xrootd
XrdMonTimer.hh
Go to the documentation of this file.
1 /*****************************************************************************/
2 /* */
3 /* XrdMonTimer.hh */
4 /* */
5 /* (c) 2005 by the Board of Trustees of the Leland Stanford, Jr., University */
6 /* All Rights Reserved */
7 /* Produced by Jacek Becla for Stanford University under contract */
8 /* DE-AC02-76SF00515 with the Department of Energy */
9 /*****************************************************************************/
10 
11 // $Id$
12 
13 #ifndef XRDMONTIMER_HH
14 #define XRDMONTIMER_HH
15 
16 #include "sys/time.h"
17 
18 class XrdMonTimer {
19 public:
20  XrdMonTimer() { reset(); }
21 
22  inline void reset(); // resets the counter
23 
24  // working with elapsed time
25  inline int start(); // starts the timer
26  inline double stop(); // stops the timer, returns elapsed time
27  inline double getElapsed() const; // returns elapsed time
28 
29  void printElapsed(const char* str);
30  // for debugging only
31  void printAll() const;
32 
33 private:
34  // modifiers
35  inline void resetTBeg();
36  inline void resetTElapsed();
37 
38  inline double calcElapsed(); // calculates, sets, and returns total elapsed time
39 
40  // selectors
41  inline int timerOn() const;
42  inline int isOn(const struct timeval& t) const;
43 
44  inline double calcDif(const struct timeval& start,
45  const struct timeval& stop) const;
46 
47  void printOne(const timeval& t, const char* prefix=0) const;
48 
49  double convert2Double(const timeval& t) const;
50 
51 private:
52  struct timeval _tbeg; // most recent "start"
53  double _elapsed; // elapsed time between all "starts" and "stops",
54  // excluding most recent "start" which has no corresponding "stop"
55 };
56 
57 #include "XrdMonTimer.icc"
58 
59 
60 #endif /* XRDMONTIMER_HH */
61