Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v28r2p1 (f1a77ff4)
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 
61 
63  template <TimeType T>
64  inline long long adjustTime(long long timevalue);
65 
71  GAUDI_API longlong ellapsedTime(TimeType typ = milliSec, InfoType fetch = Times, long pid = -1);
79  GAUDI_API longlong kernelTime(TimeType typ = milliSec, InfoType fetch = Times, long pid = -1);
87  GAUDI_API longlong userTime(TimeType typ = milliSec, InfoType fetch = Times, long pid = -1);
95  GAUDI_API longlong cpuTime(TimeType typ = milliSec, InfoType fetch = Times, long pid = -1);
103  GAUDI_API longlong remainingTime(TimeType typ = milliSec, InfoType fetch = Quota, long pid = -1);
111  GAUDI_API longlong creationTime(TimeType typ = milliSec, InfoType fetch = Times, long pid = -1);
127  template <TimeType T>
130 
133 
138 
146  class ProcessTime {
147  public:
148  typedef long long TimeValueType;
149 
152 
154  ProcessTime(TimeValueType k, TimeValueType u, TimeValueType e):
155  i_kernel(k), i_user(u), i_elapsed(e) {}
156 
158  template <TimeType T>
159  inline TimeValueType kernelTime() const { return adjustTime<T>(i_kernel); }
160 
162  template <TimeType T>
163  inline TimeValueType userTime() const { return adjustTime<T>(i_user); }
164 
166  template <TimeType T>
167  inline TimeValueType elapsedTime() const { return adjustTime<T>(i_elapsed); }
168 
170  template <TimeType T>
171  inline TimeValueType cpuTime() const { return adjustTime<T>(i_user + i_kernel); }
172 
174  inline ProcessTime operator-(const ProcessTime &rhs) const {
175  return ProcessTime(i_kernel - rhs.i_kernel,
176  i_user - rhs.i_user,
177  i_elapsed - rhs.i_elapsed);
178  }
180  inline ProcessTime& operator+=(const ProcessTime &rhs) {
181  i_kernel += rhs.i_kernel;
182  i_user += rhs.i_user;
183  i_elapsed += rhs.i_elapsed;
184  return *this;
185  }
186  private:
188  TimeValueType i_kernel, i_user, i_elapsed;
189  };
190 
196  GAUDI_API ProcessTime getProcessTime(long pid = -1);
197 
198 }
199 
200  // implementation of the templated functions
201 namespace System {
202  template <>
203  inline long long adjustTime<Year>(long long t) {
204  return (t==-1) ? t : t /= (1LL * 365 * 24 * 60 * 60 * 1000 * 1000 * 10);
205  }
206  template <>
207  inline long long adjustTime<Day>(long long t) {
208  return (t==-1) ? t : t /= (1LL * 24 * 60 * 60 * 1000 * 1000 * 10);
209  }
210  template <>
211  inline long long adjustTime<Hour>(long long t) {
212  return (t==-1) ? t : t /= (1LL * 60 * 60 * 1000 * 1000 * 10);
213  }
214  template <>
215  inline long long adjustTime<Min>(long long t) {
216  return (t==-1) ? t : t /= (60 * 1000 * 1000 * 10);
217  }
218  template <>
219  inline long long adjustTime<Sec>(long long t) {
220  return (t==-1) ? t : t /= (1000 * 1000 * 10);
221  }
222  template <>
223  inline long long adjustTime<milliSec>(long long t) {
224  return (t==-1) ? t : t /= (1000 * 10);
225  }
226  template <>
227  inline long long adjustTime<microSec>(long long t) {
228  return (t==-1) ? t : t /= (10LL);
229  }
230  template <>
231  inline long long adjustTime<nanoSec>(long long t) {
232  return (t==-1) ? t : t *= 100LL;
233  }
234  template <>
235  inline long long adjustTime<Month>(long long t) {
236  return (t==-1) ? t : t /= (1LL * 30 * 24 * 60 * 60 * 1000 * 1000 * 10);
237  }
238  template <>
239  inline long long adjustTime<Native>(long long t) {
240  return t;
241  }
242 
243  // This is frequently used and thus we inline it if possible
244  template <TimeType T>
246 #ifdef _WIN32
247  longlong current = 0;
248  ::GetSystemTimeAsFileTime((FILETIME*)&current);
249  return adjustTime<T>(current - UNIX_BASE_TIME);
250 #else
251  struct timeval tv;
252  ::gettimeofday(&tv, 0);
253  return adjustTime<T>((tv.tv_sec*1000000 + tv.tv_usec)*10);
254 #endif
255  }
256 
257  // Define all template versions here to avoid code bloat
258  template longlong currentTime<Year >();
259  template longlong currentTime<Month >();
260  template longlong currentTime<Day >();
261  template longlong currentTime<Hour >();
262  template longlong currentTime<Min >();
263  template longlong currentTime<Sec >();
264  template longlong currentTime<milliSec>();
265  template longlong currentTime<microSec>();
266  template longlong currentTime<nanoSec >();
267  template longlong currentTime<Native >();
268 
269 }
270 
271 #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:157
template longlong currentTime< milliSec >()
template longlong currentTime< microSec >()
ProcessTime(TimeValueType k, TimeValueType u, TimeValueType e)
Constructor.
Definition: Timing.h:154
GAUDI_API longlong systemStart(TimeType typ=Sec)
Maximum processing time left for this process.
Definition: Timing.cpp:96
TimeValueType kernelTime() const
Retrieve the kernel time in the requested unit.
Definition: Timing.h:159
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:163
ProcessTime operator-(const ProcessTime &rhs) const
Return the delta between two ProcessTime objects.
Definition: Timing.h:174
GAUDI_API longlong cpuTime(TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
Consumed CPU time of process in milliseconds.
Definition: Timing.cpp:167
long long adjustTime< Native >(long long t)
Definition: Timing.h:239
ProcessTime()
Constructor.
Definition: Timing.h:151
long long adjustTime< Month >(long long t)
Definition: Timing.h:235
GAUDI_API longlong ellapsedTime(TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
Elapsed time since start of process in milliseconds.
Definition: Timing.cpp:138
GAUDI_API longlong upTime(TimeType typ=Hour)
Maximum processing time left for this process.
Definition: Timing.cpp:107
TimeValueType i_kernel
Internal storage.
Definition: Timing.h:188
long long adjustTime< nanoSec >(long long t)
Definition: Timing.h:231
GAUDI_API longlong tickCount()
Retrieve the number of ticks since system startup.
Definition: Timing.cpp:65
long long adjustTime< Day >(long long t)
Definition: Timing.h:207
GAUDI_API longlong creationTime(TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
Process Creation time.
Definition: Timing.cpp:113
TimeType
Time type for conversion.
Definition: Timing.h:57
GAUDI_API longlong remainingTime(TimeType typ=milliSec, InfoType fetch=Quota, long pid=-1)
Maximum processing time left for this process.
Definition: Timing.cpp:123
template longlong currentTime< Native >()
template longlong currentTime< nanoSec >()
TimeValueType i_user
Definition: Timing.h:188
GAUDI_API longlong kernelTime(TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
CPU kernel mode time of process in milliseconds.
Definition: Timing.cpp:147
long long adjustTime< milliSec >(long long t)
Definition: Timing.h:223
long long adjustTime< Year >(long long t)
Definition: Timing.h:203
Simple class to hold the time information of a process.
Definition: Timing.h:146
long long adjustTime< microSec >(long long t)
Definition: Timing.h:227
GAUDI_API longlong currentTime()
Retrieve absolute system time.
Definition: Timing.h:245
long long adjustTime< Min >(long long t)
Definition: Timing.h:215
long long TimeValueType
Definition: Timing.h:148
TimeValueType i_elapsed
Definition: Timing.h:188
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:167
GAUDI_API ProcessTime getProcessTime(long pid=-1)
Retrieve the process time data for a process.
Definition: Timing.cpp:177
long long adjustTime< Hour >(long long t)
Definition: Timing.h:211
TimeValueType cpuTime() const
Retrieve the CPU (user+kernel) time in the requested unit.
Definition: Timing.h:171
ProcessTime & operator+=(const ProcessTime &rhs)
Add the timings to the current objects.
Definition: Timing.h:180
long long adjustTime< Sec >(long long t)
Definition: Timing.h:219
#define GAUDI_API
Definition: Kernel.h:107
InfoType
Enumeration for fetching information.
Definition: SystemBase.h:18