Use fast path for common case.

Locks are required only during memory allocation and memory needs to be
allocated only once. Subsequent recordings can take the fast path. There _is_ a
race condition in this code but this will not result in program crashes but
only missed measurements. In the worst case, if there are N threads in the user
code, the first measurement from N-1 threads will not be saved. Although not
ideal, this missed measurement hardly makes a difference to the analysis.