| 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 timing functionality. |
|---|
| 26 | """ |
|---|
| 27 | import re |
|---|
| 28 | |
|---|
| 29 | import pycallgraph |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | def filter_none(): |
|---|
| 33 | pycallgraph.start_trace() |
|---|
| 34 | for a in xrange(100): |
|---|
| 35 | re.compile('test1-%i' % a) |
|---|
| 36 | pycallgraph.make_dot_graph('filter-time-none.png') |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | def filter_min_depth(): |
|---|
| 40 | filter_func = pycallgraph.GlobbingFilter(min_depth=7) |
|---|
| 41 | pycallgraph.start_trace(time_filter_func=filter_func) |
|---|
| 42 | for a in xrange(100): |
|---|
| 43 | re.compile('test2-%i' % a) |
|---|
| 44 | pycallgraph.make_dot_graph('filter-time-min-depth.png') |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | def filter_module(): |
|---|
| 48 | filter_func = pycallgraph.GlobbingFilter(include=['sre_parse.*']) |
|---|
| 49 | pycallgraph.start_trace(time_filter_func=filter_func) |
|---|
| 50 | for a in xrange(100): |
|---|
| 51 | re.compile('test3-%i' % a) |
|---|
| 52 | pycallgraph.make_dot_graph('filter-time-module.png') |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | def main(): |
|---|
| 56 | filter_none() |
|---|
| 57 | filter_min_depth() |
|---|
| 58 | filter_module() |
|---|
| 59 | |
|---|
| 60 | if __name__ == '__main__': |
|---|
| 61 | main() |
|---|
| 62 | |
|---|
| 63 | # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: |
|---|