janestreet / memtrace

Streaming client for OCaml's Memprof
MIT License
65 stars 13 forks source link

Disable on fork #13

Closed stedolan closed 3 years ago

stedolan commented 3 years ago

This patch causes Memtrace to turn itself off if the PID changes, so that if tracing is active across a call to fork then the child process writes no further events, instead of risking corruption of the trace file with two concurrent writers.

The implementation reuses the existing mechanism for disabling Memtrace if flushing fails: in the existing code, if any tracing operation raises an exception then a backtrace is printed to stderr and future tracing is disabled. The only difference here is that if tracing is disabled due to a PID change, no message is printed to stderr.