| 1 | #!/usr/bin/env python |
|---|
| 2 | """ |
|---|
| 3 | pycallgraph |
|---|
| 4 | |
|---|
| 5 | U{http://pycallgraph.slowchop.com/} |
|---|
| 6 | |
|---|
| 7 | Copyright Gerald Kaszuba 2007 |
|---|
| 8 | |
|---|
| 9 | This program is free software; you can redistribute it and/or modify |
|---|
| 10 | it under the terms of the GNU General Public License as published by |
|---|
| 11 | the Free Software Foundation; either version 2 of the License, or |
|---|
| 12 | (at your option) any later version. |
|---|
| 13 | |
|---|
| 14 | This program is distributed in the hope that it will be useful, |
|---|
| 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 17 | GNU General Public License for more details. |
|---|
| 18 | |
|---|
| 19 | You should have received a copy of the GNU General Public License |
|---|
| 20 | along with this program; if not, write to the Free Software |
|---|
| 21 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|---|
| 22 | """ |
|---|
| 23 | |
|---|
| 24 | """ |
|---|
| 25 | This example demonstrates the use of filtering. |
|---|
| 26 | """ |
|---|
| 27 | import pycallgraph |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | class Banana: |
|---|
| 31 | |
|---|
| 32 | def __init__(self): |
|---|
| 33 | pass |
|---|
| 34 | |
|---|
| 35 | def eat(self): |
|---|
| 36 | self.secret_function() |
|---|
| 37 | |
|---|
| 38 | def secret_function(self): |
|---|
| 39 | pass |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | def filter_exclude(): |
|---|
| 43 | filter_func = pycallgraph.GlobbingFilter(exclude=['pycallgraph.*', \ |
|---|
| 44 | '*.secret_function']) |
|---|
| 45 | pycallgraph.start_trace(filter_func=filter_func) |
|---|
| 46 | banana = Banana() |
|---|
| 47 | banana.eat() |
|---|
| 48 | pycallgraph.make_dot_graph('filter-exclude.png') |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | def filter_include(): |
|---|
| 52 | filter_func = pycallgraph.GlobbingFilter(include=['*.secret_function', \ |
|---|
| 53 | 'Banana.__init__']) |
|---|
| 54 | pycallgraph.start_trace(filter_func=filter_func) |
|---|
| 55 | banana = Banana() |
|---|
| 56 | banana.eat() |
|---|
| 57 | pycallgraph.make_dot_graph('filter-include.png') |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | def filter_max_depth(): |
|---|
| 61 | filter_func = pycallgraph.GlobbingFilter(max_depth=1) |
|---|
| 62 | pycallgraph.start_trace(filter_func=filter_func) |
|---|
| 63 | banana = Banana() |
|---|
| 64 | banana.eat() |
|---|
| 65 | pycallgraph.make_dot_graph('filter-max-depth.png') |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | def main(): |
|---|
| 69 | filter_exclude() |
|---|
| 70 | filter_include() |
|---|
| 71 | filter_max_depth() |
|---|
| 72 | |
|---|
| 73 | if __name__ == '__main__': |
|---|
| 74 | main() |
|---|
| 75 | |
|---|
| 76 | # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: |
|---|