(no subject)
Skip Montanaro
skip at pobox.com
Thu Oct 4 22:14:05 EDT 2001
Leonardo> Thanks for the tip. I actually have used the explain
Leonardo> statement. But are you sure about the profiler ignoring the
Leonardo> time taken by the query? Why would it be excluded from the
Leonardo> computation time?
If the profiler is measuring cpu seconds, it will be measuring the
computation time of the Python process. The computation time of other
processes involved in the computation (possibly on other machines) just
isn't available to it. If it's measuring elapsed (wall clock) time, then
sure, it gives you some measure of the time it takes for the entire
computation to complete. However, that would include networking delays as
well as delays caused by either or both the Python program and the MySQL
database server not actually having the CPU.
Leonardo> How would the profiler even be able to distinguish between
Leonardo> time waiting in a function for some external process and time
Leonardo> spent in the python interpreter itself?
The profiler uses time.clock() if it's available, which is generally true on
most Unix-like systems. Again, on Unix-like systems, time.clock() returns
the CPU time of the current process, not the elapsed time. From the clock()
man page:
DESCRIPTION
The clock() function returns an approximation of processor
time used by the program.
Leonardo> I checked the manual for the profiler section. It says that
Leonardo> the profiler is activated by callbacks when functions are
Leonardo> called and when they return, so if a function is blocked
Leonardo> waiting for mysql, that time should be computed.
It all depends. Take a look at the code in the Profile class's __init__
method:
if not timer:
if os.name == 'mac':
self.timer = MacOS.GetTicks
self.dispatcher = self.trace_dispatch_mac
self.get_time = _get_time_mac
elif hasattr(time, 'clock'):
self.timer = self.get_time = time.clock
self.dispatcher = self.trace_dispatch_i
elif hasattr(os, 'times'):
self.timer = os.times
self.dispatcher = self.trace_dispatch
self.get_time = _get_time_times
else:
self.timer = self.get_time = time.time
self.dispatcher = self.trace_dispatch_i
If you're running on Windows (I think you said something about Linux), then
time.clock is either unavailable or is, but doesn't record CPU time. On
Linux systems it does (though to varying degrees of (in)accuracy).
--
Skip Montanaro (skip at pobox.com)
http://www.mojam.com/
http://www.musi-cal.com/
More information about the Python-list
mailing list