hotshot profiler: how to distinguish between cpu time and wait (idle) time?

Irmen de Jong irmen at -NOSPAM-REMOVETHIS-xs4all.nl
Wed Jun 9 09:33:57 EDT 2004


Hi,
when using the hotshot profiler, I can see no difference in the
measurement of a function that is busy eating CPU cycles, and
a function that is blocking/waiting on IO (or sleeping)...

For instance I have this output:

     3 function calls in 26.931 CPU seconds

Ordered by: internal time, call count
ncalls  tottime  percall  cumtime  percall filename:lineno(function)
      1   13.465   13.465   13.465   13.465 testprof.py:5(cpu)
      1   13.464   13.464   13.464   13.464 testprof.py:9(sleep)
      1    0.002    0.002   26.931   26.931 testprof.py:12(main)
      0    0.000             0.000          profile:0(profiler)

My test program (see below) consists of two functions called sequentially:
a cpu() function eating 13+ seconds of CPU cycles when calculating
sha-hashes, and a sleep() function that only has time.sleep(13) in it.

What would be really useful, is that the profiler would show that sleep()
is actually not doing *anything*, while cpu() is doing all the hard work.
I.E.: measure CPU-time, not user-time.

How do I do this? Is this possible? (I'm using Python 2.3.4)

Thanks!!
--Irmen de Jong.

--------------- test program ------------------
import hotshot, hotshot.stats
import time
import sha

def cpu():
     for i in range(1000000):
         a=sha.sha("abcdefghijklmnopqrstuvwxyz").hexdigest()

def sleep():
     time.sleep(13)

def main():
     print "cpu..."
     cpu()
     print "sleep..."
     sleep()
     print "done"

prof = hotshot.Profile("/tmp/test.prof")
result = prof.runcall(main)
prof.close()
print "PROFILE DONE, result=",result,type(result)
stats = hotshot.stats.load("/tmp/test.prof")
stats.strip_dirs()
stats.sort_stats('time', 'calls')
stats.print_stats(20)




More information about the Python-list mailing list