cProfile, timed call tree

Peter J. Holzer hjp-python at hjp.at
Wed May 30 17:10:44 EDT 2018


On 2018-05-30 07:45:07 +0200, dieter wrote:
> "Peter J. Holzer" <hjp-python at hjp.at> writes:
> > 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.
> 
> If the profile information is sampled for the call location (rather then
> the call function), you still do not get the "complete call tree".
> If you want to get results based on call paths (rather than the immediate
> caller), the sampling must (in general) sample for call paths (and
> not only the immediate caller) -- which means, you must implement
> your own profiler.

I don't dispute that you would have to implement your own profiler.
I do dispute that this information is useless. As I said, I have used
Devel::NYTProf for Perl, and after using that cProfile feels like a huge
step backwards. There are some areas where Python is ahead of Perl, but
the profiler definitely isn't one of them :-(.

        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/20180530/9f36de34/attachment.sig>


More information about the Python-list mailing list