source: trunk/source/global/management/src/G4Timer.cc@ 833

Last change on this file since 833 was 833, checked in by garnier, 17 years ago

import all except CVS

File size: 4.3 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: G4Timer.cc,v 1.15 2006/06/29 19:04:30 gunter Exp $
28// GEANT4 tag $Name: $
29//
30//
31// ----------------------------------------------------------------------
32// class G4Timer
33//
34// Implementation
35// 29.04.97 G.Cosmo Added timings for Windows systems
36
37#include "G4Timer.hh"
38#include "G4ios.hh"
39
40#undef times
41
42// Global error function
43void G4Exception(const char* s=0);
44
45#if defined(IRIX6_2)
46# if defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE_EXTENDED==1)
47# define __vfork vfork
48# endif
49#endif
50
51#ifdef WIN32
52# include <sys/types.h>
53# include <windows.h>
54
55 // extract milliseconds time unit
56 int sysconf(int a){
57 if( a == _SC_CLK_TCK ) return 1000;
58 else return 0;
59 }
60
61 static clock_t filetime2msec( FILETIME* t ){
62
63 return (clock_t)((((float)t->dwHighDateTime)*429496.7296)+
64 (((float)t->dwLowDateTime)*.0001) );
65 }
66
67
68 clock_t times(struct tms * t){
69 FILETIME ct = {0,0}, et = {0,0}, st = {0,0}, ut = {0,0}, rt = {0,0};
70 SYSTEMTIME realtime;
71
72 GetSystemTime( &realtime );
73 SystemTimeToFileTime( &realtime, &rt ); // get real time in 10^-9 sec
74 if( t != 0 ){
75 GetProcessTimes( GetCurrentProcess(), &ct, &et, &st, &ut);// get process time in 10^-9 sec
76 t->tms_utime = t->tms_cutime = filetime2msec(&ut);
77 t->tms_stime = t->tms_cstime = filetime2msec(&st);
78 }
79 return filetime2msec(&rt);
80 }
81#endif /* WIN32 */
82
83// Print timer status n std::ostream
84std::ostream& operator << (std::ostream& os, const G4Timer& t)
85{
86 if (t.IsValid())
87 {
88 os << "User=" << t.GetUserElapsed()
89 << "s Real=" << t.GetRealElapsed()
90 << "s Sys=" << t.GetSystemElapsed() << "s";
91 }
92 else
93 {
94 os << "User=****s Real=****s Sys=****s";
95 }
96 return os;
97}
98
99G4Timer::G4Timer()
100 : fValidTimes(false)
101{
102}
103
104G4double G4Timer::GetRealElapsed() const
105{
106 if (!fValidTimes)
107 {
108 G4Exception("G4Timer::GetRealElapsed - Timer not stopped or times not recorded");
109 }
110 G4double diff=fEndRealTime-fStartRealTime;
111 return diff/sysconf(_SC_CLK_TCK);
112}
113
114
115G4double G4Timer::GetSystemElapsed() const
116{
117 if (!fValidTimes)
118 {
119 G4Exception("G4Timer::GetSystemElapsed - Timer not stopped or times not recorded");
120 }
121 G4double diff=fEndTimes.tms_stime-fStartTimes.tms_stime;
122 return diff/sysconf(_SC_CLK_TCK);
123}
124
125G4double G4Timer::GetUserElapsed() const
126{
127 if (!fValidTimes)
128 {
129 G4Exception("G4Timer::GetUserElapsed - Timer not stopped or times not recorded");
130 }
131 G4double diff=fEndTimes.tms_utime-fStartTimes.tms_utime;
132 return diff/sysconf(_SC_CLK_TCK);
133}
134
Note: See TracBrowser for help on using the repository browser.