| The Gaudi Framework v29r0 (ff2e7097)

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

- File List
- File Members

Timing.cpp
Go to the documentation of this file.
1 //====================================================================
2 // Timing.cpp
3 //--------------------------------------------------------------------
4 //
5 // Package : System (The LHCb System service)
6 //
7 // Description: Implementation of Systems internals
8 //
9 // Author : M.Frank
10 // Created : 13/1/99
11 // Changes :
12 //====================================================================
13 #define GAUDIKERNEL_TIMING_CPP
14
15 #include "GaudiKernel/Timing.h"
16 #include "ProcessDescriptor.h"
17
18 #include <climits>
19 #include <ctime>
20 #ifdef _WIN32
21 #include <windows.h>
22 #else
23 #include <sys/time.h>
24 #include <sys/times.h>
25 #include <unistd.h>
26 #endif
27
28 #ifdef _WIN32
29 static const longlong UNIX_BASE_TIME = 116444736000000000;
30 #else
31 static const longlong UNIX_BASE_TIME = 0;
32 #endif
33
34 // convert time from internal representation to the appropriate type
35 // Internal representation for WIN32: 100 nanosecond intervals
36 // Unix: 1 clock tick (usually 10 milliseconds)
37 longlong System::adjustTime( TimeType typ, longlong t )
38 {
39 if ( t != -1 ) {
40 #ifndef _WIN32
41 // t /= CLK_TCK ; // needs division by clock tick unit
46
48 #endif
49 switch ( typ ) {
50 case Year:
51 return adjustTime<Year>( t );
52 case Month:
53 return adjustTime<Month>( t );
54 case Day:
55 return adjustTime<Day>( t );
56 case Hour:
57 return adjustTime<Hour>( t );
58 case Min:
59 return adjustTime<Min>( t );
60 case Sec:
61 return adjustTime<Sec>( t );
62 case milliSec:
63 return adjustTime<milliSec>( t );
64 case microSec:
65 return adjustTime<microSec>( t );
66 case nanoSec:
67 return adjustTime<nanoSec>( t );
68 case Native:
69 return adjustTime<Native>( t );
70 }
71 }
72 return t;
73 }
74
76 longlong System::tickCount()
77 {
78 longlong count = 10000;
79 #ifdef _WIN32
80 count *= ::GetTickCount(); // Number of milliSec since system startup
81 #else
82 struct tms buf;
83 count *= 10 * times( &buf );
84 #endif
85 return count;
86 }
87
88 #include <iostream>
89
91 longlong System::currentTime( TimeType typ )
92 {
93 switch ( typ ) {
94 case Year:
95 return currentTime<Year>();
96 case Month:
97 return currentTime<Month>();
98 case Day:
99 return currentTime<Day>();
100 case Hour:
101 return currentTime<Hour>();
102 case Min:
103 return currentTime<Min>();
104 case Sec:
105 return currentTime<Sec>();
106 case milliSec:
107 return currentTime<milliSec>();
108 case microSec:
109 return currentTime<microSec>();
110 case nanoSec:
111 return currentTime<nanoSec>();
112 case Native:
113 return currentTime<Native>();
114 }
115 return currentTime<Native>();
116 }
117
119 longlong System::systemStart( TimeType typ )
120 {
121 static longlong sys_start = 0;
122 if ( 0 == sys_start ) {
123 longlong c = currentTime( microSec );
124 longlong t = tickCount();
125 sys_start = 10 * c - t;
126 }
127 return adjustTime( typ, sys_start );
128 }
129
131 longlong System::upTime( TimeType typ )
132 {
133 static longlong sys_start = 10 * systemStart( microSec );
134 return adjustTime( typ, 10 * currentTime( microSec ) - sys_start );
135 }
136
138 longlong System::creationTime( TimeType typ, InfoType fetch, long pid )
139 {
140 longlong created = 0;
141 KERNEL_USER_TIMES info;
142 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) {
143 created = adjustTime( typ, info.CreateTime - UNIX_BASE_TIME );
144 }
145 return created;
146 }
147
149 longlong System::remainingTime( TimeType typ, InfoType fetch, long pid )
150 {
151 longlong left = 0;
152 QUOTA_LIMITS quota;
153 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &quota ) ) {
154 if ( left == -1 ) {
155 // left = _I64_MAX;
156 } else {
157 left = adjustTime( typ, quota.TimeLimit );
158 }
159 }
160 return left;
161 }
162
164 longlong System::ellapsedTime( TimeType typ, InfoType fetch, long pid )
165 {
166 KERNEL_USER_TIMES info;
167 longlong ellapsed = currentTime( microSec ) * 10;
168 getProcess()->query( pid, fetch, &info );
169 ellapsed = adjustTime( typ, ellapsed + UNIX_BASE_TIME - info.CreateTime );
170 return ellapsed;
171 }
172
174 longlong System::kernelTime( TimeType typ, InfoType fetch, long pid )
175 {
176 KERNEL_USER_TIMES info;
177 longlong kerneltime = 0;
178 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) {
179 kerneltime = adjustTime( typ, info.KernelTime );
180 }
181 return kerneltime;
182 }
183
185 longlong System::userTime( TimeType typ, InfoType fetch, long pid )
186 {
187 longlong usertime = 0;
188 KERNEL_USER_TIMES info;
189 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) {
190 usertime = adjustTime( typ, info.UserTime );
191 }
192 return usertime;
193 }
194
196 longlong System::cpuTime( TimeType typ, InfoType fetch, long pid )
197 {
198 longlong cputime = 0;
199 KERNEL_USER_TIMES info;
200 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) {
201 cputime = adjustTime( typ, info.KernelTime + info.UserTime );
202 }
203 return cputime;
204 }
205
206 namespace System
207 {
208 ProcessTime getProcessTime( long pid )
209 {
210 KERNEL_USER_TIMES info;
211 if ( getProcess()->query( pid, Times, &info ) ) {
212 return ProcessTime( info.KernelTime, info.UserTime, currentTime<Native>() - info.CreateTime );
213 }
214 return ProcessTime(); // return 0s in case of problems
215 }
216 }
System::KERNEL_USER_TIMES
Process/Thread System and User Time NtQueryInformationProcess using ProcessTimes NtQueryInformationTh...
Definition: ProcessDescriptor.h:93
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:185
System::currentTime< milliSec >
template longlong currentTime< milliSec >()
System::currentTime< microSec >
template longlong currentTime< microSec >()
gaudirun.c
c
Definition: gaudirun.py:407
System::currentTime< Min >
template longlong currentTime< Min >()
System::systemStart
GAUDI_API longlong systemStart(TimeType typ=Sec)
Maximum processing time left for this process.
Definition: Timing.cpp:119
System::currentTime< Month >
template longlong currentTime< Month >()
ProcessDescriptor.h
System::Min
Definition: Timing.h:58
System
Note: OS specific details for environment resolution.
Definition: Debugger.h:19
System::Times
Definition: SystemBase.h:19
System::QUOTA_LIMITS::TimeLimit
longlong TimeLimit
Definition: ProcessDescriptor.h:39
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:196
System::adjustTime< Native >
long long adjustTime< Native >(long long t)
Definition: Timing.h:262
System::Hour
Definition: Timing.h:58
System::adjustTime< Month >
long long adjustTime< Month >(long long t)
Definition: Timing.h:257
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:164
System::milliSec
Definition: Timing.h:58
System::upTime
GAUDI_API longlong upTime(TimeType typ=Hour)
Maximum processing time left for this process.
Definition: Timing.cpp:131
System::Sec
Definition: Timing.h:58
System::adjustTime< nanoSec >
long long adjustTime< nanoSec >(long long t)
Definition: Timing.h:252
System::tickCount
GAUDI_API longlong tickCount()
Retrieve the number of ticks since system startup.
Definition: Timing.cpp:76
System::microSec
Definition: Timing.h:58
System::adjustTime< Day >
long long adjustTime< Day >(long long t)
Definition: Timing.h:222
__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:138
System::currentTime< Hour >
template longlong currentTime< Hour >()
System::TimeType
TimeType
Time type for conversion.
Definition: Timing.h:58
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:149
System::currentTime< Day >
template longlong currentTime< Day >()
System::currentTime< Native >
template longlong currentTime< Native >()
System::Native
Definition: Timing.h:58
System::currentTime< nanoSec >
template longlong currentTime< nanoSec >()
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:174
System::adjustTime< milliSec >
long long adjustTime< milliSec >(long long t)
Definition: Timing.h:242
System::adjustTime< Year >
long long adjustTime< Year >(long long t)
Definition: Timing.h:217
System::ProcessTime
Simple class to hold the time information of a process.
Definition: Timing.h:147
System::adjustTime< microSec >
long long adjustTime< microSec >(long long t)
Definition: Timing.h:247
System::currentTime
GAUDI_API longlong currentTime()
Retrieve absolute system time.
Definition: Timing.h:269
System::NoFetch
Definition: SystemBase.h:19
System::adjustTime< Min >
long long adjustTime< Min >(long long t)
Definition: Timing.h:232
System::Month
Definition: Timing.h:58
System::currentTime< Sec >
template longlong currentTime< Sec >()
Timing.h
System::nanoSec
Definition: Timing.h:58
System::KERNEL_USER_TIMES::KernelTime
longlong KernelTime
Definition: ProcessDescriptor.h:96
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::getProcess
ProcessDescriptor * getProcess()
Retrieve Process structure.
Definition: ProcessDescriptor.h:135
System::QUOTA_LIMITS
Process Quotas NtQueryInformationProcess using ProcessQuotaLimits NtQueryInformationProcess using Pro...
Definition: ProcessDescriptor.h:33
System::ProcessDescriptor::query
long query(long pid, InfoType info, PROCESS_BASIC_INFORMATION *buffer)
Definition: ProcessDescriptor.cpp:587
System::getProcessTime
GAUDI_API ProcessTime getProcessTime(long pid=-1)
Retrieve the process time data for a process.
Definition: Timing.cpp:208
System::adjustTime< Hour >
long long adjustTime< Hour >(long long t)
Definition: Timing.h:227
System::Year
Definition: Timing.h:58
System::adjustTime< Sec >
long long adjustTime< Sec >(long long t)
Definition: Timing.h:237
System::currentTime< Year >
template longlong currentTime< Year >()
System::KERNEL_USER_TIMES::UserTime
longlong UserTime
Definition: ProcessDescriptor.h:97
System::KERNEL_USER_TIMES::CreateTime
longlong CreateTime
Definition: ProcessDescriptor.h:94
System::InfoType
InfoType
Enumeration for fetching information.
Definition: SystemBase.h:19
System::Day
Definition: Timing.h:58