bes  Updated for version 3.20.6
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 "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 _timer_name;
59  std::string _req_id;
60  std::string _log_name;
61  bool _started ;
62  bool _stopped ;
63 
64  struct rusage _start_usage ;
65  struct rusage _stop_usage ;
66  struct timeval _result ;
67 
68  bool timeval_subtract() ;
69 
70  public:
71 
75  BESStopWatch() : _timer_name(MISSING_LOG_PARAM),
76  _req_id(MISSING_LOG_PARAM),
77  _log_name(TIMING_LOG),
78  _started(false),
79  _stopped(false)
80 {
81 }
82 
88  BESStopWatch(std::string logName) : _timer_name(MISSING_LOG_PARAM),
89  _req_id(MISSING_LOG_PARAM),
90  _log_name(logName),
91  _started(false),
92  _stopped(false)
93 {
94 }
95 
103  virtual ~BESStopWatch();
104 
111  virtual bool start(std::string name) ;
112 
121  virtual bool start(std::string name, std::string reqID) ;
122 
123  virtual void dump( std::ostream &strm ) const ;
124 } ;
125 
126 #endif // I_BESStopWatch_h
127 
BESStopWatch::start
virtual bool start(std::string name)
Definition: BESStopWatch.cc:58
BESStopWatch::BESStopWatch
BESStopWatch(std::string logName)
Definition: BESStopWatch.h:88
BESStopWatch::~BESStopWatch
virtual ~BESStopWatch()
Definition: BESStopWatch.cc:123
BESStopWatch::BESStopWatch
BESStopWatch()
Definition: BESStopWatch.h:75
BESObj
top level BES object to house generic methods
Definition: BESObj.h:49
BESStopWatch
Definition: BESStopWatch.h:55
BESStopWatch::dump
virtual void dump(std::ostream &strm) const
dumps information about this object
Definition: BESStopWatch.cc:214