File: test_cprofile.py

package info (click to toggle)
pypy3 7.3.19%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 212,236 kB
  • sloc: python: 2,098,316; ansic: 540,565; sh: 21,462; asm: 14,419; cpp: 4,451; makefile: 4,209; objc: 761; xml: 530; exp: 499; javascript: 314; pascal: 244; lisp: 45; csh: 12; awk: 4
file content (45 lines) | stat: -rw-r--r-- 1,813 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import py, sys, re
from pypy.module.pypyjit.test_pypy_c.test_00_model import BaseTestPyPyC

class TestCProfile(BaseTestPyPyC):

    def test_cprofile_builtin(self):
        def main(n):
            import _lsprof
            prof = _lsprof.Profiler()
            i = 0
            lst = []
            prof.enable()
            while i < n:
                lst.append(i)   # ID: append
                lst.pop()       # ID: pop
                i += 1
            prof.disable()
            return [(entry.code, entry.callcount) for entry in prof.getstats()]
        #
        log = self.run(main, [500])
        assert sorted(log.result) == [
            ("<method 'append' of 'list' objects>", 500),
            ("<method 'disable' of '_lsprof.Profiler' objects>", 1),
            ("<method 'pop' of 'list' objects>", 500),
            ]
        for method in ['append', 'pop']:
            loop, = log.loops_by_id(method)
            print loop.ops_by_id(method)
            # on 32-bit, there is f1=call(read_timestamp); ...;
            # f2=call(read_timestamp); f3=call(llong_sub,f1,f2)
            # but all calls can be special-cased by the backend if
            # supported.  On 64-bit there is only the two calls to
            # read_timestamp.
            r = re.compile(r" call_\w[(]ConstClass[(](.+?)[)]")
            calls = r.findall(repr(loop.ops_by_id(method)))
            if sys.maxint == 2147483647:
                assert len(calls) == 6
            else:
                assert len(calls) == 2
            for x in calls:
                assert ('ll_read_timestamp' in x or 'llong_sub' in x
                        or 'llong_add' in x)
            #
            assert ' call_may_force(' not in repr(loop.ops_by_id(method))
            assert ' cond_call(' in repr(loop.ops_by_id(method))