A decorator that uses cProfile to profile a function
(function)
| 14 | |
| 15 | |
| 16 | def profile(function): |
| 17 | """ A decorator that uses cProfile to profile a function """ |
| 18 | |
| 19 | def inner(*args, **argv): |
| 20 | pr = cProfile.Profile() |
| 21 | pr.enable() |
| 22 | retval = function(*args, **argv) |
| 23 | pr.disable() |
| 24 | s = io.StringIO() |
| 25 | sortby = 'cumulative' |
| 26 | ps = pstats.Stats(pr).sort_stats(sortby) |
| 27 | ps.print_stats(0.1) |
| 28 | print(s.getvalue()) |
| 29 | return retval |
| 30 | |
| 31 | return inner |
| 32 | |
| 33 | |
| 34 | def homogenize(x): |
nothing calls this directly
no outgoing calls
no test coverage detected