Make profiler stuff more thread safe (last commit wasn't sufficient)