Gaudi Framework, version v23r6

Home   Generated: Wed Jan 30 2013
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Timing.cpp
Go to the documentation of this file.
1 // $Id: Timing.cpp,v 1.3 2002/11/12 18:34:30 mato Exp $
2 //====================================================================
3 // Timing.cpp
4 //--------------------------------------------------------------------
5 //
6 // Package : System (The LHCb System service)
7 //
8 // Description: Implementation of Systems internals
9 //
10 // Author : M.Frank
11 // Created : 13/1/99
12 // Changes :
13 //====================================================================
14 #define GAUDIKERNEL_TIMING_CPP
15 
16 #include "GaudiKernel/Timing.h"
17 #include "ProcessDescriptor.h"
18 
19 #include <ctime>
20 #include <climits>
21 #ifdef _WIN32
22 #include <windows.h>
23 #else
24 #include <sys/time.h>
25 #include <sys/times.h>
26 #include <unistd.h>
27 #endif
28 
29 #ifdef _WIN32
30 static const longlong UNIX_BASE_TIME = 116444736000000000;
31 #else
32 static const longlong UNIX_BASE_TIME = 0;
33 #endif
34 
35 // convert time from internal representation to the appropriate type
36 // Internal representation for WIN32: 100 nanosecond intervals
37 // Unix: 1 clock tick (usually 10 milliseconds)
39  if ( t != -1 ) {
40 #ifndef _WIN32
41 
42  // t /= CLK_TCK ; // needs division by clock tick unit
46 
48 #endif
49  switch( typ ) {
50  case Year : return adjustTime<Year >(t);
51  case Month : return adjustTime<Month >(t);
52  case Day : return adjustTime<Day >(t);
53  case Hour : return adjustTime<Hour >(t);
54  case Min : return adjustTime<Min >(t);
55  case Sec : return adjustTime<Sec >(t);
56  case milliSec: return adjustTime<milliSec>(t);
57  case microSec: return adjustTime<microSec>(t);
58  case nanoSec : return adjustTime<nanoSec >(t);
59  case Native : return adjustTime<Native >(t);
60  }
61  }
62  return t;
63 }
64 
67  longlong count = 10000;
68 #ifdef _WIN32
69  count *= ::GetTickCount(); // Number of milliSec since system startup
70 #else
71  struct tms buf;
72  count *= 10*times(&buf);
73 #endif
74  return count;
75 }
76 
77 #include <iostream>
78 
81  longlong current = 0;
82 #ifdef _WIN32
83  ::GetSystemTimeAsFileTime((FILETIME*)&current);
84  current -= UNIX_BASE_TIME;
85 #else
86  struct timeval tv;
87  struct timezone tz;
88  ::gettimeofday(&tv, &tz);
89  current = tv.tv_sec;
90  current *= 1000000;
91  current += tv.tv_usec;
92  current *= 10;
93 #endif
94  return adjustTime(typ, current);
95 }
96 
99  static longlong sys_start = 0;
100  if ( 0 == sys_start ) {
102  longlong t = tickCount();
103  sys_start = 10*c - t;
104  }
105  return adjustTime(typ, sys_start);
106 }
107 
110  static longlong sys_start = 10*systemStart(microSec);
111  return adjustTime(typ, 10*currentTime(microSec)-sys_start);
112 }
113 
116  longlong created = 0;
117  KERNEL_USER_TIMES info;
118  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) {
119  created = adjustTime(typ, info.CreateTime-UNIX_BASE_TIME);
120  }
121  return created;
122 }
123 
126  longlong left = 0;
127  QUOTA_LIMITS quota;
128  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &quota) ) {
129  if ( left == -1 ) {
130  //left = _I64_MAX;
131  }
132  else {
133  left = adjustTime(typ, quota.TimeLimit);
134  }
135  }
136  return left;
137 }
138 
141  KERNEL_USER_TIMES info;
143  getProcess()->query(pid, fetch, &info);
144  ellapsed = adjustTime(typ, ellapsed+UNIX_BASE_TIME-info.CreateTime);
145  return ellapsed;
146 }
147 
150  KERNEL_USER_TIMES info;
151  longlong kerneltime = 0;
152  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) {
153  kerneltime = adjustTime(typ, info.KernelTime );
154  }
155  return kerneltime;
156 }
157 
160  longlong usertime = 0;
161  KERNEL_USER_TIMES info;
162  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) {
163  usertime = adjustTime(typ, info.UserTime );
164  }
165  return usertime;
166 }
167 
169 longlong System::cpuTime(TimeType typ, InfoType fetch, long pid) {
170  longlong cputime = 0;
171  KERNEL_USER_TIMES info;
172  if ( fetch != NoFetch && getProcess()->query(pid, fetch, &info) ) {
173  cputime = adjustTime(typ, info.KernelTime+info.UserTime );
174  }
175  return cputime;
176 }
177 
178 namespace System {
180  KERNEL_USER_TIMES info;
181  if (getProcess()->query(pid, Times, &info)) {
182  return ProcessTime(info.KernelTime,
183  info.UserTime,
184  currentTime(Native) - info.CreateTime);
185  }
186  return ProcessTime(); // return 0s in case of problems
187  }
188 }

Generated at Wed Jan 30 2013 17:13:40 for Gaudi Framework, version v23r6 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004