StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StDbLogger.hh
1 /***************************************************************************
2  *
3  * $Id: StDbLogger.hh,v 1.2 2016/05/24 20:26:48 dmitry Exp $
4  *
5  * Author: R. Jeff Porter
6  ***************************************************************************
7  *
8  * Description: Records elapsed times for DBI & query calls
9  *
10  ***************************************************************************
11  *
12  * $Log: StDbLogger.hh,v $
13  * Revision 1.2 2016/05/24 20:26:48 dmitry
14  * coverity - unreachable delete loop suppression
15  *
16  * Revision 1.1 2001/01/22 18:37:55 porter
17  * Update of code needed in next year running. This update has little
18  * effect on the interface (only 1 method has been changed in the interface).
19  * Code also preserves backwards compatibility so that old versions of
20  * StDbLib can read new table structures.
21  * -Important features:
22  * a. more efficient low-level table structure (see StDbSql.cc)
23  * b. more flexible indexing for new systems (see StDbElememtIndex.cc)
24  * c. environment variable override KEYS for each database
25  * d. StMessage support & clock-time logging diagnostics
26  * -Cosmetic features
27  * e. hid stl behind interfaces (see new *Impl.* files) to again allow rootcint access
28  * f. removed codes that have been obsolete for awhile (e.g. db factories)
29  * & renamed some classes for clarity (e.g. tableQuery became StDataBaseI
30  * and mysqlAccessor became StDbSql)
31  *
32  **************************************************************************/
33 #ifndef STDBLOGGER_HH
34 #define STDBLOGGER_HH
35 
36 #include <sys/time.h>
37 
38 class StDbLogger {
39 
40 protected:
41 
42  double mt0;
43  double mtotalTimes;
44  int mnTotal;
45 
46 public:
47 
48  StDbLogger(): mt0(0), mtotalTimes(0), mnTotal(0) {};
49  ~StDbLogger(){};
50 
51  void start();
52  double end();
53 
54  double getTotalTimes();
55  int getNumCalls();
56  double wallTime();
57 
58 };
59 
60 inline void StDbLogger::start(){mt0=wallTime();}
61 inline double StDbLogger::end() {
62  double elapsedTime=wallTime()-mt0;
63  mtotalTimes+=elapsedTime;
64  mnTotal++;
65  return elapsedTime;
66 }
67 inline double StDbLogger::getTotalTimes() { return mtotalTimes; };
68 inline int StDbLogger::getNumCalls() { return mnTotal; }
69 inline double StDbLogger::wallTime(){
70  struct timeval Tp;
71  gettimeofday( &Tp, (struct timezone *) 0);
72 // seconds + microseconds/1000000:
73  return Tp.tv_sec + Tp.tv_usec/1000000.0;
74 };
75 
76 #endif
StDbLogger()
calls to clock
Definition: StDbLogger.hh:48