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