Darwin debugging for the Linux developer
These technical notes are meant to explain to a Linux developer what are the equivalents to debug certain things over Darwin.
Key differences from Linux
| Linux tool | macOS equivalent | Purpose |
|---|---|---|
strace |
dtruss (1), strace-macos |
System call tracing |
perf |
sample, spindump, Instruments (2) |
Performance profiling |
ss |
netstat -nv |
Socket statistics |
iostat |
iostat -Id |
Disk I/O statistics |
lsof |
lsof |
Open file listings |
/proc |
vmmap, heap, lsof |
Process/memory information |
blktrace |
fs_usage -wf filesys |
Trace real-time IO activity |
Getting flamegraphs out of sample
Combine https://github.com/brc7/flamegraph-sample/blob/master/stackcollapse-sample.py with https://speedscope.app/.
Inspecting memory allocations
heap can give a list of allocations sorted by sizes when it can recognize the type in-memory (doesn't always work for everything).
iostat tips
iostat -Id on macOS will return as the first row the cumulative data SINCE the first boot.
xfrs := IO operations per second.
Listing file descriptors
/proc doesn't exist on macOS, therefore, lsof is the only thing that can list file descriptors and let you understand the relationships.
Tracing network activity
fs_usage -wf network can trace real-time network activity on file descriptors.
Checking Internet quality
networkQuality -v will dump an Apple-infrastructure Internet connection check for bandwidth and latency.