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

Discussion in 'Python' started by Irmen de Jong, Jun 9, 2004.

  1. 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)
    Irmen de Jong, Jun 9, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Geert Jansen
    Replies:
    1
    Views:
    310
    Dieter Maurer
    Nov 26, 2005
  2. Lars Woetmann
    Replies:
    0
    Views:
    308
    Lars Woetmann
    Mar 23, 2006
  3. MAX2006
    Replies:
    5
    Views:
    5,399
    Allen Chen [MSFT]
    Apr 14, 2009
  4. potatosoftware
    Replies:
    0
    Views:
    652
    potatosoftware
    Nov 4, 2009
  5. Ian Collins
    Replies:
    2
    Views:
    443
    Victor Bazarov
    Nov 30, 2009
Loading...

Share This Page