| The Gaudi Framework v28r2p1 (f1a77ff4)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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 {
57 enum TimeType { Year, Month, Day, Hour, Min, Sec, milliSec, microSec, nanoSec, Native };
58
60 GAUDI_API longlong adjustTime(TimeType typ, longlong timevalue);
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);
116 GAUDI_API longlong systemStart(TimeType typ = Sec);
121 GAUDI_API longlong upTime(TimeType typ = Hour);
127 template <TimeType T>
129 GAUDI_API longlong currentTime();
130
132 GAUDI_API longlong currentTime(TimeType typ = milliSec);
133
137 GAUDI_API longlong 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):
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>
245 inline longlong currentTime() {
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
System::userTime
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
System::currentTime< milliSec >
template longlong currentTime< milliSec >()
Kernel.h
System::currentTime< microSec >
template longlong currentTime< microSec >()
System::ProcessTime::ProcessTime
ProcessTime(TimeValueType k, TimeValueType u, TimeValueType e)
Constructor.
Definition: Timing.h:154
System::systemStart
GAUDI_API longlong systemStart(TimeType typ=Sec)
Maximum processing time left for this process.
Definition: Timing.cpp:96
System::ProcessTime::kernelTime
TimeValueType kernelTime() const
Retrieve the kernel time in the requested unit.
Definition: Timing.h:159
System::Min
Definition: Timing.h:57
System
Note: OS specific details for environment resolution.
Definition: Debugger.h:19
System::Times
Definition: SystemBase.h:20
System::ProcessTime::userTime
TimeValueType userTime() const
Retrieve the user time in the requested unit.
Definition: Timing.h:163
System::ProcessTime::operator-
ProcessTime operator-(const ProcessTime &rhs) const
Return the delta between two ProcessTime objects.
Definition: Timing.h:174
System::cpuTime
GAUDI_API longlong cpuTime(TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
Consumed CPU time of process in milliseconds.
Definition: Timing.cpp:167
System::adjustTime< Native >
long long adjustTime< Native >(long long t)
Definition: Timing.h:239
System::Hour
Definition: Timing.h:57
System::ProcessTime::ProcessTime
ProcessTime()
Constructor.
Definition: Timing.h:151
System::adjustTime< Month >
long long adjustTime< Month >(long long t)
Definition: Timing.h:235
System::ellapsedTime
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
System::milliSec
Definition: Timing.h:57
System::upTime
GAUDI_API longlong upTime(TimeType typ=Hour)
Maximum processing time left for this process.
Definition: Timing.cpp:107
System::ProcessTime::i_kernel
TimeValueType i_kernel
Internal storage.
Definition: Timing.h:188
System::Sec
Definition: Timing.h:57
System::adjustTime< nanoSec >
long long adjustTime< nanoSec >(long long t)
Definition: Timing.h:231
System::tickCount
GAUDI_API longlong tickCount()
Retrieve the number of ticks since system startup.
Definition: Timing.cpp:65
System::microSec
Definition: Timing.h:57
System::adjustTime< Day >
long long adjustTime< Day >(long long t)
Definition: Timing.h:207
__longlong
Definition: Kernel.h:56
System::creationTime
GAUDI_API longlong creationTime(TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
Process Creation time.
Definition: Timing.cpp:113
System::TimeType
TimeType
Time type for conversion.
Definition: Timing.h:57
System::remainingTime
GAUDI_API longlong remainingTime(TimeType typ=milliSec, InfoType fetch=Quota, long pid=-1)
Maximum processing time left for this process.
Definition: Timing.cpp:123
System::currentTime< Native >
template longlong currentTime< Native >()
System::Native
Definition: Timing.h:57
System::Quota
Definition: SystemBase.h:24
System::currentTime< nanoSec >
template longlong currentTime< nanoSec >()
System::ProcessTime::i_user
TimeValueType i_user
Definition: Timing.h:188
System::kernelTime
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
System::adjustTime< milliSec >
long long adjustTime< milliSec >(long long t)
Definition: Timing.h:223
System::adjustTime< Year >
long long adjustTime< Year >(long long t)
Definition: Timing.h:203
System::ProcessTime
Simple class to hold the time information of a process.
Definition: Timing.h:146
System::adjustTime< microSec >
long long adjustTime< microSec >(long long t)
Definition: Timing.h:227
System::currentTime
GAUDI_API longlong currentTime()
Retrieve absolute system time.
Definition: Timing.h:245
System::adjustTime< Min >
long long adjustTime< Min >(long long t)
Definition: Timing.h:215
System::Month
Definition: Timing.h:57
System::ProcessTime::TimeValueType
long long TimeValueType
Definition: Timing.h:148
System::ProcessTime::i_elapsed
TimeValueType i_elapsed
Definition: Timing.h:188
System::nanoSec
Definition: Timing.h:57
System::adjustTime
GAUDI_API longlong adjustTime(TimeType typ, longlong timevalue)
Convert time from OS native time to requested representation (Experts only)
Definition: Timing.cpp:37
System::ProcessTime::elapsedTime
TimeValueType elapsedTime() const
Retrieve the elapsed time in the requested unit.
Definition: Timing.h:167
System::getProcessTime
GAUDI_API ProcessTime getProcessTime(long pid=-1)
Retrieve the process time data for a process.
Definition: Timing.cpp:177
System::adjustTime< Hour >
long long adjustTime< Hour >(long long t)
Definition: Timing.h:211
System::ProcessTime::cpuTime
TimeValueType cpuTime() const
Retrieve the CPU (user+kernel) time in the requested unit.
Definition: Timing.h:171
System::ProcessTime::operator+=
ProcessTime & operator+=(const ProcessTime &rhs)
Add the timings to the current objects.
Definition: Timing.h:180
System::Year
Definition: Timing.h:57
System::adjustTime< Sec >
long long adjustTime< Sec >(long long t)
Definition: Timing.h:219
SystemBase.h
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:107
System::InfoType
InfoType
Enumeration for fetching information.
Definition: SystemBase.h:18
System::Day
Definition: Timing.h:57