Print all C-level thread stacks for a given process id.
(pid: int)
| 188 | |
| 189 | |
| 190 | def print_thread_stacks(pid: int) -> None: |
| 191 | """Print all C-level thread stacks for a given process id.""" |
| 192 | if sys.platform == "darwin": |
| 193 | cmd = ["lldb", "--attach-pid", f"{pid}", "--batch", "--one-line", '"thread backtrace all"'] |
| 194 | else: |
| 195 | cmd = ["gdb", f"--pid={pid}", "--batch", '--eval-command="thread apply all bt"'] |
| 196 | |
| 197 | try: |
| 198 | res = subprocess.run( |
| 199 | cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding="utf-8" |
| 200 | ) |
| 201 | except Exception as exc: |
| 202 | sys.stderr.write(f"Could not print C-level thread stacks because {cmd[0]} failed: {exc}") |
| 203 | else: |
| 204 | sys.stderr.write(res.stdout) |
| 205 | |
| 206 | |
| 207 | def _get_executors(topology): |