The Gaudi Framework  v30r3 (a5ef0a68)
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 {
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 );
128  template <TimeType T>
131 
134 
139 
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>
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
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
template longlong currentTime< milliSec >()
template longlong currentTime< microSec >()
ProcessTime(TimeValueType k, TimeValueType u, TimeValueType e)
Constructor.
Definition: Timing.h:156
template longlong currentTime< Min >()
GAUDI_API longlong systemStart(TimeType typ=Sec)
Maximum processing time left for this process.
Definition: Timing.cpp:119
template longlong currentTime< Month >()
TimeValueType kernelTime() const
Retrieve the kernel time in the requested unit.
Definition: Timing.h:160
Note: OS specific details for environment resolution.
Definition: Debugger.h:19
TimeValueType userTime() const
Retrieve the user time in the requested unit.
Definition: Timing.h:167
ProcessTime operator-(const ProcessTime &rhs) const
Return the delta between two ProcessTime objects.
Definition: Timing.h:187
GAUDI_API longlong cpuTime(TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
Consumed CPU time of process in milliseconds.
Definition: Timing.cpp:196
long long adjustTime< Native >(long long t)
Definition: Timing.h:262
ProcessTime()
Constructor.
Definition: Timing.h:153
long long adjustTime< Month >(long long t)
Definition: Timing.h:257
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
GAUDI_API longlong upTime(TimeType typ=Hour)
Maximum processing time left for this process.
Definition: Timing.cpp:131
TimeValueType i_kernel
Internal storage.
Definition: Timing.h:202
long long adjustTime< nanoSec >(long long t)
Definition: Timing.h:252
GAUDI_API longlong tickCount()
Retrieve the number of ticks since system startup.
Definition: Timing.cpp:76
long long adjustTime< Day >(long long t)
Definition: Timing.h:222
GAUDI_API longlong creationTime(TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
Process Creation time.
Definition: Timing.cpp:138
template longlong currentTime< Hour >()
TimeType
Time type for conversion.
Definition: Timing.h:58
GAUDI_API longlong remainingTime(TimeType typ=milliSec, InfoType fetch=Quota, long pid=-1)
Maximum processing time left for this process.
Definition: Timing.cpp:149
template longlong currentTime< Day >()
template longlong currentTime< Native >()
template longlong currentTime< nanoSec >()
TimeValueType i_user
Definition: Timing.h:202
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
long long adjustTime< milliSec >(long long t)
Definition: Timing.h:242
long long adjustTime< Year >(long long t)
Definition: Timing.h:217
Simple class to hold the time information of a process.
Definition: Timing.h:147
long long adjustTime< microSec >(long long t)
Definition: Timing.h:247
GAUDI_API longlong currentTime()
Retrieve absolute system time.
Definition: Timing.h:269
long long adjustTime< Min >(long long t)
Definition: Timing.h:232
template longlong currentTime< Sec >()
long long TimeValueType
Definition: Timing.h:150
TimeValueType i_elapsed
Definition: Timing.h:202
GAUDI_API longlong adjustTime(TimeType typ, longlong timevalue)
Convert time from OS native time to requested representation (Experts only)
Definition: Timing.cpp:37
TimeValueType elapsedTime() const
Retrieve the elapsed time in the requested unit.
Definition: Timing.h:174
GAUDI_API ProcessTime getProcessTime(long pid=-1)
Retrieve the process time data for a process.
Definition: Timing.cpp:208
long long adjustTime< Hour >(long long t)
Definition: Timing.h:227
TimeValueType cpuTime() const
Retrieve the CPU (user+kernel) time in the requested unit.
Definition: Timing.h:181
ProcessTime & operator+=(const ProcessTime &rhs)
Add the timings to the current objects.
Definition: Timing.h:192
long long adjustTime< Sec >(long long t)
Definition: Timing.h:237
template longlong currentTime< Year >()
#define GAUDI_API
Definition: Kernel.h:104
InfoType
Enumeration for fetching information.
Definition: SystemBase.h:19