The Gaudi Framework  master (37c0b60a)
Timing.h
Go to the documentation of this file.
1 /***********************************************************************************\
2 * (c) Copyright 1998-2024 CERN for the benefit of the LHCb and ATLAS collaborations *
3 * *
4 * This software is distributed under the terms of the Apache version 2 licence, *
5 * copied verbatim in the file "LICENSE". *
6 * *
7 * In applying this licence, CERN does not waive the privileges and immunities *
8 * granted to it by virtue of its status as an Intergovernmental Organization *
9 * or submit itself to any jurisdiction. *
10 \***********************************************************************************/
11 //====================================================================
12 // Timing.h
13 //--------------------------------------------------------------------
14 //
15 // Package : Gaudi/System (The LHCb System service)
16 //
17 // Description: Definition of Systems internals
18 //
19 // Author : M.Frank
20 // Created : 13/1/99
21 //====================================================================
22 #ifndef GAUDIKERNEL_TIMING_H
23 #define GAUDIKERNEL_TIMING_H
24 
25 // Framework include files
26 #include <GaudiKernel/Kernel.h>
27 #include <GaudiKernel/SystemBase.h>
28 
29 #ifdef _WIN32
30 # include <windows.h>
31 #else
32 # include <sys/time.h>
33 #endif
34 
65 namespace System {
68 
70  GAUDI_API long long adjustTime( TimeType typ, long long timevalue );
71 
73  template <TimeType T>
74  inline long long adjustTime( long long timevalue );
75 
81  GAUDI_API long long ellapsedTime( TimeType typ = milliSec, InfoType fetch = Times, long pid = -1 );
89  GAUDI_API long long kernelTime( TimeType typ = milliSec, InfoType fetch = Times, long pid = -1 );
97  GAUDI_API long long userTime( TimeType typ = milliSec, InfoType fetch = Times, long pid = -1 );
105  GAUDI_API long long cpuTime( TimeType typ = milliSec, InfoType fetch = Times, long pid = -1 );
113  GAUDI_API long long remainingTime( TimeType typ = milliSec, InfoType fetch = Quota, long pid = -1 );
121  GAUDI_API long long creationTime( TimeType typ = milliSec, InfoType fetch = Times, long pid = -1 );
126  GAUDI_API long long systemStart( TimeType typ = Sec );
131  GAUDI_API long long upTime( TimeType typ = Hour );
137  template <TimeType T>
139  GAUDI_API long long currentTime();
140 
142  GAUDI_API long long currentTime( TimeType typ = milliSec );
143 
147  GAUDI_API long long tickCount();
148 
156  class ProcessTime {
157  public:
158  typedef long long TimeValueType;
159 
161  ProcessTime() : i_kernel( 0 ), i_user( 0 ), i_elapsed( 0 ) {}
162 
165 
167  template <TimeType T>
168  inline TimeValueType kernelTime() const {
169  return adjustTime<T>( i_kernel );
170  }
171 
173  template <TimeType T>
174  inline TimeValueType userTime() const {
175  return adjustTime<T>( i_user );
176  }
177 
179  template <TimeType T>
180  inline TimeValueType elapsedTime() const {
181  return adjustTime<T>( i_elapsed );
182  }
183 
185  template <TimeType T>
186  inline TimeValueType cpuTime() const {
187  return adjustTime<T>( i_user + i_kernel );
188  }
189 
191  inline ProcessTime operator-( const ProcessTime& rhs ) const {
192  return ProcessTime( i_kernel - rhs.i_kernel, i_user - rhs.i_user, i_elapsed - rhs.i_elapsed );
193  }
195  inline ProcessTime& operator+=( const ProcessTime& rhs ) {
196  i_kernel += rhs.i_kernel;
197  i_user += rhs.i_user;
198  i_elapsed += rhs.i_elapsed;
199  return *this;
200  }
201 
202  private:
205  };
206 
212  GAUDI_API ProcessTime getProcessTime( long pid = -1 );
213 } // namespace System
214 
215 // implementation of the templated functions
216 namespace System {
217  template <>
218  inline long long adjustTime<Year>( long long t ) {
219  return ( t == -1 ) ? t : t /= ( 1LL * 365 * 24 * 60 * 60 * 1000 * 1000 * 10 );
220  }
221  template <>
222  inline long long adjustTime<Day>( long long t ) {
223  return ( t == -1 ) ? t : t /= ( 1LL * 24 * 60 * 60 * 1000 * 1000 * 10 );
224  }
225  template <>
226  inline long long adjustTime<Hour>( long long t ) {
227  return ( t == -1 ) ? t : t /= ( 1LL * 60 * 60 * 1000 * 1000 * 10 );
228  }
229  template <>
230  inline long long adjustTime<Min>( long long t ) {
231  return ( t == -1 ) ? t : t /= ( 60 * 1000 * 1000 * 10 );
232  }
233  template <>
234  inline long long adjustTime<Sec>( long long t ) {
235  return ( t == -1 ) ? t : t /= ( 1000 * 1000 * 10 );
236  }
237  template <>
238  inline long long adjustTime<milliSec>( long long t ) {
239  return ( t == -1 ) ? t : t /= ( 1000 * 10 );
240  }
241  template <>
242  inline long long adjustTime<microSec>( long long t ) {
243  return ( t == -1 ) ? t : t /= ( 10LL );
244  }
245  template <>
246  inline long long adjustTime<nanoSec>( long long t ) {
247  return ( t == -1 ) ? t : t *= 100LL;
248  }
249  template <>
250  inline long long adjustTime<Month>( long long t ) {
251  return ( t == -1 ) ? t : t /= ( 1LL * 30 * 24 * 60 * 60 * 1000 * 1000 * 10 );
252  }
253  template <>
254  inline long long adjustTime<Native>( long long t ) {
255  return t;
256  }
257 
258  // This is frequently used and thus we inline it if possible
259  template <TimeType T>
260  inline long long currentTime() {
261 #ifdef _WIN32
262  long long current = 0;
263  ::GetSystemTimeAsFileTime( (FILETIME*)&current );
264  return adjustTime<T>( current - UNIX_BASE_TIME );
265 #else
266  struct timeval tv;
267  ::gettimeofday( &tv, 0 );
268  return adjustTime<T>( ( tv.tv_sec * 1000000 + tv.tv_usec ) * 10 );
269 #endif
270  }
271 
272  // Define all template versions here to avoid code bloat
273  template long long currentTime<Year>();
274  template long long currentTime<Month>();
275  template long long currentTime<Day>();
276  template long long currentTime<Hour>();
277  template long long currentTime<Min>();
278  template long long currentTime<Sec>();
279  template long long currentTime<milliSec>();
280  template long long currentTime<microSec>();
281  template long long currentTime<nanoSec>();
282  template long long currentTime<Native>();
283 } // namespace System
284 
285 #endif // GAUDIKERNEL_TIMING_H
System::milliSec
@ milliSec
Definition: Timing.h:67
System::currentTime< Month >
template long long currentTime< Month >()
System::Hour
@ Hour
Definition: Timing.h:67
System::InfoType
InfoType
Enumeration for fetching information.
Definition: SystemBase.h:28
System::ProcessTime::ProcessTime
ProcessTime()
Constructor.
Definition: Timing.h:161
System::adjustTime< Month >
long long adjustTime< Month >(long long t)
Definition: Timing.h:250
System::Year
@ Year
Definition: Timing.h:67
System::remainingTime
GAUDI_API long long remainingTime(TimeType typ=milliSec, InfoType fetch=Quota, long pid=-1)
Maximum processing time left for this process.
Definition: Timing.cpp:155
System::microSec
@ microSec
Definition: Timing.h:67
NewInputWrite.fetch
fetch
Definition: NewInputWrite.py:45
System::ProcessTime::kernelTime
TimeValueType kernelTime() const
Retrieve the kernel time in the requested unit.
Definition: Timing.h:168
System::currentTime< Hour >
template long long currentTime< Hour >()
System::ProcessTime::ProcessTime
ProcessTime(TimeValueType k, TimeValueType u, TimeValueType e)
Constructor.
Definition: Timing.h:164
System::TimeType
TimeType
Time type for conversion.
Definition: Timing.h:67
System::kernelTime
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:179
System::nanoSec
@ nanoSec
Definition: Timing.h:67
System::Month
@ Month
Definition: Timing.h:67
System::currentTime< Year >
template long long currentTime< Year >()
bug_34121.t
t
Definition: bug_34121.py:31
System::ProcessTime::i_user
TimeValueType i_user
Definition: Timing.h:204
System::ellapsedTime
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:169
System::adjustTime< milliSec >
long long adjustTime< milliSec >(long long t)
Definition: Timing.h:238
System::ProcessTime::elapsedTime
TimeValueType elapsedTime() const
Retrieve the elapsed time in the requested unit.
Definition: Timing.h:180
System::adjustTime< Day >
long long adjustTime< Day >(long long t)
Definition: Timing.h:222
System::adjustTime< Year >
long long adjustTime< Year >(long long t)
Definition: Timing.h:218
System::adjustTime< Native >
long long adjustTime< Native >(long long t)
Definition: Timing.h:254
System::ProcessTime::i_elapsed
TimeValueType i_elapsed
Definition: Timing.h:204
System::currentTime< milliSec >
template long long currentTime< milliSec >()
System::ProcessTime
Simple class to hold the time information of a process.
Definition: Timing.h:156
System::tickCount
GAUDI_API long long tickCount()
Retrieve the number of ticks since system startup.
Definition: Timing.cpp:87
System::currentTime
GAUDI_API long long currentTime()
Retrieve absolute system time.
Definition: Timing.h:260
System::adjustTime< nanoSec >
long long adjustTime< nanoSec >(long long t)
Definition: Timing.h:246
System::ProcessTime::i_kernel
TimeValueType i_kernel
Internal storage.
Definition: Timing.h:204
System::ProcessTime::operator-
ProcessTime operator-(const ProcessTime &rhs) const
Return the delta between two ProcessTime objects.
Definition: Timing.h:191
System::adjustTime< microSec >
long long adjustTime< microSec >(long long t)
Definition: Timing.h:242
System::upTime
GAUDI_API long long upTime(TimeType typ=Hour)
Maximum processing time left for this process.
Definition: Timing.cpp:139
System::cpuTime
GAUDI_API long long cpuTime(TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
Consumed CPU time of process in milliseconds.
Definition: Timing.cpp:197
System::userTime
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:189
System::currentTime< microSec >
template long long currentTime< microSec >()
System::currentTime< Min >
template long long currentTime< Min >()
System::adjustTime< Min >
long long adjustTime< Min >(long long t)
Definition: Timing.h:230
System::adjustTime< Hour >
long long adjustTime< Hour >(long long t)
Definition: Timing.h:226
System::Times
@ Times
Definition: SystemBase.h:28
System::Sec
@ Sec
Definition: Timing.h:67
System::Quota
@ Quota
Definition: SystemBase.h:28
System::currentTime< Sec >
template long long currentTime< Sec >()
System::Day
@ Day
Definition: Timing.h:67
System::adjustTime< Sec >
long long adjustTime< Sec >(long long t)
Definition: Timing.h:234
System::currentTime< Native >
template long long currentTime< Native >()
System::Native
@ Native
Definition: Timing.h:67
System::currentTime< Day >
template long long currentTime< Day >()
SystemBase.h
System::Min
@ Min
Definition: Timing.h:67
System::adjustTime
GAUDI_API long long adjustTime(TimeType typ, long long timevalue)
Convert time from OS native time to requested representation (Experts only)
Definition: Timing.cpp:47
Kernel.h
System
Note: OS specific details for environment resolution.
Definition: Debugger.h:29
System::ProcessTime::TimeValueType
long long TimeValueType
Definition: Timing.h:158
System::ProcessTime::userTime
TimeValueType userTime() const
Retrieve the user time in the requested unit.
Definition: Timing.h:174
System::ProcessTime::cpuTime
TimeValueType cpuTime() const
Retrieve the CPU (user+kernel) time in the requested unit.
Definition: Timing.h:186
System::getProcessTime
GAUDI_API ProcessTime getProcessTime(long pid=-1)
Retrieve the process time data for a process.
Definition: Timing.cpp:207
System::systemStart
GAUDI_API long long systemStart(TimeType typ=Sec)
Maximum processing time left for this process.
Definition: Timing.cpp:128
System::ProcessTime::operator+=
ProcessTime & operator+=(const ProcessTime &rhs)
Add the timings to the current objects.
Definition: Timing.h:195
System::currentTime< nanoSec >
template long long currentTime< nanoSec >()
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:81
System::creationTime
GAUDI_API long long creationTime(TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
Process Creation time.
Definition: Timing.cpp:145