export pycallgraphcopy=~/temp/pycallgraphcopy.dot
Pycallgraph is great, but it's also not maintained anymore.
-
open
<your env>/lib/python2.7/site-packages/pycallgraph/output/graphviz.py
-
add the following lines in the
def done
:
def done(self):
source = self.generate()
self.debug(source)
fd, temp_name = tempfile.mkstemp()
with os.fdopen(fd, 'w') as f:
f.write(source)
#>>>> this sneaks out a copy before the temp dot file is used
import shutil
copytgt = os.getenv("pycallgraphcopy")
if copytgt:
shutil.copyfile(temp_name, copytgt)
#<<<<< thats it here
create the file re.filter.txt
\s+"logging
\s+"threading
\s+"unittest
\s+"repr\.Repr
\s+"gettext
This uses a negative -v
grep to filter out all the nodes you don't want to see, ** and their descendants**
https://gist.github.com/blabber/74b8d9ed59d0b2ad0d7a734113996424
gvpr
will run reduce.g
to select only children and ancestors of the node you want to select.
Note: I didn't write reduce.g
and have no clue how it works.
Permissions: chmod u+x filterdot.sh
This script will
- run the grep to filter out the noise like logging calls.
- fire
reduce.g
to select all the nodes beneath the node you give as an argument. - run
dot
to generate an svg.
Basically if you ran pycallgraph via unittest but you only want to see what's in MyTestClass.test_i_want
you can use that script to only show things that happened there.
- find a way to trigger
pycallgraph
svg generation. - go to the work directory you created in step 2.
- run
filterdot.sh "MyTestClass.test_i_want"
- open the generated
selected.node.svg