gak / pycallgraph

pycallgraph is a Python module that creates call graphs for Python programs.
GNU General Public License v2.0
1.83k stars 335 forks source link

Explicit vs Implicit Filtering #179

Open rmorshea opened 6 years ago

rmorshea commented 6 years ago

It would be valuable for users to be able to distinguish between what I'll call "implicit" and "explicit" filtering of calls within the stack. To explain what I mean by this I will refer to a slightly modified example from the docs:

no_filter

In this modified case we include an additional public_function which gets called by secret_function. Now if we want to filter out the secret, the fact that a call to eat leads to public_function is implicit (i.e. there is no line connecting their respective nodes):

implicit_filter_exclude

What I propose is that there be an option to make the connection between eat and public_function "explicit" while still hiding secret_function. I came across a need for this functionality while trying to filter out the presence of a particularly widespread decorator from my call graph. However after having filtered out the decorator my graph became unreadable due to the fact that all call relationships that included it were removed completely (as I demonstrate above).

To overcome the issue of implicit filtering, we would want a graph that looked like this:

explicit_filter_exclude

To do so we can simply replace this line with:

self.call_stack.append(self.call_stack[-1])

I am unsure of whether this is truly the correct way to implement this feature though...