ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4SliceTimer.hh
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4SliceTimer.hh
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 //
28 //
29 // ----------------------------------------------------------------------
30 // Class G4SliceTimer
31 //
32 // Class description:
33 //
34 // Class for timer objects, able to measure elasped user/system process
35 // accumulated 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
39 // and it must be the first header file to be included!
40 //
41 // Member functions:
42 //
43 // G4SliceTimer()
44 // Construct a timer object
45 // Start()
46 // Start timing
47 // Stop()
48 // Stop timing
49 // Clear()
50 // Clear accumulated times
51 // G4bool IsValid()
52 // Return true if have a valid time (ie start() and stop() called)
53 // G4double GetRealElapsed()
54 // Return the elapsed real time between last calling start() and stop()
55 // G4double GetSystemElapsed()
56 // Return the elapsed system time between last calling start() and stop()
57 // G4double GetUserElapsed()
58 // Return the elapsed user time between last calling start() and stop()
59 //
60 // Operators:
61 //
62 // std::ostream& operator << (std::ostream& os, const G4SliceTimer& t);
63 // Print the elapsed real,system and usertimes on os. Prints **s for times
64 // if !IsValid
65 //
66 // Member data:
67 //
68 // G4bool fValidTimes
69 // True after start and stop have both been called more than once and
70 // an equal number of times
71 // clock_t fStartRealTime,fEndRealTime
72 // Real times (arbitrary time 0)
73 // tms fStartTimes,fEndTimes
74 // Timing structures (see times(2)) for start and end times
75 
76 // History:
77 // 23.10.06 - M.Asai - Derived from G4Timer implementation
78 // ----------------------------------------------------------------------
79 #ifndef G4SLICE_TIMER_HH
80 #define G4SLICE_TIMER_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 
111 {
112  public:
113 
114  G4SliceTimer();
115 
116  inline void Start();
117  inline void Stop();
118  inline void Clear();
119  inline G4bool IsValid() const;
120  G4double GetRealElapsed() const;
121  G4double GetSystemElapsed() const;
122  G4double GetUserElapsed() const;
123 
124  private:
125 
130 };
131 
132 std::ostream& operator << (std::ostream& os, const G4SliceTimer& t);
133 
134 #include "G4SliceTimer.icc"
135 
136 #endif