The Gaudi Framework  master (82fdf313)
Loading...
Searching...
No Matches
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>
15
16#include <sys/time.h>
17
43namespace 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 );
114
116 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
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 }
172
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
194namespace 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
#define GAUDI_API
Definition Kernel.h:49
Simple class to hold the time information of a process.
Definition Timing.h:134
TimeValueType elapsedTime() const
Retrieve the elapsed time in the requested unit.
Definition Timing.h:158
ProcessTime operator-(const ProcessTime &rhs) const
Return the delta between two ProcessTime objects.
Definition Timing.h:169
TimeValueType i_elapsed
Definition Timing.h:182
TimeValueType userTime() const
Retrieve the user time in the requested unit.
Definition Timing.h:152
ProcessTime()
Constructor.
Definition Timing.h:139
TimeValueType i_kernel
Internal storage.
Definition Timing.h:182
ProcessTime(TimeValueType k, TimeValueType u, TimeValueType e)
Constructor.
Definition Timing.h:142
ProcessTime & operator+=(const ProcessTime &rhs)
Add the timings to the current objects.
Definition Timing.h:173
TimeValueType cpuTime() const
Retrieve the CPU (user+kernel) time in the requested unit.
Definition Timing.h:164
long long TimeValueType
Definition Timing.h:136
TimeValueType i_user
Definition Timing.h:182
TimeValueType kernelTime() const
Retrieve the kernel time in the requested unit.
Definition Timing.h:146
Note: OS specific details for environment resolution.
Definition Environment.h:25
long long adjustTime< Day >(long long t)
Definition Timing.h:200
long long adjustTime< Native >(long long t)
Definition Timing.h:232
GAUDI_API ProcessTime getProcessTime(long pid=-1)
Retrieve the process time data for a process.
Definition Timing.cpp:192
TimeType
Time type for conversion.
Definition Timing.h:45
@ milliSec
Definition Timing.h:45
@ Min
Definition Timing.h:45
@ Native
Definition Timing.h:45
@ Year
Definition Timing.h:45
@ Sec
Definition Timing.h:45
@ nanoSec
Definition Timing.h:45
@ Hour
Definition Timing.h:45
@ Month
Definition Timing.h:45
@ microSec
Definition Timing.h:45
@ Day
Definition Timing.h:45
template long long currentTime< Month >()
long long adjustTime< Year >(long long t)
Definition Timing.h:196
long long adjustTime< Hour >(long long t)
Definition Timing.h:204
template long long currentTime< Sec >()
long long adjustTime< nanoSec >(long long t)
Definition Timing.h:224
long long adjustTime< milliSec >(long long t)
Definition Timing.h:216
long long adjustTime< microSec >(long long t)
Definition Timing.h:220
template long long currentTime< milliSec >()
GAUDI_API long long systemStart(TimeType typ=Sec)
Maximum processing time left for this process.
Definition Timing.cpp:113
long long adjustTime< Sec >(long long t)
Definition Timing.h:212
template long long currentTime< microSec >()
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
template long long currentTime< Day >()
InfoType
Enumeration for fetching information.
Definition SystemBase.h:15
GAUDI_API long long creationTime(TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
Process Creation time.
Definition Timing.cpp:130
template long long currentTime< Hour >()
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
long long adjustTime< Month >(long long t)
Definition Timing.h:228
GAUDI_API long long currentTime()
Retrieve absolute system time.
Definition Timing.h:238
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
template long long currentTime< nanoSec >()
long long adjustTime< Min >(long long t)
Definition Timing.h:208
template long long currentTime< Native >()
GAUDI_API long long tickCount()
Retrieve the number of ticks since system startup.
Definition Timing.cpp:76
template long long currentTime< Min >()
template long long currentTime< Year >()
GAUDI_API long long upTime(TimeType typ=Hour)
Maximum processing time left for this process.
Definition Timing.cpp:124
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
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
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