Wouldn't it be possible to put the debugFct call before each wait(1);? That would basically do what you need.