Benjamin Peterson | 4e299c7 | 2008-10-06 21:03:05 +0000 | [diff] [blame] | 1 | """Test suite for the cProfile module.""" |
| 2 | |
| 3 | import sys |
Benjamin Peterson | 6ccc703 | 2008-10-07 02:32:59 +0000 | [diff] [blame] | 4 | from test.support import run_unittest, TESTFN, unlink |
Benjamin Peterson | 4e299c7 | 2008-10-06 21:03:05 +0000 | [diff] [blame] | 5 | |
| 6 | # rip off all interesting stuff from test_profile |
| 7 | import cProfile |
| 8 | from test.test_profile import ProfileTest, regenerate_expected_output |
| 9 | |
| 10 | class CProfileTest(ProfileTest): |
| 11 | profilerclass = cProfile.Profile |
Antoine Pitrou | 8e124f3 | 2009-05-30 21:41:10 +0000 | [diff] [blame] | 12 | expected_max_output = "{built-in method max}" |
Benjamin Peterson | 4e299c7 | 2008-10-06 21:03:05 +0000 | [diff] [blame] | 13 | |
Benjamin Peterson | 7d76653 | 2008-10-06 22:05:00 +0000 | [diff] [blame] | 14 | def get_expected_output(self): |
| 15 | return _ProfileOutput |
| 16 | |
Benjamin Peterson | 6ccc703 | 2008-10-07 02:32:59 +0000 | [diff] [blame] | 17 | # Issue 3895. |
| 18 | def test_bad_counter_during_dealloc(self): |
| 19 | import _lsprof |
| 20 | # Must use a file as StringIO doesn't trigger the bug. |
Brett Cannon | 5ede149 | 2010-10-29 22:47:04 +0000 | [diff] [blame] | 21 | with open(TESTFN, 'w') as file: |
| 22 | sys.stderr = file |
| 23 | try: |
| 24 | obj = _lsprof.Profiler(lambda: int) |
| 25 | obj.enable() |
| 26 | obj = _lsprof.Profiler(1) |
| 27 | obj.disable() |
| 28 | finally: |
| 29 | sys.stderr = sys.__stderr__ |
Antoine Pitrou | d05f9ad | 2010-10-29 23:55:55 +0000 | [diff] [blame] | 30 | unlink(TESTFN) |
Benjamin Peterson | 6ccc703 | 2008-10-07 02:32:59 +0000 | [diff] [blame] | 31 | |
Benjamin Peterson | 4e299c7 | 2008-10-06 21:03:05 +0000 | [diff] [blame] | 32 | |
| 33 | def test_main(): |
| 34 | run_unittest(CProfileTest) |
| 35 | |
| 36 | def main(): |
| 37 | if '-r' not in sys.argv: |
| 38 | test_main() |
| 39 | else: |
| 40 | regenerate_expected_output(__file__, CProfileTest) |
| 41 | |
| 42 | |
| 43 | # Don't remove this comment. Everything below it is auto-generated. |
| 44 | #--cut-------------------------------------------------------------------------- |
Benjamin Peterson | 7d76653 | 2008-10-06 22:05:00 +0000 | [diff] [blame] | 45 | _ProfileOutput = {} |
| 46 | _ProfileOutput['print_stats'] = """\ |
Benjamin Peterson | 4e299c7 | 2008-10-06 21:03:05 +0000 | [diff] [blame] | 47 | 28 0.028 0.001 0.028 0.001 profilee.py:110(__getattr__) |
| 48 | 1 0.270 0.270 1.000 1.000 profilee.py:25(testfunc) |
| 49 | 23/3 0.150 0.007 0.170 0.057 profilee.py:35(factorial) |
| 50 | 20 0.020 0.001 0.020 0.001 profilee.py:48(mul) |
| 51 | 2 0.040 0.020 0.600 0.300 profilee.py:55(helper) |
| 52 | 4 0.116 0.029 0.120 0.030 profilee.py:73(helper1) |
| 53 | 2 0.000 0.000 0.140 0.070 profilee.py:84(helper2_indirect) |
| 54 | 8 0.312 0.039 0.400 0.050 profilee.py:88(helper2) |
| 55 | 8 0.064 0.008 0.080 0.010 profilee.py:98(subhelper)""" |
Benjamin Peterson | 7d76653 | 2008-10-06 22:05:00 +0000 | [diff] [blame] | 56 | _ProfileOutput['print_callers'] = """\ |
Benjamin Peterson | 4e299c7 | 2008-10-06 21:03:05 +0000 | [diff] [blame] | 57 | profilee.py:110(__getattr__) <- 16 0.016 0.016 profilee.py:98(subhelper) |
| 58 | profilee.py:25(testfunc) <- 1 0.270 1.000 <string>:1(<module>) |
| 59 | profilee.py:35(factorial) <- 1 0.014 0.130 profilee.py:25(testfunc) |
| 60 | 20/3 0.130 0.147 profilee.py:35(factorial) |
| 61 | 2 0.006 0.040 profilee.py:84(helper2_indirect) |
| 62 | profilee.py:48(mul) <- 20 0.020 0.020 profilee.py:35(factorial) |
| 63 | profilee.py:55(helper) <- 2 0.040 0.600 profilee.py:25(testfunc) |
| 64 | profilee.py:73(helper1) <- 4 0.116 0.120 profilee.py:55(helper) |
| 65 | profilee.py:84(helper2_indirect) <- 2 0.000 0.140 profilee.py:55(helper) |
| 66 | profilee.py:88(helper2) <- 6 0.234 0.300 profilee.py:55(helper) |
| 67 | 2 0.078 0.100 profilee.py:84(helper2_indirect) |
| 68 | profilee.py:98(subhelper) <- 8 0.064 0.080 profilee.py:88(helper2) |
| 69 | {built-in method exc_info} <- 4 0.000 0.000 profilee.py:73(helper1) |
| 70 | {built-in method hasattr} <- 4 0.000 0.004 profilee.py:73(helper1) |
| 71 | 8 0.000 0.008 profilee.py:88(helper2) |
| 72 | {method 'append' of 'list' objects} <- 4 0.000 0.000 profilee.py:73(helper1)""" |
Benjamin Peterson | 7d76653 | 2008-10-06 22:05:00 +0000 | [diff] [blame] | 73 | _ProfileOutput['print_callees'] = """\ |
Benjamin Peterson | 4e299c7 | 2008-10-06 21:03:05 +0000 | [diff] [blame] | 74 | <string>:1(<module>) -> 1 0.270 1.000 profilee.py:25(testfunc) |
| 75 | profilee.py:110(__getattr__) -> |
| 76 | profilee.py:25(testfunc) -> 1 0.014 0.130 profilee.py:35(factorial) |
| 77 | 2 0.040 0.600 profilee.py:55(helper) |
| 78 | profilee.py:35(factorial) -> 20/3 0.130 0.147 profilee.py:35(factorial) |
| 79 | 20 0.020 0.020 profilee.py:48(mul) |
| 80 | profilee.py:48(mul) -> |
| 81 | profilee.py:55(helper) -> 4 0.116 0.120 profilee.py:73(helper1) |
| 82 | 2 0.000 0.140 profilee.py:84(helper2_indirect) |
| 83 | 6 0.234 0.300 profilee.py:88(helper2) |
| 84 | profilee.py:73(helper1) -> 4 0.000 0.000 {built-in method exc_info} |
| 85 | profilee.py:84(helper2_indirect) -> 2 0.006 0.040 profilee.py:35(factorial) |
| 86 | 2 0.078 0.100 profilee.py:88(helper2) |
| 87 | profilee.py:88(helper2) -> 8 0.064 0.080 profilee.py:98(subhelper) |
| 88 | profilee.py:98(subhelper) -> 16 0.016 0.016 profilee.py:110(__getattr__) |
| 89 | {built-in method hasattr} -> 12 0.012 0.012 profilee.py:110(__getattr__)""" |
| 90 | |
| 91 | if __name__ == "__main__": |
| 92 | main() |