stdout/stderr in Instruments does not show output

I'm using Instruments to profile a C program that prints to stdout via printf but the program output does not appear in the Detail Area of the stdout/stderr instrument I added.

The program is launched by Instruments itself when I click the Record button and it appears to run correctly – I just can't see the stdout output.

I'm using Version 14.3.1 (14E300c) of Instruments on a MacBook Pro 16" (2019) running macOS 13.4 (22F66).

Hi Eurydice,

I suspect that this is due to the output you are writing to printf being buffered. stdout buffers output by default, meaning output will be written to a buffer first and once the buffer fills up it will actually be written out. It might be that your program write so little that the buffer never fills up and then when you stop the recording, Instruments kills the process without it ever actually writing the output.

When you run the same program in a Terminal, Terminal changes stdout to do line-by-line buffering, meaning the output will be written out once a line ends.

To quickly test whether this is the case for you, try changing to stderr instead. stderr should always be unbuffered (and the stdout/stderr instrument also captures stderr.

If it is indeed due to buffering of stdout, there is some more information about configuring the buffering behavior of your program under various conditions here: https://developer.apple.com/forums/thread/669842?answerId=706389022#706389022

The most promising option seems to be setting the STDBUF environment variable.

If this workaround works for you, could you please also file a radar on Instruments? Instruments already changes the buffering behavior for Foundation-based apps, but it could likely do a better job for generic C programs.

If changing the buffering behavior does NOT solve your problem, please report back here. As it's WWDC week you can also sign up for the Performance, power, and stability lab on Friday to have an engineer from the Instruments team take a look at the issue with you and either solve the issue or help you file a feedback report on Instruments. Note that signup closes on Thursday at 6PM California time.

stdout/stderr in Instruments does not show output
 
 
Q