bes  Updated for version 3.20.8
BESStopWatch.h
1 // BESStopWatch.h
2 
3 // This file is part of bes, A C++ back-end server implementation framework
4 // for the OPeNDAP Data Access Protocol.
5 
6 // Copyright (c) 2004-2009 University Corporation for Atmospheric Research
7 // Author: Patrick West <pwest@ucar.edu> and Jose Garcia <jgarcia@ucar.edu>
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 //
23 // You can contact University Corporation for Atmospheric Research at
24 // 3080 Center Green Drive, Boulder, CO 80301
25 
26 // (c) COPYRIGHT University Corporation for Atmospheric Research 2004-2005
27 // Please read the full copyright statement in the file COPYRIGHT_UCAR.
28 //
29 // Authors:
30 // ndp Nathan Potter <ndp@opendap.org>
31 // pwest Patrick West <pwest@ucar.edu>
32 // jgarcia Jose Garcia <jgarcia@ucar.edu>
33 
34 #ifndef I_BESStopWatch_h
35 #define I_BESStopWatch_h 1
36 
37 #include "sys/time.h"
38 #include "sys/resource.h"
39 #if HAVE_UNISTD_H
40 #include <unistd.h>
41 #endif
42 
43 #include "BESObj.h"
44 
45 #define TIMING_LOG_KEY "timing"
46 #define MISSING_LOG_PARAM ""
47 
48 class BESStopWatch;
49 
50 namespace bes_timing {
51 extern BESStopWatch *elapsedTimeToReadStart;
52 extern BESStopWatch *elapsedTimeToTransmitStart;
53 }
54 
55 class BESStopWatch : public BESObj
56 {
57  private:
58  std::string d_timer_name;
59  std::string d_req_id;
60  std::string d_log_name;
61  bool d_started ;
62  bool d_stopped ;
63 
64  struct timeval d_start_usage;
65  struct timeval d_stop_usage;
66  struct timeval d_result ;
67 
68  // bool timeval_subtract() ;
69  unsigned long int get_elapsed_us();
70  unsigned long int get_start_us();
71  unsigned long int get_stop_us();
72  bool get_time_of_day(struct timeval &time_val);
73  void report();
74 
75  public:
76 
80  BESStopWatch() : d_timer_name(MISSING_LOG_PARAM),
81  d_req_id(MISSING_LOG_PARAM),
82  d_log_name(TIMING_LOG_KEY),
83  d_started(false),
84  d_stopped(false)
85 {
86 }
87 
93  BESStopWatch(std::string logName) : d_timer_name(MISSING_LOG_PARAM),
94  d_req_id(MISSING_LOG_PARAM),
95  d_log_name(logName),
96  d_started(false),
97  d_stopped(false)
98 {
99 }
100 
108  virtual ~BESStopWatch();
109 
116  virtual bool start(std::string name) ;
117 
126  virtual bool start(std::string name, std::string reqID) ;
127 
128  virtual void dump( std::ostream &strm ) const ;
129 } ;
130 
131 #endif // I_BESStopWatch_h
132 
top level BES object to house generic methods
Definition: BESObj.h:50
BESStopWatch(std::string logName)
Definition: BESStopWatch.h:93
virtual bool start(std::string name)
Definition: BESStopWatch.cc:67
virtual void dump(std::ostream &strm) const
dumps information about this object
virtual ~BESStopWatch()