Back to index

python3.2  3.2.2
Functions | Variables
systimes Namespace Reference

Functions

def getrusage_systimes
 Implementations.
def process_time_clock_systimes
def wall_clock_clock_systimes
def wall_clock_time_systimes
def win32process_getprocesstimes_systimes
def ctypes_getprocesstimes_systimes
def processtime
def some_workload
 Testing.
def test_workload
def test_idle

Variables

 SYSTIMES_IMPLEMENTATION = None
 Choose an implementation.
string USE_CTYPES_GETPROCESSTIMES = 'ctypes GetProcessTimes() wrapper'
string USE_WIN32PROCESS_GETPROCESSTIMES = 'win32process.GetProcessTimes()'
string USE_RESOURCE_GETRUSAGE = 'resource.getrusage()'
string USE_PROCESS_TIME_CLOCK = 'time.clock() (process time)'
string USE_WALL_TIME_CLOCK = 'time.clock() (wall-clock)'
string USE_WALL_TIME_TIME = 'time.time() (wall-clock)'
tuple start = time.clock()
tuple stop = time.clock()
int WIN32_PROCESS_TIMES_TICKS_PER_SECOND = 1
 systimes = getrusage_systimes

Function Documentation

Definition at line 133 of file systimes.py.

00133 
00134 def ctypes_getprocesstimes_systimes():
00135     creationtime = ctypes.c_ulonglong()
00136     exittime = ctypes.c_ulonglong()
00137     kerneltime = ctypes.c_ulonglong()
00138     usertime = ctypes.c_ulonglong()
00139     rc = ctypes.windll.kernel32.GetProcessTimes(
00140         ctypes.windll.kernel32.GetCurrentProcess(),
00141         ctypes.byref(creationtime),
00142         ctypes.byref(exittime),
00143         ctypes.byref(kerneltime),
00144         ctypes.byref(usertime))
00145     if not rc:
00146         raise TypeError('GetProcessTimes() returned an error')
00147     return (usertime.value / WIN32_PROCESS_TIMES_TICKS_PER_SECOND,
00148             kerneltime.value / WIN32_PROCESS_TIMES_TICKS_PER_SECOND)
00149 
00150 # Select the default for the systimes() function

Implementations.

Definition at line 103 of file systimes.py.

00103 
00104 def getrusage_systimes():
00105     return resource.getrusage(resource.RUSAGE_SELF)[:2]

Definition at line 106 of file systimes.py.

00106 
00107 def process_time_clock_systimes():
00108     return (time.clock(), 0.0)

Return the total time spent on the process.

    This is the sum of user and system time as returned by
    systimes().

Definition at line 172 of file systimes.py.

00172 
00173 def processtime():
00174 
00175     """ Return the total time spent on the process.
00176 
00177         This is the sum of user and system time as returned by
00178         systimes().
00179 
00180     """
00181     user, system = systimes()
00182     return user + system

Testing.

Definition at line 185 of file systimes.py.

00185 
00186 def some_workload():
00187     x = 0
00188     for i in range(10000000):
00189         x = x + 1

Here is the caller graph for this function:

Definition at line 200 of file systimes.py.

00200 
00201 def test_idle():
00202     print('Testing systimes() under idle conditions')
00203     t0 = systimes()
00204     time.sleep(1)
00205     t1 = systimes()
00206     print('before:', t0)
00207     print('after:', t1)
00208     print('differences:', (t1[0] - t0[0], t1[1] - t0[1]))
00209     print()

Here is the call graph for this function:

Definition at line 190 of file systimes.py.

00190 
00191 def test_workload():
00192     print('Testing systimes() under load conditions')
00193     t0 = systimes()
00194     some_workload()
00195     t1 = systimes()
00196     print('before:', t0)
00197     print('after:', t1)
00198     print('differences:', (t1[0] - t0[0], t1[1] - t0[1]))
00199     print()

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 109 of file systimes.py.

00109 
00110 def wall_clock_clock_systimes():
00111     return (time.clock(), 0.0)

Definition at line 112 of file systimes.py.

00112 
00113 def wall_clock_time_systimes():
00114     return (time.time(), 0.0)
00115 
00116 # Number of clock ticks per second for the values returned
00117 # by GetProcessTimes() on Windows.
00118 #
00119 # Note: Ticks returned by GetProcessTimes() are 100ns intervals on
00120 # Windows XP. However, the process times are only updated with every
00121 # clock tick and the frequency of these is somewhat lower: depending
00122 # on the OS version between 10ms and 15ms. Even worse, the process
00123 # time seems to be allocated to process currently running when the
00124 # clock interrupt arrives, ie. it is possible that the current time
00125 # slice gets accounted to a different process.

Definition at line 128 of file systimes.py.

00128 
00129 def win32process_getprocesstimes_systimes():
00130     d = win32process.GetProcessTimes(win32process.GetCurrentProcess())
00131     return (d['UserTime'] / WIN32_PROCESS_TIMES_TICKS_PER_SECOND,
00132             d['KernelTime'] / WIN32_PROCESS_TIMES_TICKS_PER_SECOND)


Variable Documentation

tuple systimes.start = time.clock()

Definition at line 89 of file systimes.py.

tuple systimes.stop = time.clock()

Definition at line 91 of file systimes.py.

Definition at line 152 of file systimes.py.

Choose an implementation.

Definition at line 53 of file systimes.py.

string systimes.USE_CTYPES_GETPROCESSTIMES = 'ctypes GetProcessTimes() wrapper'

Definition at line 54 of file systimes.py.

string systimes.USE_PROCESS_TIME_CLOCK = 'time.clock() (process time)'

Definition at line 57 of file systimes.py.

string systimes.USE_RESOURCE_GETRUSAGE = 'resource.getrusage()'

Definition at line 56 of file systimes.py.

string systimes.USE_WALL_TIME_CLOCK = 'time.clock() (wall-clock)'

Definition at line 58 of file systimes.py.

string systimes.USE_WALL_TIME_TIME = 'time.time() (wall-clock)'

Definition at line 59 of file systimes.py.

string systimes.USE_WIN32PROCESS_GETPROCESSTIMES = 'win32process.GetProcessTimes()'

Definition at line 55 of file systimes.py.

Definition at line 126 of file systimes.py.