I know that I can redirect the xtrace output to some_file with something like this:

exec 2 >> some_file
set +x

...but this sends to some_file not only the xtrace output, but also any other content originally sent to fd 2, which includes most error messages and warnings, all unrelated to xtrace.

Is there a way to capture only the xtrace output in some_file?

I should add that I'm looking for a way to do this that would distort as little as possible the xtrace output itself, and the timing information gathered through a PS4 setting like, e.g.

zmodload zsh/datetime
export PS4='${(j::)epochtime} %N:%i> '
  • 3
    Looking at the source code, this doesn't appear to be possible: traces are written to xtrerr and xtrerr is initialized with xtrerr = stderr and changes only temporarily while processing a redirection. – Gilles 'SO- stop being evil' Jan 12 '17 at 1:01

Might not be the solution you are looking for, but having run into a similar scenario in the past, my go-to is to write a python parser to take the trace file, and output only the data I care about into a resulting file. As long as the patterns of the "garbage text" that you don't care about are predictable/differentiable from the xtrace output, the parsing should be extremely easy to do.

Example - grabbing a trace of all IOs across all submission queues for 20 min test consisting of reads and writes results in a 40GB-70GB file, but after parsing the data I care about out of it, my result file is only ~1-3GB in size, and actually usable for analysis and visualization. Granted, with such large file sizes, it takes a server-class system ~15-30 min to process through it all, but doing the same process (separate scenario, same idea - multiple logs each only about 24kb) - I can get all of the data from all logs into a single consumable file in under 2 seconds.

All that to say, it might be worth it to add a post-processing step that might add a few seconds/minutes to the overall capture, rather than waiting for a one-stop-shop.

Best of luck!

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.