profiling threads

Ian McMeans imcmeans at telus.net
Tue Feb 25 18:23:20 EST 2003


Does anyone have advice on how I can profile a threaded program?

I'm able to do it, but I'm having a hard time finding out what my actual CPU
usage is, as opposed to the running time of the proram.

My program has a bunch of threads, and something (I don't know what) is
using 100% of my CPU time whenever the program runs. The main thread spends
most of it's time in the .wait(2) function, waiting for the child threads to
complete, so it's not the main thread that's using the CPU.

For each thread in my program, I've dumped a profile to my hard drive.
However, when I analyze these profiles, I see things like this:


Tue Feb 25 15:15:06 2003    f:\source\pget\thread-1.profile

         9467 function calls (9379 primitive calls) in 158.547 CPU seconds

   Ordered by: internal time
   List reduced from 150 to 10 due to restriction <10>

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        4  150.255   37.564  150.255   37.564 httplib.py:299(_safe_read)
       14    2.944    0.210    3.134    0.224 httplib.py:113(begin)
       14    1.281    0.092    1.281    0.092 httplib.py:359(connect)
        8    0.752    0.094  152.759   19.095
pget.py:352(save_file_if_neccesary)
        1    0.522    0.522  158.426  158.426 pget.py:246(handle_all_urlsx)

This doesn't explain my CPU usage, though. I'm not surprised that files took
30 seconds on average to download, that's not what I care about. What's
bothering me is that for some reason, it's using 100% CPU while it's
running. I doubt the htpplib functions are eating my CPU, so what's going
on?






More information about the Python-list mailing list