All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups 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 
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 
139 
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  }
166  private:
169  };
170 
176  GAUDI_API ProcessTime getProcessTime(long pid = -1);
177 
178 }
179 
180 // implementation of the templated adjustTime
181 namespace System {
182  template <>
183  inline long long adjustTime<Year>(long long t) {
184  return (t==-1) ? t : t /= (1LL * 365 * 24 * 60 * 60 * 1000 * 1000 * 10);
185  }
186  template <>
187  inline long long adjustTime<Day>(long long t) {
188  return (t==-1) ? t : t /= (1LL * 24 * 60 * 60 * 1000 * 1000 * 10);
189  }
190  template <>
191  inline long long adjustTime<Hour>(long long t) {
192  return (t==-1) ? t : t /= (1LL * 60 * 60 * 1000 * 1000 * 10);
193  }
194  template <>
195  inline long long adjustTime<Min>(long long t) {
196  return (t==-1) ? t : t /= (60 * 1000 * 1000 * 10);
197  }
198  template <>
199  inline long long adjustTime<Sec>(long long t) {
200  return (t==-1) ? t : t /= (1000 * 1000 * 10);
201  }
202  template <>
203  inline long long adjustTime<milliSec>(long long t) {
204  return (t==-1) ? t : t /= (1000 * 10);
205  }
206  template <>
207  inline long long adjustTime<microSec>(long long t) {
208  return (t==-1) ? t : t /= (10LL);
209  }
210  template <>
211  inline long long adjustTime<nanoSec>(long long t) {
212  return (t==-1) ? t : t *= 100LL;
213  }
214  template <>
215  inline long long adjustTime<Month>(long long t) {
216  return (t==-1) ? t : t /= (1LL * 30 * 24 * 60 * 60 * 1000 * 1000 * 10);
217  }
218  template <>
219  inline long long adjustTime<Native>(long long t) {
220  return t;
221  }
222 }
223 
224 #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:159
ProcessTime(TimeValueType k, TimeValueType u, TimeValueType e)
Constructor.
Definition: Timing.h:141
GAUDI_API longlong systemStart(TimeType typ=Sec)
Maximum processing time left for this process.
Definition: Timing.cpp:98
TimeValueType kernelTime() const
Retrieve the kernel time in the requested unit.
Definition: Timing.h:146
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
GAUDI_API longlong cpuTime(TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
Consumed CPU time of process in milliseconds.
Definition: Timing.cpp:169
long long adjustTime< Native >(long long t)
Definition: Timing.h:219
ProcessTime()
Constructor.
Definition: Timing.h:138
long long adjustTime< Month >(long long t)
Definition: Timing.h:215
GAUDI_API longlong ellapsedTime(TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
Elapsed time since start of process in milliseconds.
Definition: Timing.cpp:140
GAUDI_API longlong upTime(TimeType typ=Hour)
Maximum processing time left for this process.
Definition: Timing.cpp:109
TimeValueType i_kernel
Internal storage.
Definition: Timing.h:168
long long adjustTime< nanoSec >(long long t)
Definition: Timing.h:211
GAUDI_API longlong tickCount()
Retrieve the number of ticks since system startup.
Definition: Timing.cpp:66
long long adjustTime< Day >(long long t)
Definition: Timing.h:187
GAUDI_API longlong creationTime(TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
Process Creation time.
Definition: Timing.cpp:115
TimeType
Time type for conversion.
Definition: Timing.h:51
GAUDI_API longlong remainingTime(TimeType typ=milliSec, InfoType fetch=Quota, long pid=-1)
Maximum processing time left for this process.
Definition: Timing.cpp:125
TimeValueType i_user
Definition: Timing.h:168
GAUDI_API longlong kernelTime(TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
CPU kernel mode time of process in milliseconds.
Definition: Timing.cpp:149
long long adjustTime< milliSec >(long long t)
Definition: Timing.h:203
long long adjustTime< Year >(long long t)
Definition: Timing.h:183
Simple class to hold the time information of a process.
Definition: Timing.h:133
long long adjustTime< microSec >(long long t)
Definition: Timing.h:207
long long adjustTime< Min >(long long t)
Definition: Timing.h:195
long long TimeValueType
Definition: Timing.h:135
TimeValueType i_elapsed
Definition: Timing.h:168
GAUDI_API longlong adjustTime(TimeType typ, longlong timevalue)
Convert time from OS native time to requested representation (Experts only)
Definition: Timing.cpp:38
TimeValueType elapsedTime() const
Retrieve the elapsed time in the requested unit.
Definition: Timing.h:154
GAUDI_API ProcessTime getProcessTime(long pid=-1)
Retrieve the process time data for a process.
Definition: Timing.cpp:179
long long adjustTime< Hour >(long long t)
Definition: Timing.h:191
TimeValueType cpuTime() const
Retrieve the CPU (user+kernel) time in the requested unit.
Definition: Timing.h:158
long long adjustTime< Sec >(long long t)
Definition: Timing.h:199
#define GAUDI_API
Definition: Kernel.h:108
InfoType
Enumeration for fetching information.
Definition: SystemBase.h:18
GAUDI_API longlong currentTime(TimeType typ=milliSec)
Retrieve absolute system time.
Definition: Timing.cpp:80