Geant4  10.00.p03
G4Timer.hh
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id: G4Timer.hh 67970 2013-03-13 10:10:06Z gcosmo $
28 //
29 //
30 // ----------------------------------------------------------------------
31 // Class G4Timer
32 //
33 // Class description:
34 //
35 // Class for timer objects, able to measure elasped user/system process time.
36 //
37 // Note: Uses <sys/times.h> & <unistd.h> - POSIX.1 defined
38 // If used, this header must be included in the source (.cc) file and it
39 // must be the first header file to be included!
40 //
41 // Member functions:
42 //
43 // G4Timer()
44 // Construct a timer object
45 // Start()
46 // Start timing
47 // Stop()
48 // Stop timing
49 // G4bool IsValid()
50 // Return true if have a valid time (ie start() and stop() called)
51 // G4double GetRealElapsed()
52 // Return the elapsed real time between last calling start() and stop()
53 // G4double GetSystemElapsed()
54 // Return the elapsed system time between last calling start() and stop()
55 // G4double GetUserElapsed()
56 // Return the elapsed user time between last calling start() and stop()
57 //
58 // Operators:
59 //
60 // std::ostream& operator << (std::ostream& os, const G4Timer& t);
61 // Print the elapsed real,system and usertimes on os. Prints **s for times
62 // if !IsValid
63 //
64 // Member data:
65 //
66 // G4bool fValidTimes
67 // True after start and stop have both been called more than once and
68 // an equal number of times
69 // clock_t fStartRealTime,fEndRealTime
70 // Real times (arbitrary time 0)
71 // tms fStartTimes,fEndTimes
72 // Timing structures (see times(2)) for start and end times
73 
74 // History:
75 // 23.08.96 P.Kent Updated to also computed real elapsed time
76 // 21.08.95 P.Kent
77 // 29.04.97 G.Cosmo Added timings for Windows/NT
78 
79 #ifndef G4TIMER_HH
80 #define G4TIMER_HH
81 
82 #ifndef WIN32
83 # include <unistd.h>
84 # include <sys/times.h>
85 #else
86 # include <time.h>
87 # define _SC_CLK_TCK 1
88 
89  extern "C" {
90  int sysconf(int);
91  };
92 
93  // Structure returned by times()
94 
95  struct tms {
96  clock_t tms_utime; /* user time */
97  clock_t tms_stime; /* system time */
98  clock_t tms_cutime; /* user time, children */
99  clock_t tms_cstime; /* system time, children */
100  };
101 
102  extern "C" {
103  extern clock_t times(struct tms *);
104  };
105 #endif /* WIN32 */
106 
107 #include "G4Types.hh"
108 #include "G4ios.hh"
109 
110 class G4Timer
111 {
112  public:
113 
114  G4Timer();
115 
116  inline void Start();
117  inline void Stop();
118  inline G4bool IsValid() const;
119  inline const char* GetClockTime() const;
120  G4double GetRealElapsed() const;
121  G4double GetSystemElapsed() const;
122  G4double GetUserElapsed() const;
123 
124  private:
125 
129 };
130 
131 std::ostream& operator << (std::ostream& os, const G4Timer& t);
132 
133 #include "G4Timer.icc"
134 
135 #define times ostimes
136 
137 #endif
G4bool fValidTimes
Definition: G4Timer.hh:126
const char * GetClockTime() const
G4double GetSystemElapsed() const
Definition: G4Timer.cc:119
G4bool IsValid() const
tms fStartTimes
Definition: G4Timer.hh:128
bool G4bool
Definition: G4Types.hh:79
G4double GetUserElapsed() const
Definition: G4Timer.cc:130
clock_t fStartRealTime
Definition: G4Timer.hh:127
clock_t fEndRealTime
Definition: G4Timer.hh:127
G4double GetRealElapsed() const
Definition: G4Timer.cc:107
void Stop()
std::ostream & operator<<(std::ostream &os, const G4Timer &t)
Definition: G4Timer.cc:87
G4Timer()
Definition: G4Timer.cc:102
void Start()
double G4double
Definition: G4Types.hh:76
tms fEndTimes
Definition: G4Timer.hh:128
#define times
Definition: G4Timer.hh:135