cProfile, timed call tree

dieter dieter at handshake.de
Wed May 30 01:45:07 EDT 2018


"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.




More information about the Python-list mailing list