Compiling with gprof

Hi,
I want to compile and run Ardupilot within SITL with the flag for gprof, which is -pg. I added this flag to the file Tools/ardupilotwaf/boards.py by modifying the debug option from using the flag -g to -pg. Now, if I was to run SITL with this flag, it should generate a ‘gmon.out’ file after finishes execution.

I tried to run the SITL properly, but the issue was that SITL does not terminate using exit or return which is required for gprof. I also tried to run SITL with an invalid board type, which terminates using exit. This is supposed to work, however I am unable to get the gmon.out output file. I can tell the flag for gprof is being interpreted because changing the flag back to -g results in a full compilation again.