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.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /global/management/src/G4Timer.cc (Version 11.3.0) and /global/management/src/G4Timer.cc (Version 10.5)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 // G4Timer class implementation                << 
 27 //                                                 26 //
 28 // Author: P.Kent, 21.08.95 - First implementa <<  27 //
 29 // Revision: G.Cosmo, 29.04.97 - Added timings <<  28 // 
 30 // ------------------------------------------- <<  29 // ----------------------------------------------------------------------
                                                   >>  30 // class G4Timer
                                                   >>  31 //
                                                   >>  32 // Implementation
                                                   >>  33 // 29.04.97 G.Cosmo Added timings for Windows systems
 31                                                    34 
 32 #include "G4Timer.hh"                              35 #include "G4Timer.hh"
 33 #include "G4ios.hh"                                36 #include "G4ios.hh"
 34 #include "G4Exception.hh"                      << 
 35                                                    37 
 36 #include <iomanip>                                 38 #include <iomanip>
 37                                                    39 
                                                   >>  40 // Global error function
                                                   >>  41 #include "G4ExceptionSeverity.hh"
                                                   >>  42 void G4Exception(const char* originOfException,
                                                   >>  43                  const char* exceptionCode,
                                                   >>  44                              G4ExceptionSeverity severity,
                                                   >>  45                  const char* comments);
                                                   >>  46 
 38 #if defined(IRIX6_2)                               47 #if defined(IRIX6_2)
 39 #  if defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE <<  48 #  if defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE_EXTENDED==1)
 40 #    define __vfork vfork                          49 #    define __vfork vfork
 41 #  endif                                           50 #  endif
 42 #endif                                             51 #endif
 43                                                    52 
 44 #ifdef WIN32                                       53 #ifdef WIN32
 45 #  include <sys/types.h>                           54 #  include <sys/types.h>
 46 #  include <windows.h>                             55 #  include <windows.h>
 47                                                    56 
 48 // extract milliseconds time unit              <<  57    // extract milliseconds time unit
 49 G4int sysconf(G4int a)                         <<  58    G4int sysconf(G4int a)
 50 {                                              <<  59    {
 51   if(a == _SC_CLK_TCK)                         <<  60      if( a == _SC_CLK_TCK ) return 1000;
 52     return 1000;                               <<  61      else return 0;
 53   else                                         <<  62    }
 54     return 0;                                  <<  63 
 55 }                                              <<  64    static clock_t filetime2msec( FILETIME* t )
 56                                                <<  65    {
 57 static clock_t filetime2msec(FILETIME* t)      <<  66      return (clock_t)((((G4float)t->dwHighDateTime)*429496.7296)+
 58 {                                              <<  67              (((G4float)t->dwLowDateTime)*.0001) );
 59   return (clock_t)((((G4float) t->dwHighDateTi <<  68    }
 60                    (((G4float) t->dwLowDateTim <<  69 
 61 }                                              <<  70 
 62                                                <<  71    clock_t times(struct tms * t)
 63 clock_t times(struct tms* t)                   <<  72    {
 64 {                                              <<  73      FILETIME      ct = {0,0}, et = {0,0}, st = {0,0}, ut = {0,0}, rt = {0,0};
 65   FILETIME ct = { 0, 0 }, et = { 0, 0 }, st =  <<  74      SYSTEMTIME realtime;
 66            rt = { 0, 0 };                      <<  75 
 67   SYSTEMTIME realtime;                         <<  76      GetSystemTime( &realtime );
 68                                                <<  77      SystemTimeToFileTime( &realtime, &rt ); // get real time in 10^-9 sec
 69   GetSystemTime(&realtime);                    <<  78      if( t != 0 )
 70   SystemTimeToFileTime(&realtime, &rt);  // ge <<  79      {
 71   if(t != 0)                                   <<  80        GetProcessTimes( GetCurrentProcess(), &ct, &et, &st, &ut);
 72   {                                            <<  81          // get process time in 10^-9 sec
 73     GetProcessTimes(GetCurrentProcess(), &ct,  <<  82        t->tms_utime = t->tms_cutime = filetime2msec(&ut);
 74     // get process time in 10^-9 sec           <<  83        t->tms_stime = t->tms_cstime = filetime2msec(&st);
 75     t->tms_utime = t->tms_cutime = filetime2ms <<  84      }
 76     t->tms_stime = t->tms_cstime = filetime2ms <<  85      return filetime2msec(&rt);
 77   }                                            <<  86    }
 78   return filetime2msec(&rt);                   << 
 79 }                                              << 
 80 #endif /* WIN32 */                                 87 #endif /* WIN32 */
 81                                                    88 
 82 // Print timer status on std::ostream              89 // Print timer status on std::ostream
 83 //                                                 90 //
 84 std::ostream& operator<<(std::ostream& os, con <<  91 std::ostream& operator << (std::ostream& os, const G4Timer& t)
 85 {                                                  92 {
 86   // so fixed doesn't propagate                    93   // so fixed doesn't propagate
 87   std::stringstream ss;                            94   std::stringstream ss;
 88   ss << std::fixed;                                95   ss << std::fixed;
 89   if(t.IsValid())                              <<  96   if (t.IsValid())
 90   {                                                97   {
 91     ss << "User=" << t.GetUserElapsed() << "s  <<  98     ss << "User=" << t.GetUserElapsed()
                                                   >>  99        << "s Real=" << t.GetRealElapsed()
 92        << "s Sys=" << t.GetSystemElapsed() <<     100        << "s Sys=" << t.GetSystemElapsed() << "s";
 93 #ifdef G4MULTITHREADED                            101 #ifdef G4MULTITHREADED
 94     // avoid possible FPE error                   102     // avoid possible FPE error
 95     if(t.GetRealElapsed() > 1.0e-6)               103     if(t.GetRealElapsed() > 1.0e-6)
 96     {                                             104     {
 97       G4double cpu_util = (t.GetUserElapsed()  << 105       G4double cpu_util = (t.GetUserElapsed()+t.GetSystemElapsed()) /
 98                           t.GetRealElapsed() * << 106                            t.GetRealElapsed() * 100.0;
 99       ss << std::setprecision(1);                 107       ss << std::setprecision(1);
100       ss << " [Cpu=" << std::setprecision(1) <    108       ss << " [Cpu=" << std::setprecision(1) << cpu_util << "%]";
101     }                                             109     }
102 #endif                                            110 #endif
103   }                                               111   }
104   else                                            112   else
105   {                                               113   {
106     ss << "User=****s Real=****s Sys=****s";      114     ss << "User=****s Real=****s Sys=****s";
107   }                                               115   }
108   os << ss.str();                                 116   os << ss.str();
109                                                   117 
110   return os;                                      118   return os;
111 }                                                 119 }
112                                                   120 
                                                   >> 121 G4Timer::G4Timer()
                                                   >> 122   : fValidTimes(false)
                                                   >> 123 {
                                                   >> 124 }
                                                   >> 125 
113 G4double G4Timer::GetRealElapsed() const          126 G4double G4Timer::GetRealElapsed() const
114 {                                                 127 {
115   if(!fValidTimes)                             << 128   if (!fValidTimes)
116   {                                               129   {
117     G4Exception("G4Timer::GetRealElapsed()", " << 130     G4Exception("G4Timer::GetRealElapsed()", "InvalidCondition",
118                 "Timer not stopped or times no << 131                 FatalException, "Timer not stopped or times not recorded!");
119   }                                               132   }
120   std::chrono::duration<G4double> diff = fEndR << 133   std::chrono::duration<G4double> diff=fEndRealTime-fStartRealTime;
121   return diff.count();                            134   return diff.count();
122 }                                                 135 }
123                                                   136 
                                                   >> 137 
124 G4double G4Timer::GetSystemElapsed() const        138 G4double G4Timer::GetSystemElapsed() const
125 {                                                 139 {
126   if(!fValidTimes)                             << 140   if (!fValidTimes)
127   {                                               141   {
128     G4Exception("G4Timer::GetSystemElapsed()",    142     G4Exception("G4Timer::GetSystemElapsed()", "InvalidCondition",
129                 FatalException, "Timer not sto    143                 FatalException, "Timer not stopped or times not recorded!");
130   }                                               144   }
131   G4double diff = fEndTimes.tms_stime - fStart << 145   G4double diff=fEndTimes.tms_stime-fStartTimes.tms_stime;
132   return diff / sysconf(_SC_CLK_TCK);          << 146   return diff/sysconf(_SC_CLK_TCK);
133 }                                                 147 }
134                                                   148 
135 G4double G4Timer::GetUserElapsed() const          149 G4double G4Timer::GetUserElapsed() const
136 {                                                 150 {
137   if(!fValidTimes)                             << 151   if (!fValidTimes)
138   {                                               152   {
139     G4Exception("G4Timer::GetUserElapsed()", " << 153     G4Exception("G4Timer::GetUserElapsed()", "InvalidCondition",
140                 "Timer not stopped or times no << 154                 FatalException, "Timer not stopped or times not recorded");
141   }                                               155   }
142   G4double diff = fEndTimes.tms_utime - fStart << 156   G4double diff=fEndTimes.tms_utime-fStartTimes.tms_utime;
143   return diff / sysconf(_SC_CLK_TCK);          << 157   return diff/sysconf(_SC_CLK_TCK);
144 }                                                 158 }
145                                                   159