Getting line-level timings using hotshot

P

Paul McGuire

I've googled and scanned docs and tried and errored, but have not seemed to
find the right combination of steps to get line-level timing and profiling
using hotshot.

From the docs, I *think* I'm supposed to:

1. Create a hotshot.Profile object, giving the name of the output stats
file, and setting the lineevents and linetimings arguments to 1.
2. Run the code to be timed using the Profile object's run() method.
3. Close the output file by calling the Profile object's close() method.

This should create an output stats file containing the lineevents, with
timing information.

Now, I need to create a hotshot.stats StatsLoader object, using
hotshot.stats.load(filename).

At this point, things get fuzzier for me. The examples I find on the web
typically follow load() with a call to strip_dirs(), but without much
explanation why.

Then the crucial question - what are the args to pass to sort_stats()? I
can enumerate the options, but I'm afraid none of them are self-evident.
Here is the table of options from the ActivePython online docs:

'calls' = call count
'cumulative' = cumulative time
'file' = file name
'module' = file name
'pcalls' = primitive call count
'line' = line number
'name' = function name
'nfl' = name/file/line
'stdname' = standard name
'time' = internal time

(This question is complicated by the ability to specify multiple options in
the sort_stats() call. But no matter what combination I try, I still only
get function level time reporting.)

Lastly, print_stats(n) gets called, to list out the 'n' highest entries in
the sorted list.

Can anyone help me out? I know which functions are most time consuming now,
but what lines in those functions? What are the missing steps to get line
level timing for performance tuning?

Thanks,
-- Paul
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top