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