Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  master (d98a2936)
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 * (c) Copyright 1998-2025 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 #pragma once
12 
13 #include <GaudiKernel/Kernel.h>
14 #include <GaudiKernel/SystemBase.h>
15 
16 #include <sys/time.h>
17 
43 namespace System {
46 
48  GAUDI_API long long adjustTime( TimeType typ, long long timevalue );
49 
51  template <TimeType T>
52  inline long long adjustTime( long long timevalue );
53 
59  GAUDI_API long long ellapsedTime( TimeType typ = milliSec, InfoType fetch = Times, long pid = -1 );
67  GAUDI_API long long kernelTime( TimeType typ = milliSec, InfoType fetch = Times, long pid = -1 );
75  GAUDI_API long long userTime( TimeType typ = milliSec, InfoType fetch = Times, long pid = -1 );
83  GAUDI_API long long cpuTime( TimeType typ = milliSec, InfoType fetch = Times, long pid = -1 );
91  GAUDI_API long long remainingTime( TimeType typ = milliSec, InfoType fetch = Quota, long pid = -1 );
99  GAUDI_API long long creationTime( TimeType typ = milliSec, InfoType fetch = Times, long pid = -1 );
104  GAUDI_API long long systemStart( TimeType typ = Sec );
109  GAUDI_API long long upTime( TimeType typ = Hour );
115  template <TimeType T>
117  GAUDI_API long long currentTime();
118 
120  GAUDI_API long long currentTime( TimeType typ = milliSec );
121 
125  GAUDI_API long long tickCount();
126 
134  class ProcessTime {
135  public:
136  typedef long long TimeValueType;
137 
139  ProcessTime() : i_kernel( 0 ), i_user( 0 ), i_elapsed( 0 ) {}
140 
143 
145  template <TimeType T>
146  inline TimeValueType kernelTime() const {
147  return adjustTime<T>( i_kernel );
148  }
149 
151  template <TimeType T>
152  inline TimeValueType userTime() const {
153  return adjustTime<T>( i_user );
154  }
155 
157  template <TimeType T>
158  inline TimeValueType elapsedTime() const {
159  return adjustTime<T>( i_elapsed );
160  }
161 
163  template <TimeType T>
164  inline TimeValueType cpuTime() const {
165  return adjustTime<T>( i_user + i_kernel );
166  }
167 
169  inline ProcessTime operator-( const ProcessTime& rhs ) const {
170  return ProcessTime( i_kernel - rhs.i_kernel, i_user - rhs.i_user, i_elapsed - rhs.i_elapsed );
171  }
173  inline ProcessTime& operator+=( const ProcessTime& rhs ) {
174  i_kernel += rhs.i_kernel;
175  i_user += rhs.i_user;
176  i_elapsed += rhs.i_elapsed;
177  return *this;
178  }
179 
180  private:
183  };
184 
190  GAUDI_API ProcessTime getProcessTime( long pid = -1 );
191 } // namespace System
192 
193 // implementation of the templated functions
194 namespace System {
195  template <>
196  inline long long adjustTime<Year>( long long t ) {
197  return ( t == -1 ) ? t : t /= ( 1LL * 365 * 24 * 60 * 60 * 1000 * 1000 * 10 );
198  }
199  template <>
200  inline long long adjustTime<Day>( long long t ) {
201  return ( t == -1 ) ? t : t /= ( 1LL * 24 * 60 * 60 * 1000 * 1000 * 10 );
202  }
203  template <>
204  inline long long adjustTime<Hour>( long long t ) {
205  return ( t == -1 ) ? t : t /= ( 1LL * 60 * 60 * 1000 * 1000 * 10 );
206  }
207  template <>
208  inline long long adjustTime<Min>( long long t ) {
209  return ( t == -1 ) ? t : t /= ( 60 * 1000 * 1000 * 10 );
210  }
211  template <>
212  inline long long adjustTime<Sec>( long long t ) {
213  return ( t == -1 ) ? t : t /= ( 1000 * 1000 * 10 );
214  }
215  template <>
216  inline long long adjustTime<milliSec>( long long t ) {
217  return ( t == -1 ) ? t : t /= ( 1000 * 10 );
218  }
219  template <>
220  inline long long adjustTime<microSec>( long long t ) {
221  return ( t == -1 ) ? t : t /= ( 10LL );
222  }
223  template <>
224  inline long long adjustTime<nanoSec>( long long t ) {
225  return ( t == -1 ) ? t : t *= 100LL;
226  }
227  template <>
228  inline long long adjustTime<Month>( long long t ) {
229  return ( t == -1 ) ? t : t /= ( 1LL * 30 * 24 * 60 * 60 * 1000 * 1000 * 10 );
230  }
231  template <>
232  inline long long adjustTime<Native>( long long t ) {
233  return t;
234  }
235 
236  // This is frequently used and thus we inline it if possible
237  template <TimeType T>
238  inline long long currentTime() {
239  struct timeval tv;
240  ::gettimeofday( &tv, 0 );
241  return adjustTime<T>( ( tv.tv_sec * 1000000 + tv.tv_usec ) * 10 );
242  }
243 
244  // Define all template versions here to avoid code bloat
245  template long long currentTime<Year>();
246  template long long currentTime<Month>();
247  template long long currentTime<Day>();
248  template long long currentTime<Hour>();
249  template long long currentTime<Min>();
250  template long long currentTime<Sec>();
251  template long long currentTime<milliSec>();
252  template long long currentTime<microSec>();
253  template long long currentTime<nanoSec>();
254  template long long currentTime<Native>();
255 } // namespace System
System::milliSec
@ milliSec
Definition: Timing.h:45
System::currentTime< Month >
template long long currentTime< Month >()
System::Hour
@ Hour
Definition: Timing.h:45
System::InfoType
InfoType
Enumeration for fetching information.
Definition: SystemBase.h:15
System::ProcessTime::ProcessTime
ProcessTime()
Constructor.
Definition: Timing.h:139
System::adjustTime< Month >
long long adjustTime< Month >(long long t)
Definition: Timing.h:228
System::Year
@ Year
Definition: Timing.h:45
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:140
System::microSec
@ microSec
Definition: Timing.h:45
NewInputWrite.fetch
fetch
Definition: NewInputWrite.py:45
System::ProcessTime::kernelTime
TimeValueType kernelTime() const
Retrieve the kernel time in the requested unit.
Definition: Timing.h:146
System::currentTime< Hour >
template long long currentTime< Hour >()
System::ProcessTime::ProcessTime
ProcessTime(TimeValueType k, TimeValueType u, TimeValueType e)
Constructor.
Definition: Timing.h:142
System::TimeType
TimeType
Time type for conversion.
Definition: Timing.h:45
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:164
System::nanoSec
@ nanoSec
Definition: Timing.h:45
System::Month
@ Month
Definition: Timing.h:45
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:182
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:154
System::adjustTime< milliSec >
long long adjustTime< milliSec >(long long t)
Definition: Timing.h:216
System::ProcessTime::elapsedTime
TimeValueType elapsedTime() const
Retrieve the elapsed time in the requested unit.
Definition: Timing.h:158
System::adjustTime< Day >
long long adjustTime< Day >(long long t)
Definition: Timing.h:200
System::adjustTime< Year >
long long adjustTime< Year >(long long t)
Definition: Timing.h:196
System::adjustTime< Native >
long long adjustTime< Native >(long long t)
Definition: Timing.h:232
System::ProcessTime::i_elapsed
TimeValueType i_elapsed
Definition: Timing.h:182
System::currentTime< milliSec >
template long long currentTime< milliSec >()
System::ProcessTime
Simple class to hold the time information of a process.
Definition: Timing.h:134
System::tickCount
GAUDI_API long long tickCount()
Retrieve the number of ticks since system startup.
Definition: Timing.cpp:76
System::currentTime
GAUDI_API long long currentTime()
Retrieve absolute system time.
Definition: Timing.h:238
System::adjustTime< nanoSec >
long long adjustTime< nanoSec >(long long t)
Definition: Timing.h:224
System::ProcessTime::i_kernel
TimeValueType i_kernel
Internal storage.
Definition: Timing.h:182
System::ProcessTime::operator-
ProcessTime operator-(const ProcessTime &rhs) const
Return the delta between two ProcessTime objects.
Definition: Timing.h:169
System::adjustTime< microSec >
long long adjustTime< microSec >(long long t)
Definition: Timing.h:220
System::upTime
GAUDI_API long long upTime(TimeType typ=Hour)
Maximum processing time left for this process.
Definition: Timing.cpp:124
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:182
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:174
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:208
System::adjustTime< Hour >
long long adjustTime< Hour >(long long t)
Definition: Timing.h:204
System::Times
@ Times
Definition: SystemBase.h:15
System::Sec
@ Sec
Definition: Timing.h:45
System::Quota
@ Quota
Definition: SystemBase.h:15
System::currentTime< Sec >
template long long currentTime< Sec >()
System::Day
@ Day
Definition: Timing.h:45
System::adjustTime< Sec >
long long adjustTime< Sec >(long long t)
Definition: Timing.h:212
System::currentTime< Native >
template long long currentTime< Native >()
System::Native
@ Native
Definition: Timing.h:45
System::currentTime< Day >
template long long currentTime< Day >()
SystemBase.h
System::Min
@ Min
Definition: Timing.h:45
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:38
Kernel.h
System
Note: OS specific details for environment resolution.
Definition: Environment.h:25
System::ProcessTime::TimeValueType
long long TimeValueType
Definition: Timing.h:136
System::ProcessTime::userTime
TimeValueType userTime() const
Retrieve the user time in the requested unit.
Definition: Timing.h:152
System::ProcessTime::cpuTime
TimeValueType cpuTime() const
Retrieve the CPU (user+kernel) time in the requested unit.
Definition: Timing.h:164
System::getProcessTime
GAUDI_API ProcessTime getProcessTime(long pid=-1)
Retrieve the process time data for a process.
Definition: Timing.cpp:192
System::systemStart
GAUDI_API long long systemStart(TimeType typ=Sec)
Maximum processing time left for this process.
Definition: Timing.cpp:113
System::ProcessTime::operator+=
ProcessTime & operator+=(const ProcessTime &rhs)
Add the timings to the current objects.
Definition: Timing.h:173
System::currentTime< nanoSec >
template long long currentTime< nanoSec >()
GAUDI_API
#define GAUDI_API
Definition: Kernel.h:49
System::creationTime
GAUDI_API long long creationTime(TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
Process Creation time.
Definition: Timing.cpp:130