G4SliceTimer.hh

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // 
00030 // ----------------------------------------------------------------------
00031 // Class G4SliceTimer
00032 //
00033 // Class description:
00034 //
00035 // Class for timer objects, able to measure elasped user/system process
00036 // accumulated time.
00037 //
00038 // Note: Uses <sys/times.h> & <unistd.h> - POSIX.1 defined
00039 //       If used, this header must be included in the source (.cc) file
00040 //       and it must be the first header file to be included!
00041 //
00042 // Member functions:
00043 //
00044 // G4SliceTimer()
00045 //   Construct a timer object
00046 // Start()
00047 //   Start timing
00048 // Stop()
00049 //   Stop timing
00050 // Clear()
00051 //   Clear accumulated times
00052 // G4bool IsValid()
00053 //   Return true if have a valid time (ie start() and stop() called)
00054 // G4double GetRealElapsed()
00055 //   Return the elapsed real time between last calling start() and stop()
00056 // G4double GetSystemElapsed()
00057 //   Return the elapsed system time between last calling start() and stop()
00058 // G4double GetUserElapsed()
00059 //   Return the elapsed user time between last calling start() and stop()
00060 //
00061 // Operators:
00062 //
00063 // std::ostream& operator << (std::ostream& os, const G4SliceTimer& t);
00064 //   Print the elapsed real,system and usertimes on os. Prints **s for times
00065 //   if !IsValid
00066 //
00067 // Member data:
00068 //
00069 // G4bool fValidTimes
00070 //   True after start and stop have both been called more than once and
00071 //   an equal number of times
00072 // clock_t fStartRealTime,fEndRealTime
00073 //   Real times (arbitrary time 0)
00074 // tms fStartTimes,fEndTimes
00075 //   Timing structures (see times(2)) for start and end times
00076 
00077 // History:
00078 // 23.10.06 - M.Asai - Derived from G4Timer implementation
00079 // ----------------------------------------------------------------------
00080 #ifndef G4SLICE_TIMER_HH
00081 #define G4SLICE_TIMER_HH
00082 
00083 #ifndef WIN32
00084 #  include <unistd.h>
00085 #  include <sys/times.h>
00086 #else
00087 #  include <time.h>
00088 #  define _SC_CLK_TCK    1
00089 
00090    extern "C" {
00091           int sysconf(int);
00092    };
00093 
00094    // Structure returned by times()
00095   
00096    struct tms {
00097       clock_t tms_utime;           /* user time */
00098       clock_t tms_stime;           /* system time */
00099       clock_t tms_cutime;          /* user time, children */
00100       clock_t tms_cstime;          /* system time, children */
00101    };
00102 
00103    extern "C" {
00104       extern clock_t times(struct tms *);
00105    };
00106 #endif  /* WIN32 */
00107 
00108 #include "G4Types.hh"
00109 #include "G4ios.hh"
00110 
00111 class G4SliceTimer
00112 {
00113   public:
00114 
00115     G4SliceTimer();
00116 
00117     inline void Start();
00118     inline void Stop();
00119     inline void Clear();
00120     inline G4bool IsValid() const;
00121     G4double GetRealElapsed() const;
00122     G4double GetSystemElapsed() const;
00123     G4double GetUserElapsed() const;
00124 
00125   private:
00126 
00127     G4bool fValidTimes;
00128     clock_t fStartRealTime,fEndRealTime;
00129     tms fStartTimes,fEndTimes;
00130     G4double fRealElapsed,fSystemElapsed,fUserElapsed;
00131 };
00132 
00133 std::ostream& operator << (std::ostream& os, const G4SliceTimer& t);
00134 
00135 #include "G4SliceTimer.icc"
00136 
00137 #define times ostimes
00138 
00139 #endif

Generated on Mon May 27 17:49:51 2013 for Geant4 by  doxygen 1.4.7