make profiler thread safe

@yilongli please review

I elected to not use instance state because it would have required a much more invasive change to the code base. Let me know if you're okay with this solution.