| The Gaudi Framework v27r1

- 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 <ctime>
19 #include <climits>
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 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 : return adjustTime<Year >(t);
50 case Month : return adjustTime<Month >(t);
51 case Day : return adjustTime<Day >(t);
52 case Hour : return adjustTime<Hour >(t);
53 case Min : return adjustTime<Min >(t);
54 case Sec : return adjustTime<Sec >(t);
55 case milliSec: return adjustTime<milliSec>(t);
56 case microSec: return adjustTime<microSec>(t);
57 case nanoSec : return adjustTime<nanoSec >(t);
58 case Native : return adjustTime<Native >(t);
59 }
60 }
61 return t;
62 }
63
65 longlong System::tickCount() {
66 longlong count = 10000;
67 #ifdef _WIN32
68 count *= ::GetTickCount(); // Number of milliSec since system startup
69 #else
70 struct tms buf;
71 count *= 10*times(&buf);
72 #endif
73 return count;
74 }
75
76 #include <iostream>
77
79 longlong System::currentTime(TimeType typ) {
80 longlong current = 0;
81 #ifdef _WIN32
82 ::GetSystemTimeAsFileTime((FILETIME*)&current);
83 current -= UNIX_BASE_TIME;
84 #else
85 struct timeval tv;
86 struct timezone tz;
87 ::gettimeofday(&tv, &tz);
88 current = tv.tv_sec;
89 current *= 1000000;
90 current += tv.tv_usec;
91 current *= 10;
92 #endif
93 return adjustTime(typ, current);
94 }
95
97 longlong System::systemStart(TimeType typ) {
98 static longlong sys_start = 0;
99 if ( 0 == sys_start ) {
100 longlong c = currentTime(microSec);
101 longlong t = tickCount();
102 sys_start = 10*c - t;
103 }
104 return adjustTime(typ, sys_start);
105 }
106
108 longlong System::upTime(TimeType typ) {
109 static longlong sys_start = 10*systemStart(microSec);
110 return adjustTime(typ, 10*currentTime(microSec)-sys_start);
111 }
112
114 longlong System::creationTime(TimeType typ, InfoType fetch, long pid) {
115 longlong created = 0;
116 KERNEL_USER_TIMES info;
117 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) {
118 created = adjustTime(typ, info.CreateTime-UNIX_BASE_TIME);
119 }
120 return created;
121 }
122
124 longlong System::remainingTime(TimeType typ, InfoType fetch, long pid) {
125 longlong left = 0;
126 QUOTA_LIMITS quota;
127 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &quota) ) {
128 if ( left == -1 ) {
129 //left = _I64_MAX;
130 }
131 else {
132 left = adjustTime(typ, quota.TimeLimit);
133 }
134 }
135 return left;
136 }
137
139 longlong System::ellapsedTime(TimeType typ, InfoType fetch, long pid) {
140 KERNEL_USER_TIMES info;
141 longlong ellapsed = currentTime(microSec)*10;
142 getProcess()->query(pid, fetch, &info);
143 ellapsed = adjustTime(typ, ellapsed+UNIX_BASE_TIME-info.CreateTime);
144 return ellapsed;
145 }
146
148 longlong System::kernelTime(TimeType typ, InfoType fetch, long pid) {
149 KERNEL_USER_TIMES info;
150 longlong kerneltime = 0;
151 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) {
152 kerneltime = adjustTime(typ, info.KernelTime );
153 }
154 return kerneltime;
155 }
156
158 longlong System::userTime(TimeType typ, InfoType fetch, long pid) {
159 longlong usertime = 0;
160 KERNEL_USER_TIMES info;
161 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) {
162 usertime = adjustTime(typ, info.UserTime );
163 }
164 return usertime;
165 }
166
168 longlong System::cpuTime(TimeType typ, InfoType fetch, long pid) {
169 longlong cputime = 0;
170 KERNEL_USER_TIMES info;
171 if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) {
172 cputime = adjustTime(typ, info.KernelTime+info.UserTime );
173 }
174 return cputime;
175 }
176
177 namespace System {
178 ProcessTime getProcessTime(long pid) {
179 KERNEL_USER_TIMES info;
180 if (getProcess()->query(pid, Times, &info)) {
181 return ProcessTime(info.KernelTime,
182 info.UserTime,
183 currentTime(Native) - info.CreateTime);
184 }
185 return ProcessTime(); // return 0s in case of problems
186 }
187 }
System::getProcess
ProcessDescriptor * getProcess()
Retrieve Process structure.
Definition: ProcessDescriptor.cpp:384
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:158
System::systemStart
GAUDI_API longlong systemStart(TimeType typ=Sec)
Maximum processing time left for this process.
Definition: Timing.cpp:97
ProcessDescriptor.h
System::Min
Definition: Timing.h:51
gaudirun.c
tuple c
Definition: gaudirun.py:391
System
Note: OS specific details for environment resolution.
Definition: Debugger.h:19
System::Times
Definition: SystemBase.h:20
System::QUOTA_LIMITS::TimeLimit
longlong TimeLimit
Definition: ProcessDescriptor.h:38
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:168
System::adjustTime< Native >
long long adjustTime< Native >(long long t)
Definition: Timing.h:226
System::Hour
Definition: Timing.h:51
System::adjustTime< Month >
long long adjustTime< Month >(long long t)
Definition: Timing.h:222
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:139
System::milliSec
Definition: Timing.h:51
System::upTime
GAUDI_API longlong upTime(TimeType typ=Hour)
Maximum processing time left for this process.
Definition: Timing.cpp:108
ana.ellapsed
tuple ellapsed
Definition: ana.py:140
System::Sec
Definition: Timing.h:51
System::adjustTime< nanoSec >
long long adjustTime< nanoSec >(long long t)
Definition: Timing.h:218
System::tickCount
GAUDI_API longlong tickCount()
Retrieve the number of ticks since system startup.
Definition: Timing.cpp:65
System::microSec
Definition: Timing.h:51
System::adjustTime< Day >
long long adjustTime< Day >(long long t)
Definition: Timing.h:194
__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:114
System::TimeType
TimeType
Time type for conversion.
Definition: Timing.h:51
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:124
System::Native
Definition: Timing.h:51
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:148
System::adjustTime< milliSec >
long long adjustTime< milliSec >(long long t)
Definition: Timing.h:210
System::adjustTime< Year >
long long adjustTime< Year >(long long t)
Definition: Timing.h:190
System::ProcessTime
Simple class to hold the time information of a process.
Definition: Timing.h:133
System::adjustTime< microSec >
long long adjustTime< microSec >(long long t)
Definition: Timing.h:214
System::NoFetch
Definition: SystemBase.h:18
System::adjustTime< Min >
long long adjustTime< Min >(long long t)
Definition: Timing.h:202
System::Month
Definition: Timing.h:51
Timing.h
System::nanoSec
Definition: Timing.h:51
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::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:638
System::getProcessTime
GAUDI_API ProcessTime getProcessTime(long pid=-1)
Retrieve the process time data for a process.
Definition: Timing.cpp:178
System::adjustTime< Hour >
long long adjustTime< Hour >(long long t)
Definition: Timing.h:198
System::Year
Definition: Timing.h:51
System::adjustTime< Sec >
long long adjustTime< Sec >(long long t)
Definition: Timing.h:206
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:18
System::Day
Definition: Timing.h:51
System::currentTime
GAUDI_API longlong currentTime(TimeType typ=milliSec)
Retrieve absolute system time.
Definition: Timing.cpp:79