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 
49 namespace System {
52 
55 
57  template <TimeType T>
58  inline long long adjustTime(long long timevalue);
59 
65  GAUDI_API longlong ellapsedTime(TimeType typ = milliSec, InfoType fetch = Times, long pid = -1);
73  GAUDI_API longlong kernelTime(TimeType typ = milliSec, InfoType fetch = Times, long pid = -1);
81  GAUDI_API longlong userTime(TimeType typ = milliSec, InfoType fetch = Times, long pid = -1);
89  GAUDI_API longlong cpuTime(TimeType typ = milliSec, InfoType fetch = Times, long pid = -1);
97  GAUDI_API longlong remainingTime(TimeType typ = milliSec, InfoType fetch = Quota, long pid = -1);
105  GAUDI_API longlong creationTime(TimeType typ = milliSec, InfoType fetch = Times, long pid = -1);
125 
133  class ProcessTime {
134  public:
135  typedef long long TimeValueType;
136 
138  ProcessTime(): i_kernel(0), i_user(0), i_elapsed(0) {}
139 
141  ProcessTime(TimeValueType k, TimeValueType u, TimeValueType e):
142  i_kernel(k), i_user(u), i_elapsed(e) {}
143 
145  template <TimeType T>
146  inline TimeValueType kernelTime() const { return adjustTime<T>(i_kernel); }
147 
149  template <TimeType T>
150  inline TimeValueType userTime() const { return adjustTime<T>(i_user); }
151 
153  template <TimeType T>
154  inline TimeValueType elapsedTime() const { return adjustTime<T>(i_elapsed); }
155 
157  template <TimeType T>
158  inline TimeValueType cpuTime() const { return adjustTime<T>(i_user + i_kernel); }
159 
161  inline ProcessTime operator-(const ProcessTime &rhs) const {
162  return ProcessTime(i_kernel - rhs.i_kernel,
163  i_user - rhs.i_user,
164  i_elapsed - rhs.i_elapsed);
165  }
167  inline ProcessTime& operator+=(const ProcessTime &rhs) {
168  i_kernel += rhs.i_kernel;
169  i_user += rhs.i_user;
170  i_elapsed += rhs.i_elapsed;
171  return *this;
172  }
173  private:
175  TimeValueType i_kernel, i_user, i_elapsed;
176  };
177 
183  GAUDI_API ProcessTime getProcessTime(long pid = -1);
184 
185 }
186 
187 // implementation of the templated adjustTime
188 namespace System {
189  template <>
190  inline long long adjustTime<Year>(long long t) {
191  return (t==-1) ? t : t /= (1LL * 365 * 24 * 60 * 60 * 1000 * 1000 * 10);
192  }
193  template <>
194  inline long long adjustTime<Day>(long long t) {
195  return (t==-1) ? t : t /= (1LL * 24 * 60 * 60 * 1000 * 1000 * 10);
196  }
197  template <>
198  inline long long adjustTime<Hour>(long long t) {
199  return (t==-1) ? t : t /= (1LL * 60 * 60 * 1000 * 1000 * 10);
200  }
201  template <>
202  inline long long adjustTime<Min>(long long t) {
203  return (t==-1) ? t : t /= (60 * 1000 * 1000 * 10);
204  }
205  template <>
206  inline long long adjustTime<Sec>(long long t) {
207  return (t==-1) ? t : t /= (1000 * 1000 * 10);
208  }
209  template <>
210  inline long long adjustTime<milliSec>(long long t) {
211  return (t==-1) ? t : t /= (1000 * 10);
212  }
213  template <>
214  inline long long adjustTime<microSec>(long long t) {
215  return (t==-1) ? t : t /= (10LL);
216  }
217  template <>
218  inline long long adjustTime<nanoSec>(long long t) {
219  return (t==-1) ? t : t *= 100LL;
220  }
221  template <>
222  inline long long adjustTime<Month>(long long t) {
223  return (t==-1) ? t : t /= (1LL * 30 * 24 * 60 * 60 * 1000 * 1000 * 10);
224  }
225  template <>
226  inline long long adjustTime<Native>(long long t) {
227  return t;
228  }
229 }
230 
231 #endif // GAUDIKERNEL_TIMING_H
GAUDI_API ProcessTime getProcessTime(long pid=-1)
Retrieve the process time data for a process.
Definition: Timing.cpp:178
#define GAUDI_API
Definition: Kernel.h:107
TimeValueType kernelTime() const
Retrieve the kernel time in the requested unit.
Definition: Timing.h:146
Note: OS specific details for environment resolution.
Definition: Debugger.h:19
GAUDI_API longlong remainingTime(TimeType typ=milliSec, InfoType fetch=Quota, long pid=-1)
Maximum processing time left for this process.
Definition: Timing.cpp:124
TimeValueType userTime() const
Retrieve the user time in the requested unit.
Definition: Timing.h:150
ProcessTime operator-(const ProcessTime &rhs) const
Return the delta between two ProcessTime objects.
Definition: Timing.h:161
long long adjustTime< Native >(long long t)
Definition: Timing.h:226
ProcessTime()
Constructor.
Definition: Timing.h:138
long long adjustTime< Month >(long long t)
Definition: Timing.h:222
TimeValueType i_kernel
Internal storage.
Definition: Timing.h:175
long long adjustTime< nanoSec >(long long t)
Definition: Timing.h:218
GAUDI_API longlong currentTime(TimeType typ=milliSec)
Retrieve absolute system time.
Definition: Timing.cpp:79
long long adjustTime< Day >(long long t)
Definition: Timing.h:194
GAUDI_API longlong systemStart(TimeType typ=Sec)
Maximum processing time left for this process.
Definition: Timing.cpp:97
TimeType
Time type for conversion.
Definition: Timing.h:51
TimeValueType i_user
Definition: Timing.h:175
long long adjustTime< milliSec >(long long t)
Definition: Timing.h:210
long long adjustTime< Year >(long long t)
Definition: Timing.h:190
long long adjustTime< microSec >(long long t)
Definition: Timing.h:214
GAUDI_API longlong ellapsedTime(TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
Elapsed time since start of process in milliseconds.
Definition: Timing.cpp:139
long long adjustTime< Min >(long long t)
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
long long TimeValueType
Definition: Timing.h:135
TimeValueType i_elapsed
Definition: Timing.h:175
TimeValueType elapsedTime() const
Retrieve the elapsed time in the requested unit.
Definition: Timing.h:154
long long adjustTime< Hour >(long long t)
Definition: Timing.h:198
TimeValueType cpuTime() const
Retrieve the CPU (user+kernel) time in the requested unit.
Definition: Timing.h:158
ProcessTime & operator+=(const ProcessTime &rhs)
Add the timings to the current objects.
Definition: Timing.h:167
GAUDI_API longlong creationTime(TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
Process Creation time.
Definition: Timing.cpp:114
GAUDI_API longlong kernelTime(TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
CPU kernel mode time of process in milliseconds.
Definition: Timing.cpp:148
long long adjustTime< Sec >(long long t)
Definition: Timing.h:206
GAUDI_API longlong upTime(TimeType typ=Hour)
Maximum processing time left for this process.
Definition: Timing.cpp:108
GAUDI_API longlong cpuTime(TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
Consumed CPU time of process in milliseconds.
Definition: Timing.cpp:168
InfoType
Enumeration for fetching information.
Definition: SystemBase.h:18
GAUDI_API longlong tickCount()
Retrieve the number of ticks since system startup.
Definition: Timing.cpp:65
GAUDI_API longlong userTime(TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
CPU user mode time of process in milliseconds.
Definition: Timing.cpp:158