| The Gaudi Framework v32r1 (f65d50dc)

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 long long UNIX_BASE_TIME = 116444736000000000;
30 #else
31 static const long long 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 long long System::adjustTime( TimeType typ, long long t ) {
38 if ( t != -1 ) {
39 #ifndef _WIN32
40 // t /= CLK_TCK ; // needs division by clock tick unit
45
47 #endif
48 switch ( typ ) {
49 case Year:
50 return adjustTime<Year>( t );
51 case Month:
52 return adjustTime<Month>( t );
53 case Day:
54 return adjustTime<Day>( t );
55 case Hour:
56 return adjustTime<Hour>( t );
57 case Min:
58 return adjustTime<Min>( t );
59 case Sec:
60 return adjustTime<Sec>( t );
61 case milliSec:
62 return adjustTime<milliSec>( t );
63 case microSec:
64 return adjustTime<microSec>( t );
65 case nanoSec:
66 return adjustTime<nanoSec>( t );
67 case Native:
68 return adjustTime<Native>( t );
69 default:
70 return t;
71 }
72 }
73 return t;
74 }
75
77 long long System::tickCount() {
78 long long 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 long long System::currentTime( TimeType typ ) {
92 switch ( typ ) {
93 case Year:
94 return currentTime<Year>();
95 case Month:
96 return currentTime<Month>();
97 case Day:
98 return currentTime<Day>();
99 case Hour:
100 return currentTime<Hour>();
101 case Min:
102 return currentTime<Min>();
103 case Sec:
104 return currentTime<Sec>();
105 case milliSec:
106 return currentTime<milliSec>();
107 case microSec:
108 return currentTime<microSec>();
109 case nanoSec:
110 return currentTime<nanoSec>();
111 case Native:
112 return currentTime<Native>();
113 }
114 return currentTime<Native>();
115 }
116
118 long long System::systemStart( TimeType typ ) {
119 static long long sys_start = 0;
120 if ( 0 == sys_start ) {
121 long long c = currentTime( microSec );
122 long long t = tickCount();
123 sys_start = 10 * c - t;
124 }
125 return adjustTime( typ, sys_start );
126 }
127
129 long long System::upTime( TimeType typ ) {
130 static long long sys_start = 10 * systemStart( microSec );
131 return adjustTime( typ, 10 * currentTime( microSec ) - sys_start );
132 }
133
135 long long System::creationTime( TimeType typ, InfoType fetch, long pid ) {
136 long long created = 0;
137 KERNEL_USER_TIMES info;
138 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) {
139 created = adjustTime( typ, info.CreateTime - UNIX_BASE_TIME );
140 }
141 return created;
142 }
143
145 long long System::remainingTime( TimeType typ, InfoType fetch, long pid ) {
146 long long left = 0;
147 QUOTA_LIMITS quota;
148 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &quota ) ) {
149 if ( left == -1 ) {
150 // left = _I64_MAX;
151 } else {
152 left = adjustTime( typ, quota.TimeLimit );
153 }
154 }
155 return left;
156 }
157
159 long long System::ellapsedTime( TimeType typ, InfoType fetch, long pid ) {
160 KERNEL_USER_TIMES info;
161 long long ellapsed = currentTime( microSec ) * 10;
162 getProcess()->query( pid, fetch, &info );
163 ellapsed = adjustTime( typ, ellapsed + UNIX_BASE_TIME - info.CreateTime );
164 return ellapsed;
165 }
166
168 long long System::kernelTime( TimeType typ, InfoType fetch, long pid ) {
169 KERNEL_USER_TIMES info;
170 long long kerneltime = 0;
171 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) {
172 kerneltime = adjustTime( typ, info.KernelTime );
173 }
174 return kerneltime;
175 }
176
178 long long System::userTime( TimeType typ, InfoType fetch, long pid ) {
179 long long usertime = 0;
180 KERNEL_USER_TIMES info;
181 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) { usertime = adjustTime( typ, info.UserTime ); }
182 return usertime;
183 }
184
186 long long System::cpuTime( TimeType typ, InfoType fetch, long pid ) {
187 long long cputime = 0;
188 KERNEL_USER_TIMES info;
189 if ( fetch != NoFetch && getProcess()->query( pid, fetch, &info ) ) {
190 cputime = adjustTime( typ, info.KernelTime + info.UserTime );
191 }
192 return cputime;
193 }
194
195 namespace System {
196 ProcessTime getProcessTime( long pid ) {
197 KERNEL_USER_TIMES info;
198 if ( getProcess()->query( pid, Times, &info ) ) {
199 return ProcessTime( info.KernelTime, info.UserTime, currentTime<Native>() - info.CreateTime );
200 }
201 return ProcessTime(); // return 0s in case of problems
202 }
203 } // namespace System
System::KERNEL_USER_TIMES::KernelTime
long long KernelTime
Definition: ProcessDescriptor.h:95
System::creationTime
GAUDI_API long long creationTime(TimeType typ=milliSec, InfoType fetch=Times, long pid=-1)
Process Creation time.
Definition: Timing.cpp:135
System::KERNEL_USER_TIMES
Process/Thread System and User Time NtQueryInformationProcess using ProcessTimes NtQueryInformationTh...
Definition: ProcessDescriptor.h:92
gaudirun.c
c
Definition: gaudirun.py:487
System::currentTime< Month >
template long long currentTime< Month >()
ProcessDescriptor.h
System::Min
Definition: Timing.h:57
System
Note: OS specific details for environment resolution.
Definition: Debugger.h:19
System::Times
Definition: SystemBase.h:18
System::KERNEL_USER_TIMES::UserTime
long long UserTime
Definition: ProcessDescriptor.h:96
System::currentTime< Year >
template long long currentTime< Year >()
System::adjustTime< Native >
long long adjustTime< Native >(long long t)
Definition: Timing.h:244
System::Hour
Definition: Timing.h:57
System::adjustTime< Month >
long long adjustTime< Month >(long long t)
Definition: Timing.h:240
System::milliSec
Definition: Timing.h:57
System::currentTime< Hour >
template long long currentTime< Hour >()
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:145
System::Sec
Definition: Timing.h:57
System::adjustTime< nanoSec >
long long adjustTime< nanoSec >(long long t)
Definition: Timing.h:236
System::currentTime
GAUDI_API long long currentTime()
Retrieve absolute system time.
Definition: Timing.h:250
System::microSec
Definition: Timing.h:57
System::adjustTime< Day >
long long adjustTime< Day >(long long t)
Definition: Timing.h:212
System::TimeType
TimeType
Time type for conversion.
Definition: Timing.h:57
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:168
System::Native
Definition: Timing.h:57
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:178
System::KERNEL_USER_TIMES::CreateTime
long long CreateTime
Definition: ProcessDescriptor.h:93
System::QUOTA_LIMITS::TimeLimit
long long TimeLimit
Definition: ProcessDescriptor.h:38
System::adjustTime< milliSec >
long long adjustTime< milliSec >(long long t)
Definition: Timing.h:228
System::adjustTime< Year >
long long adjustTime< Year >(long long t)
Definition: Timing.h:208
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:232
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:159
System::NoFetch
Definition: SystemBase.h:18
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:186
System::tickCount
GAUDI_API long long tickCount()
Retrieve the number of ticks since system startup.
Definition: Timing.cpp:77
System::upTime
GAUDI_API long long upTime(TimeType typ=Hour)
Maximum processing time left for this process.
Definition: Timing.cpp:129
System::adjustTime< Min >
long long adjustTime< Min >(long long t)
Definition: Timing.h:220
System::currentTime< Sec >
template long long currentTime< Sec >()
System::Month
Definition: Timing.h:57
System::currentTime< Min >
template long long currentTime< Min >()
Timing.h
System::currentTime< Native >
template long long currentTime< Native >()
System::currentTime< milliSec >
template long long currentTime< milliSec >()
System::currentTime< Day >
template long long currentTime< Day >()
System::nanoSec
Definition: Timing.h:57
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:37
System::getProcess
ProcessDescriptor * getProcess()
Retrieve Process structure.
Definition: ProcessDescriptor.h:132
System::QUOTA_LIMITS
Process Quotas NtQueryInformationProcess using ProcessQuotaLimits NtQueryInformationProcess using Pro...
Definition: ProcessDescriptor.h:32
System::ProcessDescriptor::query
long query(long pid, InfoType info, PROCESS_BASIC_INFORMATION *buffer)
Definition: ProcessDescriptor.cpp:584
System::getProcessTime
GAUDI_API ProcessTime getProcessTime(long pid=-1)
Retrieve the process time data for a process.
Definition: Timing.cpp:196
System::adjustTime< Hour >
long long adjustTime< Hour >(long long t)
Definition: Timing.h:216
System::currentTime< nanoSec >
template long long currentTime< nanoSec >()
System::Year
Definition: Timing.h:57
System::adjustTime< Sec >
long long adjustTime< Sec >(long long t)
Definition: Timing.h:224
System::currentTime< microSec >
template long long currentTime< microSec >()
System::systemStart
GAUDI_API long long systemStart(TimeType typ=Sec)
Maximum processing time left for this process.
Definition: Timing.cpp:118
System::InfoType
InfoType
Enumeration for fetching information.
Definition: SystemBase.h:18
System::Day
Definition: Timing.h:57