Debian Codegraph @

rpython/rlib/rvmprof/__init__.py

raw symbols SCIP
1 from rpython.rlib.objectmodel import specialize
2 from rpython.rlib.rvmprof.rvmprof import _get_vmprof, VMProfError
3 from rpython.rlib.rvmprof.rvmprof import vmprof_execute_code, MAX_FUNC_NAME
4 from rpython.rlib.rvmprof.rvmprof import _was_registered
5 from rpython.rlib.rvmprof.cintf import VMProfPlatformUnsupported
6 from rpython.rtyper.lltypesystem import rffi, lltype
7
8 #
9 # See README.txt.
10 #
11
12 #vmprof_execute_code(): implemented directly in rvmprof.py
13
14 def register_code_object_class(CodeClass, full_name_func):
15 _get_vmprof().register_code_object_class(CodeClass, full_name_func)
16
17 @specialize.argtype(0)
18 def register_code(code, name):
19 _get_vmprof().register_code(code, name)
20
21 @specialize.call_location()
22 def get_unique_id(code):
23 """Return the internal unique ID of a code object. Can only be
24 called after register_code(). Call this in the jitdriver's
25 method 'get_unique_id(*greenkey)'. This always returns 0 if we
26 didn't call register_code_object_class() on the class.
27 """
28 assert code is not None
29 if _was_registered(code.__class__):
30 # '0' can occur here too, if the code object was prebuilt,
31 # or if register_code() was not called for another reason.
32 return code._vmprof_unique_id
33 return 0
34
35 def enable(fileno, interval, memory=0, native=0, real_time=0):
36 _get_vmprof().enable(fileno, interval, memory, native, real_time)
37
38 def disable():
39 _get_vmprof().disable()
40
41 def is_enabled():
42 vmp = _get_vmprof()
43 return vmp.is_enabled
44
45 def get_profile_path(space):
46 vmp = _get_vmprof()
47 if not vmp.is_enabled:
48 return None
49
50 with rffi.scoped_alloc_buffer(4096) as buf:
51 length = vmp.cintf.vmprof_get_profile_path(buf.raw, buf.size)
52 if length == -1:
53 return ""
54 return buf.str(length)
55
56 return None
57
58 def stop_sampling():
59 return _get_vmprof().stop_sampling()
60
61 def start_sampling():
62 return _get_vmprof().start_sampling()
63
64 # ----------------
65 # stacklet support
66 # ----------------
67 #
68 # Ideally, vmprof_tl_stack, VMPROFSTACK etc. should be part of "self.cintf":
69 # not sure why they are a global. Eventually, we should probably fix all this
70 # mess.
71 from rpython.rlib.rvmprof.cintf import vmprof_tl_stack, VMPROFSTACK
72
73 def save_stack():
74 stop_sampling()
75 return vmprof_tl_stack.get_or_make_raw()
76
77 def empty_stack():
78 vmprof_tl_stack.setraw(lltype.nullptr(VMPROFSTACK))
79
80 def restore_stack(x):
81 vmprof_tl_stack.setraw(x)
82 start_sampling()