source: trunk/source/global/management/include/G4SliceTimer.hh @ 1202

Last change on this file since 1202 was 1058, checked in by garnier, 15 years ago

file release beta

File size: 4.5 KB
Line 
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: G4SliceTimer.hh,v 1.1 2006/10/23 07:43:31 gcosmo Exp $
28// GEANT4 tag $Name: geant4-09-02-ref-02 $
29//
30//
31// ----------------------------------------------------------------------
32// Class G4SliceTimer
33//
34// Class description:
35//
36// Class for timer objects, able to measure elasped user/system process
37// accumulated time.
38//
39// Note: Uses <sys/times.h> & <unistd.h> - POSIX.1 defined
40//       If used, this header must be included in the source (.cc) file
41//       and it must be the first header file to be included!
42//
43// Member functions:
44//
45// G4SliceTimer()
46//   Construct a timer object
47// Start()
48//   Start timing
49// Stop()
50//   Stop timing
51// Clear()
52//   Clear accumulated times
53// G4bool IsValid()
54//   Return true if have a valid time (ie start() and stop() called)
55// G4double GetRealElapsed()
56//   Return the elapsed real time between last calling start() and stop()
57// G4double GetSystemElapsed()
58//   Return the elapsed system time between last calling start() and stop()
59// G4double GetUserElapsed()
60//   Return the elapsed user time between last calling start() and stop()
61//
62// Operators:
63//
64// std::ostream& operator << (std::ostream& os, const G4SliceTimer& t);
65//   Print the elapsed real,system and usertimes on os. Prints **s for times
66//   if !IsValid
67//
68// Member data:
69//
70// G4bool fValidTimes
71//   True after start and stop have both been called more than once and
72//   an equal number of times
73// clock_t fStartRealTime,fEndRealTime
74//   Real times (arbitrary time 0)
75// tms fStartTimes,fEndTimes
76//   Timing structures (see times(2)) for start and end times
77
78// History:
79// 23.10.06 - M.Asai - Derived from G4Timer implementation
80// ----------------------------------------------------------------------
81#ifndef G4SLICE_TIMER_HH
82#define G4SLICE_TIMER_HH
83
84#ifndef WIN32
85#  include <unistd.h>
86#  include <sys/times.h>
87#else
88#  include <time.h>
89#  define _SC_CLK_TCK    1
90
91   extern "C" {
92          int sysconf(int);
93   };
94
95   // Structure returned by times()
96 
97   struct tms {
98      clock_t tms_utime;           /* user time */
99      clock_t tms_stime;           /* system time */
100      clock_t tms_cutime;          /* user time, children */
101      clock_t tms_cstime;          /* system time, children */
102   };
103
104   extern "C" {
105      extern clock_t times(struct tms *);
106   };
107#endif  /* WIN32 */
108
109#include "G4Types.hh"
110#include "G4ios.hh"
111
112class G4SliceTimer
113{
114  public:
115
116    G4SliceTimer();
117
118    inline void Start();
119    inline void Stop();
120    inline void Clear();
121    inline G4bool IsValid() const;
122    G4double GetRealElapsed() const;
123    G4double GetSystemElapsed() const;
124    G4double GetUserElapsed() const;
125
126  private:
127
128    G4bool fValidTimes;
129    clock_t fStartRealTime,fEndRealTime;
130    tms fStartTimes,fEndTimes;
131    G4double fRealElapsed,fSystemElapsed,fUserElapsed;
132};
133
134std::ostream& operator << (std::ostream& os, const G4SliceTimer& t);
135
136#include "G4SliceTimer.icc"
137
138#define times ostimes
139
140#endif
Note: See TracBrowser for help on using the repository browser.