Lock the profiler mutex when enabling and disabling it.

Disabling flushes data to the file, and that definitely
should be properly synchronized.