Handle profiling buffer underrun.

In rare circumstances it's possible for the thread executing the "stop
profiling" method to start processing the data before all other threads
have finished writing data.  In particular, it's possible for a thread
to be switched out after advancing the offset pointer but before writing
actual data.

This is problematic because the buffer is expected to contain method
pointers.  The fill value (0xee) does not yield a valid pointer.

This adds a short usleep() to reduce the likelihood of the problem
occurring, and adds a buffer scan to detect partial records.  When
encountered, the rest of the log is truncated.

For internal bug 1861898.
1 file changed