Debian Codegraph @

pypy/module/pypyjit/test_pypy_c/test_cprofile.py

raw symbols SCIP
1 import py, sys, re
2 from pypy.module.pypyjit.test_pypy_c.test_00_model import BaseTestPyPyC
3
4 class TestCProfile(BaseTestPyPyC):
5
6 def test_cprofile_builtin(self):
7 def main(n):
8 import _lsprof
9 prof = _lsprof.Profiler()
10 i = 0
11 lst = []
12 prof.enable()
13 while i < n:
14 lst.append(i) # ID: append
15 lst.pop() # ID: pop
16 i += 1
17 prof.disable()
18 return [(entry.code, entry.callcount) for entry in prof.getstats()]
19 #
20 log = self.run(main, [500])
21 assert sorted(log.result) == [
22 ("<method 'append' of 'list' objects>", 500),
23 ("<method 'disable' of '_lsprof.Profiler' objects>", 1),
24 ("<method 'pop' of 'list' objects>", 500),
25 ]
26 for method in ['append', 'pop']:
27 loop, = log.loops_by_id(method)
28 print loop.ops_by_id(method)
29 # on 32-bit, there is f1=call(read_timestamp); ...;
30 # f2=call(read_timestamp); f3=call(llong_sub,f1,f2)
31 # but all calls can be special-cased by the backend if
32 # supported. On 64-bit there is only the two calls to
33 # read_timestamp.
34 r = re.compile(r" call_\w[(]ConstClass[(](.+?)[)]")
35 calls = r.findall(repr(loop.ops_by_id(method)))
36 if sys.maxint == 2147483647:
37 assert len(calls) == 6
38 else:
39 assert len(calls) == 2
40 for x in calls:
41 assert ('ll_read_timestamp' in x or 'llong_sub' in x
42 or 'llong_add' in x)
43 #
44 assert ' call_may_force(' not in repr(loop.ops_by_id(method))
45 assert ' cond_call(' in repr(loop.ops_by_id(method))