strace_manager
strace_manager
¶
Strace management for the Marianne daemon profiler.
Attaches strace -c to child processes to collect per-syscall count and
time-percentage summaries. Also supports on-demand full trace via
strace -f -t -p PID -o <file> for deep debugging.
Handles gracefully: - strace not installed - Permission denied (non-root) - Target process already exited - Strace process cleanup on daemon shutdown
Strace processes are tracked so they can be cleaned up by
ProcessGroupManager on daemon shutdown.
Classes¶
StraceManager
¶
Manages strace attachment to child processes.
Typical lifecycle::
mgr = StraceManager(enabled=True)
await mgr.attach(pid) # spawns ``strace -c -p PID``
... # time passes, child does work
summary = await mgr.detach(pid) # SIGINT -> parse summary
await mgr.detach_all() # cleanup on shutdown
Source code in src/marianne/daemon/profiler/strace_manager.py
Attributes¶
Functions¶
is_available
staticmethod
¶
attach
async
¶
Attach strace -c -p <pid> for syscall summary collection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pid
|
int
|
Target process PID to trace. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if strace was successfully spawned, False otherwise. |
Source code in src/marianne/daemon/profiler/strace_manager.py
detach
async
¶
Detach strace from a process and parse the summary output.
Sends SIGINT to the strace process (which causes it to print its
-c summary table to stderr), then parses the output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pid
|
int
|
Target process PID to stop tracing. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
Dict with |
dict[str, Any] | None
|
or None if the pid was not being traced. |
Source code in src/marianne/daemon/profiler/strace_manager.py
attach_full_trace
async
¶
Attach a full strace (strace -f -t -p PID -o file).
This is the on-demand deep-trace triggered by mzt top --trace PID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pid
|
int
|
Target process PID. |
required |
output_file
|
Path
|
Path to write the full trace output. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if strace was successfully spawned, False otherwise. |
Source code in src/marianne/daemon/profiler/strace_manager.py
detach_all
async
¶
Detach and terminate all strace processes.
Called during daemon shutdown for cleanup.
Source code in src/marianne/daemon/profiler/strace_manager.py
get_strace_pids
¶
Return PIDs of all running strace subprocesses.
Useful for registering with ProcessGroupManager so they get cleaned up on daemon shutdown.