Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Filter out pycallgraph nodes #42

Closed
gak opened this issue Aug 12, 2009 · 5 comments
Closed

Filter out pycallgraph nodes #42

gak opened this issue Aug 12, 2009 · 5 comments

Comments

@gak
Copy link
Owner

gak commented Aug 12, 2009

No description provided.

@gak
Copy link
Owner Author

gak commented Aug 12, 2009

Author: gak

@gak
Copy link
Owner Author

gak commented Aug 12, 2009

Author: Alec Thomas alec@swapoff.org
I think a general callback filter would be the most elegant solution. Perhaps the following signature:

{{{
#!python
def filter(depth, module, thing):
return True
}}}

Then perhaps have some useful utility filters builtin:

{{{
#!python
import fnmatch

class GlobFilter(object):
def init(self, include=[], exclude=[]):
...

def __call__(self, depth, module, thing):
   # Match module.thing against the include/exclude glob lists
   ...

}}}

@gak
Copy link
Owner Author

gak commented Aug 12, 2009

Author: Alec Thomas alec@swapoff.org
Here's an example of a custom filter which subclasses the default !GlobbingFilter and prints as it traces:

{{{
#!python
import pycallgraph

class Filter(pycallgraph.GlobbingFilter):
def call(self, stack, module, cls, func, full_name):
if pycallgraph.GlobbingFilter.call(self, stack, module, cls, func, full_name):
print ' ' * len(stack) + full_name

pycallgraph.start_trace(filter=Filter(exclude=['pycallgraph.*']))

def foo():
print "foo()"

def bar():
foo()
foo()

bar()

pycallgraph.make_graph('test.png')
}}}

@gak
Copy link
Owner Author

gak commented Aug 12, 2009

Author: Alec Thomas alec@swapoff.org
Or a more basic trace:

{{{
#!python
def print_me(stack, module, cls, func, full_name):
print ' ' * len(stack) + full_name

pycallgraph.start_trace(filter=print_me)
}}}

@gak
Copy link
Owner Author

gak commented Aug 12, 2009

Author: gak

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant