MCPcopy Index your code
hub / github.com/RustPython/RustPython / StraceResult

Class StraceResult

Lib/test/support/strace_helper.py:27–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25
26@dataclass
27class StraceResult:
28 strace_returncode: int
29 python_returncode: int
30
31 """The event messages generated by strace. This is very similar to the
32 stderr strace produces with returncode marker section removed."""
33 event_bytes: bytes
34 stdout: bytes
35 stderr: bytes
36
37 def events(self):
38 """Parse event_bytes data into system calls for easier processing.
39
40 This assumes the program under inspection doesn't print any non-utf8
41 strings which would mix into the strace output."""
42 decoded_events = self.event_bytes.decode('utf-8', 'surrogateescape')
43 matches = [
44 _syscall_regex.match(event)
45 for event in decoded_events.splitlines()
46 ]
47 return [
48 StraceEvent(match["syscall"],
49 [arg.strip() for arg in (match["args"].split(","))],
50 match["returncode"]) for match in matches if match
51 ]
52
53 def sections(self):
54 """Find all "MARK <X>" writes and use them to make groups of events.
55
56 This is useful to avoid variable / overhead events, like those at
57 interpreter startup or when opening a file so a test can verify just
58 the small case under study."""
59 current_section = "__startup"
60 sections = {current_section: []}
61 for event in self.events():
62 if event.syscall == 'write' and len(
63 event.args) > 2 and event.args[1].startswith("\"MARK "):
64 # Found a new section, don't include the write in the section
65 # but all events until next mark should be in that section
66 current_section = event.args[1].split(
67 " ", 1)[1].removesuffix('\\n"')
68 if current_section not in sections:
69 sections[current_section] = list()
70 else:
71 sections[current_section].append(event)
72
73 return sections
74
75def _filter_memory_call(call):
76 # mmap can operate on a fd or "MAP_ANONYMOUS" which gives a block of memory.

Callers 2

_make_errorFunction · 0.85
strace_pythonFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected