cProfile, timed call tree

Peter J. Holzer hjp-python at hjp.at
Tue May 29 06:02:58 EDT 2018


On 2018-05-26 07:38:09 +0200, dieter wrote:
> But, in general, you are right: you cannot reconstruct complete
> call trees. The reason is quite simple: maintaining information
> for the complete caller ancestry (rather than just the immediate
> caller) is expensive (both in terms of runtime and storage).
> Profiling usually is used as a preparation for optimization.
> Optimization has the greatest effects if applied to inner loops.
> And for the analysis of inner loops, complete call tree information
> is not necessary.

I disagree. I have used Tim Bunce's excellent perl profiler
(Devel::NYTProf, for the two people here who also use Perl and don't
already know it), which does record whole call trees, and this is very
useful. You not only see that a function is called 1.5 million times,
you also see where it is called (not just from which functions, but from
which lines) and how much time is spent in calls from each location. 
Often this allowed me find ways to avoid calling a function altogether
or prevented me from chasing down the wrong rabbit hole.

Sometimes it is also useful to find out how your code works, when you
get back to it after a few months ;-).

        hp


-- 
   _  | Peter J. Holzer    | we build much bigger, better disasters now
|_|_) |                    | because we have much more sophisticated
| |   | hjp at hjp.at         | management tools.
__/   | http://www.hjp.at/ | -- Ross Anderson <https://www.edge.org/>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20180529/ee859b3b/attachment.sig>


More information about the Python-list mailing list