| The Gaudi Framework v30r0 (c919700c)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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
56 {
58 enum TimeType { Year, Month, Day, Hour, Min, Sec, milliSec, microSec, nanoSec, Native };
59
61 GAUDI_API longlong adjustTime( TimeType typ, longlong timevalue );
62
64 template <TimeType T>
65 inline long long adjustTime( long long timevalue );
66
72 GAUDI_API longlong ellapsedTime( TimeType typ = milliSec, InfoType fetch = Times, long pid = -1 );
80 GAUDI_API longlong kernelTime( TimeType typ = milliSec, InfoType fetch = Times, long pid = -1 );
88 GAUDI_API longlong userTime( TimeType typ = milliSec, InfoType fetch = Times, long pid = -1 );
96 GAUDI_API longlong cpuTime( TimeType typ = milliSec, InfoType fetch = Times, long pid = -1 );
104 GAUDI_API longlong remainingTime( TimeType typ = milliSec, InfoType fetch = Quota, long pid = -1 );
112 GAUDI_API longlong creationTime( TimeType typ = milliSec, InfoType fetch = Times, long pid = -1 );
117 GAUDI_API longlong systemStart( TimeType typ = Sec );
122 GAUDI_API longlong upTime( TimeType typ = Hour );
128 template <TimeType T>
130 GAUDI_API longlong currentTime();
131
133 GAUDI_API longlong currentTime( TimeType typ = milliSec );
134
138 GAUDI_API longlong tickCount();
139
147 class ProcessTime
148 {
149 public:
150 typedef long long TimeValueType;
151
153 ProcessTime() : i_kernel( 0 ), i_user( 0 ), i_elapsed( 0 ) {}
154
156 ProcessTime( TimeValueType k, TimeValueType u, TimeValueType e ) : i_kernel( k ), i_user( u ), i_elapsed( e ) {}
157
159 template <TimeType T>
160 inline TimeValueType kernelTime() const
161 {
162 return adjustTime<T>( i_kernel );
163 }
164
166 template <TimeType T>
167 inline TimeValueType userTime() const
168 {
169 return adjustTime<T>( i_user );
170 }
171
173 template <TimeType T>
174 inline TimeValueType elapsedTime() const
175 {
176 return adjustTime<T>( i_elapsed );
177 }
178
180 template <TimeType T>
181 inline TimeValueType cpuTime() const
182 {
183 return adjustTime<T>( i_user + i_kernel );
184 }
185
187 inline ProcessTime operator-( const ProcessTime& rhs ) const
188 {
189 return ProcessTime( i_kernel - rhs.i_kernel, i_user - rhs.i_user, i_elapsed - rhs.i_elapsed );
190 }
192 inline ProcessTime& operator+=( const ProcessTime& rhs )
193 {
194 i_kernel += rhs.i_kernel;
195 i_user += rhs.i_user;
196 i_elapsed += rhs.i_elapsed;
197 return *this;
198 }
199
200 private:
202 TimeValueType i_kernel, i_user, i_elapsed;
203 };
204
210 GAUDI_API ProcessTime getProcessTime( long pid = -1 );
211 }
212
213 // implementation of the templated functions
214 namespace System
215 {
216 template <>
217 inline long long adjustTime<Year>( long long t )
218 {
219 return ( t == -1 ) ? t : t /= ( 1LL * 365 * 24 * 60 * 60 * 1000 * 1000 * 10 );
220 }
221 template <>
222 inline long long adjustTime<Day>( long long t )
223 {
224 return ( t == -1 ) ? t : t /= ( 1LL * 24 * 60 * 60 * 1000 * 1000 * 10 );
225 }
226 template <>
227 inline long long adjustTime<Hour>( long long t )
228 {
229 return ( t == -1 ) ? t : t /= ( 1LL * 60 * 60 * 1000 * 1000 * 10 );
230 }
231 template <>
232 inline long long adjustTime<Min>( long long t )
233 {
234 return ( t == -1 ) ? t : t /= ( 60 * 1000 * 1000 * 10 );
235 }
236 template <>
237 inline long long adjustTime<Sec>( long long t )
238 {
239 return ( t == -1 ) ? t : t /= ( 1000 * 1000 * 10 );
240 }
241 template <>
242 inline long long adjustTime<milliSec>( long long t )
243 {
244 return ( t == -1 ) ? t : t /= ( 1000 * 10 );
245 }
246 template <>
247 inline long long adjustTime<microSec>( long long t )
248 {
249 return ( t == -1 ) ? t : t /= ( 10LL );
250 }
251 template <>
252 inline long long adjustTime<nanoSec>( long long t )
253 {
254 return ( t == -1 ) ? t : t *= 100LL;
255 }
256 template <>
257 inline long long adjustTime<Month>( long long t )
258 {
259 return ( t == -1 ) ? t : t /= ( 1LL * 30 * 24 * 60 * 60 * 1000 * 1000 * 10 );
260 }
261 template <>
262 inline long long adjustTime<Native>( long long t )
263 {
264 return t;
265 }
266
267 // This is frequently used and thus we inline it if possible
268 template <TimeType T>
269 inline longlong currentTime()
270 {
271 #ifdef _WIN32
272 longlong current = 0;
273 ::GetSystemTimeAsFileTime( (FILETIME*)&current );
274 return adjustTime<T>( current - UNIX_BASE_TIME );
275 #else
276 struct timeval tv;
277 ::gettimeofday( &tv, 0 );
278 return adjustTime<T>( ( tv.tv_sec * 1000000 + tv.tv_usec ) * 10 );
279 #endif
280 }
281
282 // Define all template versions here to avoid code bloat
283 template longlong currentTime<Year>();
284 template longlong currentTime<Month>();
285 template longlong currentTime<Day>();
286 template longlong currentTime<Hour>();
287 template longlong currentTime<Min>();
288 template longlong currentTime<Sec>();
289 template longlong currentTime<milliSec>();
290 template longlong currentTime<microSec>();
291 template longlong currentTime<nanoSec>();
292 template longlong currentTime<Native>();
293 }
294
295 #endif // GAUDIKERNEL_TIMING_H
System::userTime
GAUDI_API longlong userTime(TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
CPU user mode time of process in milliseconds.
Definition: Timing.cpp:185
System::currentTime< milliSec >
template longlong currentTime< milliSec >()
Kernel.h
System::currentTime< microSec >
template longlong currentTime< microSec >()
System::ProcessTime::ProcessTime
ProcessTime(TimeValueType k, TimeValueType u, TimeValueType e)
Constructor.
Definition: Timing.h:156
System::currentTime< Min >
template longlong currentTime< Min >()
System::systemStart
GAUDI_API longlong systemStart(TimeType typ=Sec)
Maximum processing time left for this process.
Definition: Timing.cpp:119
System::currentTime< Month >
template longlong currentTime< Month >()
System::ProcessTime::kernelTime
TimeValueType kernelTime() const
Retrieve the kernel time in the requested unit.
Definition: Timing.h:160
System::Min
Definition: Timing.h:58
System
Note: OS specific details for environment resolution.
Definition: Debugger.h:19
System::Times
Definition: SystemBase.h:19
System::ProcessTime::userTime
TimeValueType userTime() const
Retrieve the user time in the requested unit.
Definition: Timing.h:167
System::ProcessTime::operator-
ProcessTime operator-(const ProcessTime &rhs) const
Return the delta between two ProcessTime objects.
Definition: Timing.h:187
System::cpuTime
GAUDI_API longlong cpuTime(TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
Consumed CPU time of process in milliseconds.
Definition: Timing.cpp:196
System::adjustTime< Native >
long long adjustTime< Native >(long long t)
Definition: Timing.h:262
System::Hour
Definition: Timing.h:58
System::ProcessTime::ProcessTime
ProcessTime()
Constructor.
Definition: Timing.h:153
System::adjustTime< Month >
long long adjustTime< Month >(long long t)
Definition: Timing.h:257
System::ellapsedTime
GAUDI_API longlong ellapsedTime(TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
Elapsed time since start of process in milliseconds.
Definition: Timing.cpp:164
System::milliSec
Definition: Timing.h:58
System::upTime
GAUDI_API longlong upTime(TimeType typ=Hour)
Maximum processing time left for this process.
Definition: Timing.cpp:131
System::ProcessTime::i_kernel
TimeValueType i_kernel
Internal storage.
Definition: Timing.h:202
System::Sec
Definition: Timing.h:58
System::adjustTime< nanoSec >
long long adjustTime< nanoSec >(long long t)
Definition: Timing.h:252
System::tickCount
GAUDI_API longlong tickCount()
Retrieve the number of ticks since system startup.
Definition: Timing.cpp:76
System::microSec
Definition: Timing.h:58
System::adjustTime< Day >
long long adjustTime< Day >(long long t)
Definition: Timing.h:222
__longlong
Definition: Kernel.h:56
System::creationTime
GAUDI_API longlong creationTime(TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
Process Creation time.
Definition: Timing.cpp:138
System::currentTime< Hour >
template longlong currentTime< Hour >()
System::TimeType
TimeType
Time type for conversion.
Definition: Timing.h:58
System::remainingTime
GAUDI_API longlong remainingTime(TimeType typ=milliSec, InfoType fetch=Quota, long pid=-1)
Maximum processing time left for this process.
Definition: Timing.cpp:149
System::currentTime< Day >
template longlong currentTime< Day >()
System::currentTime< Native >
template longlong currentTime< Native >()
System::Native
Definition: Timing.h:58
System::Quota
Definition: SystemBase.h:19
System::currentTime< nanoSec >
template longlong currentTime< nanoSec >()
System::ProcessTime::i_user
TimeValueType i_user
Definition: Timing.h:202
System::kernelTime
GAUDI_API longlong kernelTime(TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
CPU kernel mode time of process in milliseconds.
Definition: Timing.cpp:174
System::adjustTime< milliSec >
long long adjustTime< milliSec >(long long t)
Definition: Timing.h:242
System::adjustTime< Year >
long long adjustTime< Year >(long long t)
Definition: Timing.h:217
System::ProcessTime
Simple class to hold the time information of a process.
Definition: Timing.h:147
System::adjustTime< microSec >
long long adjustTime< microSec >(long long t)
Definition: Timing.h:247
System::currentTime
GAUDI_API longlong currentTime()
Retrieve absolute system time.
Definition: Timing.h:269
System::adjustTime< Min >
long long adjustTime< Min >(long long t)
Definition: Timing.h:232
System::Month
Definition: Timing.h:58
System::currentTime< Sec >
template longlong currentTime< Sec >()
System::ProcessTime::TimeValueType
long long TimeValueType
Definition: Timing.h:150
System::ProcessTime::i_elapsed
TimeValueType i_elapsed
Definition: Timing.h:202
System::nanoSec
Definition: Timing.h:58
System::adjustTime
GAUDI_API longlong adjustTime(TimeType typ, longlong timevalue)
Convert time from OS native time to requested representation (Experts only)
Definition: Timing.cpp:37
System::ProcessTime::elapsedTime
TimeValueType elapsedTime() const
Retrieve the elapsed time in the requested unit.
Definition: Timing.h:174
System::getProcessTime
GAUDI_API ProcessTime getProcessTime(long pid=-1)
Retrieve the process time data for a process.
Definition: Timing.cpp:208
System::adjustTime< Hour >
long long adjustTime< Hour >(long long t)
Definition: Timing.h:227
System::ProcessTime::cpuTime
TimeValueType cpuTime() const
Retrieve the CPU (user+kernel) time in the requested unit.
Definition: Timing.h:181
System::ProcessTime::operator+=
ProcessTime & operator+=(const ProcessTime &rhs)
Add the timings to the current objects.
Definition: Timing.h:192
System::Year
Definition: Timing.h:58
System::adjustTime< Sec >
long long adjustTime< Sec >(long long t)
Definition: Timing.h:237
System::currentTime< Year >
template longlong currentTime< Year >()
SystemBase.h
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:110
System::InfoType
InfoType
Enumeration for fetching information.
Definition: SystemBase.h:19
System::Day
Definition: Timing.h:58