I'm using pycallgraph from the command line to profile and draw the call graph of a relatively simple program. However, the resulting image includes the internals of standard libraries (threading, json, socket) even though I don't use the -s command line option. Using the -e option to exclude those modules has no effect and using -i results in an empty call graph. I've also tried cProfile, but it only graphs the main thread.
How can I make pycallgraph to only show calls in my code? The current messy result is useless.
Edit: I'm using 0.5.1, available via easy_install. Running pycallgraph ./cursesclient.py outputs this: . As you can see, pycallgraph show the internals of modules json, re, encodings, socket and threading. Re and encodings are never even called directly in my code, but through json and socket, respectively.
Pycallgraph provides filtering capabilities to filter out any module, class or function you would like to exclude from call graph. Following function should be defined before you start the trace and passed to pycallgraph
Example
def filtercalls(call_stack, modul, clas, func, full):
mod_ignore = ['shutil','scipy.optimize','re','os','sys','json']
func_ignore = ['CustomFunctionName','pdbcall']
clas_ignore = ['pdb']
return modul not in mod_ignore and func not in func_ignore and clas not in clas_ignore
The pycallgraph trace start is
pycallgraph.start_trace(filter_func=filtercalls)
This way, any module, class or function you provide in filtercalls will be removed. Please note that many time in standard libraries providing just the module name is not enough. Thus, including numpy in mod_ignore will still result in numpy.core being included
pycallgraph has an undocumented stop_trace() method that you can use to exclude sections of code. Something like
import pycallgraph
import mycode
import stuff_i_dont_want_to_see
pycallgraph.start_trace()
#Initializations
pycallgraph.stop_trace()
stuff_i_dont_want_to_see()
pycallgraph.start_trace()
mycode.things()
pycallgraph.make_dot_graph('cleaner_graph.png')
Is that what you're after?
source
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With