Debian Codegraph @

pyinstrument/frame_info.py

raw symbols SCIP
1 from typing import List, Tuple
2
3 # pyright: strict
4
5
6 IDENTIFIER_SEP = "\x00"
7 ATTRIBUTES_SEP = "\x01"
8
9 ATTRIBUTE_MARKER_CLASS_NAME = "c"
10 ATTRIBUTE_MARKER_LINE_NUMBER = "l"
11 ATTRIBUTE_MARKER_TRACEBACKHIDE = "h"
12
13
14 def parse_frame_info(frame_info: str) -> Tuple[str, List[str]]:
15 """
16 Parses a frame_info string, returns a tuple of (identifier, attributes),
17 where `identifier` is a unique identifier for this code (e.g. a function
18 or method), and `attributes` is a list of invocation-specific attributes
19 that were captured at profile-time.
20 """
21
22 identifier, _, attributes_str = frame_info.partition(ATTRIBUTES_SEP)
23
24 if not attributes_str:
25 return identifier, []
26
27 return identifier, attributes_str.split(ATTRIBUTES_SEP)
28
29
30 def frame_info_get_identifier(frame_info: str) -> str:
31 """
32 Equivalent to `parse_frame_info(frame_info)[0]`, but faster.
33 """
34 index = frame_info.find(ATTRIBUTES_SEP)
35
36 if index == -1:
37 # no attributes
38 return frame_info
39
40 return frame_info[0:index]