| The Gaudi Framework v32r1 (f65d50dc)

Timing.h
Go to the documentation of this file.
1 //====================================================================
2 // Timing.h
3 //--------------------------------------------------------------------
4 //
5 // Package : Gaudi/System (The LHCb System service)
6 //
7 // Description: Definition of Systems internals
8 //
9 // Author : M.Frank
10 // Created : 13/1/99
11 //====================================================================
12 #ifndef GAUDIKERNEL_TIMING_H
13 #define GAUDIKERNEL_TIMING_H
14
15 // Framework include files
16 #include "GaudiKernel/Kernel.h"
17 #include "GaudiKernel/SystemBase.h"
18
19 #ifdef _WIN32
20 # include <windows.h>
21 #else
22 # include <sys/time.h>
23 #endif
24
55 namespace System {
57 enum TimeType { Year, Month, Day, Hour, Min, Sec, milliSec, microSec, nanoSec, Native };
58
60 GAUDI_API long long adjustTime( TimeType typ, long long timevalue );
61
63 template <TimeType T>
64 inline long long adjustTime( long long timevalue );
65
71 GAUDI_API long long ellapsedTime( TimeType typ = milliSec, InfoType fetch = Times, long pid = -1 );
79 GAUDI_API long long kernelTime( TimeType typ = milliSec, InfoType fetch = Times, long pid = -1 );
87 GAUDI_API long long userTime( TimeType typ = milliSec, InfoType fetch = Times, long pid = -1 );
95 GAUDI_API long long cpuTime( TimeType typ = milliSec, InfoType fetch = Times, long pid = -1 );
103 GAUDI_API long long remainingTime( TimeType typ = milliSec, InfoType fetch = Quota, long pid = -1 );
111 GAUDI_API long long creationTime( TimeType typ = milliSec, InfoType fetch = Times, long pid = -1 );
116 GAUDI_API long long systemStart( TimeType typ = Sec );
121 GAUDI_API long long upTime( TimeType typ = Hour );
127 template <TimeType T>
129 GAUDI_API long long currentTime();
130
132 GAUDI_API long long currentTime( TimeType typ = milliSec );
133
137 GAUDI_API long long tickCount();
138
146 class ProcessTime {
147 public:
148 typedef long long TimeValueType;
149
151 ProcessTime() : i_kernel( 0 ), i_user( 0 ), i_elapsed( 0 ) {}
152
154 ProcessTime( TimeValueType k, TimeValueType u, TimeValueType e ) : i_kernel( k ), i_user( u ), i_elapsed( e ) {}
155
157 template <TimeType T>
158 inline TimeValueType kernelTime() const {
159 return adjustTime<T>( i_kernel );
160 }
161
163 template <TimeType T>
164 inline TimeValueType userTime() const {
165 return adjustTime<T>( i_user );
166 }
167
169 template <TimeType T>
170 inline TimeValueType elapsedTime() const {
171 return adjustTime<T>( i_elapsed );
172 }
173
175 template <TimeType T>
176 inline TimeValueType cpuTime() const {
177 return adjustTime<T>( i_user + i_kernel );
178 }
179
181 inline ProcessTime operator-( const ProcessTime& rhs ) const {
182 return ProcessTime( i_kernel - rhs.i_kernel, i_user - rhs.i_user, i_elapsed - rhs.i_elapsed );
183 }
185 inline ProcessTime& operator+=( const ProcessTime& rhs ) {
186 i_kernel += rhs.i_kernel;
187 i_user += rhs.i_user;
188 i_elapsed += rhs.i_elapsed;
189 return *this;
190 }
191
192 private:
194 TimeValueType i_kernel, i_user, i_elapsed;
195 };
196
202 GAUDI_API ProcessTime getProcessTime( long pid = -1 );
203 } // namespace System
204
205 // implementation of the templated functions
206 namespace System {
207 template <>
208 inline long long adjustTime<Year>( long long t ) {
209 return ( t == -1 ) ? t : t /= ( 1LL * 365 * 24 * 60 * 60 * 1000 * 1000 * 10 );
210 }
211 template <>
212 inline long long adjustTime<Day>( long long t ) {
213 return ( t == -1 ) ? t : t /= ( 1LL * 24 * 60 * 60 * 1000 * 1000 * 10 );
214 }
215 template <>
216 inline long long adjustTime<Hour>( long long t ) {
217 return ( t == -1 ) ? t : t /= ( 1LL * 60 * 60 * 1000 * 1000 * 10 );
218 }
219 template <>
220 inline long long adjustTime<Min>( long long t ) {
221 return ( t == -1 ) ? t : t /= ( 60 * 1000 * 1000 * 10 );
222 }
223 template <>
224 inline long long adjustTime<Sec>( long long t ) {
225 return ( t == -1 ) ? t : t /= ( 1000 * 1000 * 10 );
226 }
227 template <>
228 inline long long adjustTime<milliSec>( long long t ) {
229 return ( t == -1 ) ? t : t /= ( 1000 * 10 );
230 }
231 template <>
232 inline long long adjustTime<microSec>( long long t ) {
233 return ( t == -1 ) ? t : t /= ( 10LL );
234 }
235 template <>
236 inline long long adjustTime<nanoSec>( long long t ) {
237 return ( t == -1 ) ? t : t *= 100LL;
238 }
239 template <>
240 inline long long adjustTime<Month>( long long t ) {
241 return ( t == -1 ) ? t : t /= ( 1LL * 30 * 24 * 60 * 60 * 1000 * 1000 * 10 );
242 }
243 template <>
244 inline long long adjustTime<Native>( long long t ) {
245 return t;
246 }
247
248 // This is frequently used and thus we inline it if possible
249 template <TimeType T>
250 inline long long currentTime() {
251 #ifdef _WIN32
252 long long current = 0;
253 ::GetSystemTimeAsFileTime( (FILETIME*)&current );
254 return adjustTime<T>( current - UNIX_BASE_TIME );
255 #else
256 struct timeval tv;
257 ::gettimeofday( &tv, 0 );
258 return adjustTime<T>( ( tv.tv_sec * 1000000 + tv.tv_usec ) * 10 );
259 #endif
260 }
261
262 // Define all template versions here to avoid code bloat
263 template long long currentTime<Year>();
264 template long long currentTime<Month>();
265 template long long currentTime<Day>();
266 template long long currentTime<Hour>();
267 template long long currentTime<Min>();
268 template long long currentTime<Sec>();
269 template long long currentTime<milliSec>();
270 template long long currentTime<microSec>();
271 template long long currentTime<nanoSec>();
272 template long long currentTime<Native>();
273 } // namespace System
274
275 #endif // GAUDIKERNEL_TIMING_H
System::creationTime
GAUDI_API long long creationTime(TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
Process Creation time.
Definition: Timing.cpp:135
System::ProcessTime::userTime
TimeValueType userTime() const
Retrieve the user time in the requested unit.
Definition: Timing.h:164
Kernel.h
System::ProcessTime::ProcessTime
ProcessTime(TimeValueType k, TimeValueType u, TimeValueType e)
Constructor.
Definition: Timing.h:154
System::currentTime< Month >
template long long currentTime< Month >()
System::Min
Definition: Timing.h:57
System
Note: OS specific details for environment resolution.
Definition: Debugger.h:19
System::Times
Definition: SystemBase.h:18
System::currentTime< Year >
template long long currentTime< Year >()
System::ProcessTime::elapsedTime
TimeValueType elapsedTime() const
Retrieve the elapsed time in the requested unit.
Definition: Timing.h:170
System::adjustTime< Native >
long long adjustTime< Native >(long long t)
Definition: Timing.h:244
System::Hour
Definition: Timing.h:57
System::ProcessTime::ProcessTime
ProcessTime()
Constructor.
Definition: Timing.h:151
System::adjustTime< Month >
long long adjustTime< Month >(long long t)
Definition: Timing.h:240
System::milliSec
Definition: Timing.h:57
System::currentTime< Hour >
template long long currentTime< Hour >()
System::remainingTime
GAUDI_API long long remainingTime(TimeType typ=milliSec, InfoType fetch=Quota, long pid=-1)
Maximum processing time left for this process.
Definition: Timing.cpp:145
System::ProcessTime::i_kernel
TimeValueType i_kernel
Internal storage.
Definition: Timing.h:194
System::Sec
Definition: Timing.h:57
System::ProcessTime::operator-
ProcessTime operator-(const ProcessTime &rhs) const
Return the delta between two ProcessTime objects.
Definition: Timing.h:181
System::ProcessTime::kernelTime
TimeValueType kernelTime() const
Retrieve the kernel time in the requested unit.
Definition: Timing.h:158
System::adjustTime< nanoSec >
long long adjustTime< nanoSec >(long long t)
Definition: Timing.h:236
System::currentTime
GAUDI_API long long currentTime()
Retrieve absolute system time.
Definition: Timing.h:250
System::microSec
Definition: Timing.h:57
System::adjustTime< Day >
long long adjustTime< Day >(long long t)
Definition: Timing.h:212
System::TimeType
TimeType
Time type for conversion.
Definition: Timing.h:57
System::kernelTime
GAUDI_API long long kernelTime(TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
CPU kernel mode time of process in milliseconds.
Definition: Timing.cpp:168
System::Native
Definition: Timing.h:57
System::userTime
GAUDI_API long long userTime(TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
CPU user mode time of process in milliseconds.
Definition: Timing.cpp:178
System::Quota
Definition: SystemBase.h:18
System::ProcessTime::i_user
TimeValueType i_user
Definition: Timing.h:194
System::adjustTime< milliSec >
long long adjustTime< milliSec >(long long t)
Definition: Timing.h:228
System::adjustTime< Year >
long long adjustTime< Year >(long long t)
Definition: Timing.h:208
System::ProcessTime
Simple class to hold the time information of a process.
Definition: Timing.h:146
System::adjustTime< microSec >
long long adjustTime< microSec >(long long t)
Definition: Timing.h:232
System::ellapsedTime
GAUDI_API long long ellapsedTime(TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
Elapsed time since start of process in milliseconds.
Definition: Timing.cpp:159
System::cpuTime
GAUDI_API long long cpuTime(TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
Consumed CPU time of process in milliseconds.
Definition: Timing.cpp:186
System::tickCount
GAUDI_API long long tickCount()
Retrieve the number of ticks since system startup.
Definition: Timing.cpp:77
System::upTime
GAUDI_API long long upTime(TimeType typ=Hour)
Maximum processing time left for this process.
Definition: Timing.cpp:129
System::adjustTime< Min >
long long adjustTime< Min >(long long t)
Definition: Timing.h:220
System::currentTime< Sec >
template long long currentTime< Sec >()
System::Month
Definition: Timing.h:57
System::currentTime< Min >
template long long currentTime< Min >()
System::currentTime< Native >
template long long currentTime< Native >()
System::ProcessTime::TimeValueType
long long TimeValueType
Definition: Timing.h:148
System::currentTime< milliSec >
template long long currentTime< milliSec >()
System::ProcessTime::i_elapsed
TimeValueType i_elapsed
Definition: Timing.h:194
System::currentTime< Day >
template long long currentTime< Day >()
System::nanoSec
Definition: Timing.h:57
System::ProcessTime::cpuTime
TimeValueType cpuTime() const
Retrieve the CPU (user+kernel) time in the requested unit.
Definition: Timing.h:176
System::adjustTime
GAUDI_API long long adjustTime(TimeType typ, long long timevalue)
Convert time from OS native time to requested representation (Experts only)
Definition: Timing.cpp:37
System::getProcessTime
GAUDI_API ProcessTime getProcessTime(long pid=-1)
Retrieve the process time data for a process.
Definition: Timing.cpp:196
System::adjustTime< Hour >
long long adjustTime< Hour >(long long t)
Definition: Timing.h:216
System::currentTime< nanoSec >
template long long currentTime< nanoSec >()
System::ProcessTime::operator+=
ProcessTime & operator+=(const ProcessTime &rhs)
Add the timings to the current objects.
Definition: Timing.h:185
System::Year
Definition: Timing.h:57
System::adjustTime< Sec >
long long adjustTime< Sec >(long long t)
Definition: Timing.h:224
System::currentTime< microSec >
template long long currentTime< microSec >()
SystemBase.h
System::systemStart
GAUDI_API long long systemStart(TimeType typ=Sec)
Maximum processing time left for this process.
Definition: Timing.cpp:118
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:71
System::InfoType
InfoType
Enumeration for fetching information.
Definition: SystemBase.h:18
System::Day
Definition: Timing.h:57