Trace into a file or an open fd and refactor tracing code.