Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 {
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
GAUDI_API long long creationTime(TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
Process Creation time.
Definition: Timing.cpp:135
ProcessTime(TimeValueType k, TimeValueType u, TimeValueType e)
Constructor.
Definition: Timing.h:154
template long long currentTime< Month >()
TimeValueType kernelTime() const
Retrieve the kernel time in the requested unit.
Definition: Timing.h:158
Note: OS specific details for environment resolution.
Definition: Debugger.h:19
template long long currentTime< Year >()
TimeValueType userTime() const
Retrieve the user time in the requested unit.
Definition: Timing.h:164
ProcessTime operator-(const ProcessTime &rhs) const
Return the delta between two ProcessTime objects.
Definition: Timing.h:181
long long adjustTime< Native >(long long t)
Definition: Timing.h:244
ProcessTime()
Constructor.
Definition: Timing.h:151
long long adjustTime< Month >(long long t)
Definition: Timing.h:240
template long long currentTime< Hour >()
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
TimeValueType i_kernel
Internal storage.
Definition: Timing.h:194
long long adjustTime< nanoSec >(long long t)
Definition: Timing.h:236
GAUDI_API long long currentTime()
Retrieve absolute system time.
Definition: Timing.h:250
long long adjustTime< Day >(long long t)
Definition: Timing.h:212
TimeType
Time type for conversion.
Definition: Timing.h:57
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
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
TimeValueType i_user
Definition: Timing.h:194
long long adjustTime< milliSec >(long long t)
Definition: Timing.h:228
long long adjustTime< Year >(long long t)
Definition: Timing.h:208
Simple class to hold the time information of a process.
Definition: Timing.h:146
long long adjustTime< microSec >(long long t)
Definition: Timing.h:232
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
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
GAUDI_API long long tickCount()
Retrieve the number of ticks since system startup.
Definition: Timing.cpp:77
GAUDI_API long long upTime(TimeType typ=Hour)
Maximum processing time left for this process.
Definition: Timing.cpp:129
long long adjustTime< Min >(long long t)
Definition: Timing.h:220
template long long currentTime< Sec >()
template long long currentTime< Min >()
template long long currentTime< Native >()
long long TimeValueType
Definition: Timing.h:148
template long long currentTime< milliSec >()
TimeValueType i_elapsed
Definition: Timing.h:194
template long long currentTime< Day >()
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
TimeValueType elapsedTime() const
Retrieve the elapsed time in the requested unit.
Definition: Timing.h:170
GAUDI_API ProcessTime getProcessTime(long pid=-1)
Retrieve the process time data for a process.
Definition: Timing.cpp:196
long long adjustTime< Hour >(long long t)
Definition: Timing.h:216
TimeValueType cpuTime() const
Retrieve the CPU (user+kernel) time in the requested unit.
Definition: Timing.h:176
template long long currentTime< nanoSec >()
ProcessTime & operator+=(const ProcessTime &rhs)
Add the timings to the current objects.
Definition: Timing.h:185
long long adjustTime< Sec >(long long t)
Definition: Timing.h:224
template long long currentTime< microSec >()
GAUDI_API long long systemStart(TimeType typ=Sec)
Maximum processing time left for this process.
Definition: Timing.cpp:118
#define GAUDI_API
Definition: Kernel.h:71
InfoType
Enumeration for fetching information.
Definition: SystemBase.h:18