janestreet / magic-trace

magic-trace collects and displays high-resolution traces of what a process is doing
https://magic-trace.org
MIT License
4.58k stars 87 forks source link

Add a mode to automatically capture a trace and exit #258

Closed knrafto closed 2 years ago

knrafto commented 2 years ago

We have a script to automatically run magic-trace during tests. Right now we have to start magic-trace, wait for some amount of time, and then send SIGINT to magic-trace using pkill. Unfortunately, the time we need to wait is not predictable (it could be 5s or more for large binaries) so this occasionally sends SIGINT too early. If would be nice if we could tell magic-trace to take a snapshot and exit when it's done.

I tried to implement this myself but I couldn't find a good way to know when perf is "ready". It looks like magic-trace itself has a hardcoded 500ms timeout, which is definitely not long enough for our binaries. Do you have any ideas?

knrafto commented 2 years ago

(sorry, this is a feature request, not a bug report, but I don't see how to change the labels now)

Xyene commented 2 years ago

I think https://github.com/janestreet/magic-trace/issues/230 should address this. You could write magic-trace attach -p [your process' pid] -- true and that would do the right thing.

knrafto commented 2 years ago

Interesting, thanks! Closing to dedup