Refactor prof_dump() to use a two-pass algorithm, such that string formatting and write(2) calls happen outside the critical section.