From 4c5bcd78597e495c08d883322f231cb99f43f8fd Mon Sep 17 00:00:00 2001 From: qiaolongfei Date: Sun, 5 Aug 2018 22:16:02 +0800 Subject: [PATCH] add guard to profiler --- paddle/fluid/platform/profiler.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/paddle/fluid/platform/profiler.cc b/paddle/fluid/platform/profiler.cc index 01de9d704..75cae95f8 100644 --- a/paddle/fluid/platform/profiler.cc +++ b/paddle/fluid/platform/profiler.cc @@ -176,6 +176,7 @@ void PopEvent(const std::string& name, const DeviceContext* dev_ctx) { RecordEvent::RecordEvent(const std::string& name, const DeviceContext* dev_ctx) : is_enabled_(false), start_ns_(PosixInNsec()) { + std::lock_guard l(profiler_mu); if (g_state == ProfilerState::kDisabled) return; is_enabled_ = true; dev_ctx_ = dev_ctx; @@ -186,6 +187,7 @@ RecordEvent::RecordEvent(const std::string& name, const DeviceContext* dev_ctx) } RecordEvent::~RecordEvent() { + std::lock_guard l(profiler_mu); if (g_state == ProfilerState::kDisabled || !is_enabled_) return; DeviceTracer* tracer = GetDeviceTracer(); if (tracer) { @@ -198,6 +200,7 @@ RecordEvent::~RecordEvent() { RecordBlock::RecordBlock(int block_id) : is_enabled_(false), start_ns_(PosixInNsec()) { + std::lock_guard l(profiler_mu); if (g_state == ProfilerState::kDisabled) return; is_enabled_ = true; SetCurBlock(block_id); @@ -205,6 +208,7 @@ RecordBlock::RecordBlock(int block_id) } RecordBlock::~RecordBlock() { + std::lock_guard l(profiler_mu); if (g_state == ProfilerState::kDisabled || !is_enabled_) return; DeviceTracer* tracer = GetDeviceTracer(); if (tracer) { @@ -217,11 +221,13 @@ RecordBlock::~RecordBlock() { } RecordThread::RecordThread(int thread_id) { + std::lock_guard l(profiler_mu); if (g_state == ProfilerState::kDisabled) return; SetCurThread(thread_id); } RecordThread::~RecordThread() { + std::lock_guard l(profiler_mu); if (g_state == ProfilerState::kDisabled) return; ClearCurThread(); } -- GitLab