@@ -176,6 +176,7 @@ void PopEvent(const std::string& name, const DeviceContext* dev_ctx) {
176
176
177
177
RecordEvent::RecordEvent (const std::string& name, const DeviceContext* dev_ctx)
178
178
: is_enabled_(false ), start_ns_(PosixInNsec()) {
179
+ std::lock_guard<std::mutex> l (profiler_mu);
179
180
if (g_state == ProfilerState::kDisabled ) return ;
180
181
is_enabled_ = true ;
181
182
dev_ctx_ = dev_ctx;
@@ -186,6 +187,7 @@ RecordEvent::RecordEvent(const std::string& name, const DeviceContext* dev_ctx)
186
187
}
187
188
188
189
RecordEvent::~RecordEvent () {
190
+ std::lock_guard<std::mutex> l (profiler_mu);
189
191
if (g_state == ProfilerState::kDisabled || !is_enabled_) return ;
190
192
DeviceTracer* tracer = GetDeviceTracer ();
191
193
if (tracer) {
@@ -198,13 +200,15 @@ RecordEvent::~RecordEvent() {
198
200
199
201
RecordBlock::RecordBlock (int block_id)
200
202
: is_enabled_(false ), start_ns_(PosixInNsec()) {
203
+ std::lock_guard<std::mutex> l (profiler_mu);
201
204
if (g_state == ProfilerState::kDisabled ) return ;
202
205
is_enabled_ = true ;
203
206
SetCurBlock (block_id);
204
207
name_ = string::Sprintf (" block_%d" , block_id);
205
208
}
206
209
207
210
RecordBlock::~RecordBlock () {
211
+ std::lock_guard<std::mutex> l (profiler_mu);
208
212
if (g_state == ProfilerState::kDisabled || !is_enabled_) return ;
209
213
DeviceTracer* tracer = GetDeviceTracer ();
210
214
if (tracer) {
@@ -217,11 +221,13 @@ RecordBlock::~RecordBlock() {
217
221
}
218
222
219
223
RecordThread::RecordThread (int thread_id) {
224
+ std::lock_guard<std::mutex> l (profiler_mu);
220
225
if (g_state == ProfilerState::kDisabled ) return ;
221
226
SetCurThread (thread_id);
222
227
}
223
228
224
229
RecordThread::~RecordThread () {
230
+ std::lock_guard<std::mutex> l (profiler_mu);
225
231
if (g_state == ProfilerState::kDisabled ) return ;
226
232
ClearCurThread ();
227
233
}
0 commit comments